Ejemplo n.º 1
0
        /// <summary>
        /// Update person **Note:** this endpoint is available in Alfresco 5.2 and newer versions.  Update the given person&#39;s details.  You can use the &#x60;-me-&#x60; string in place of &#x60;&lt;personId&gt;&#x60; to specify the currently authenticated user.  If applicable, the given person&#39;s login access can also be optionally disabled or re-enabled.  You must have admin rights to update a person — unless updating your own details.  If you are changing your password, as a non-admin user, then the existing password must also be supplied (using the oldPassword field in addition to the new password value).  Admin users cannot be disabled by setting enabled to false.  Non-admin users may not disable themselves.  You can set custom properties when you update a person: &#x60;&#x60;&#x60;JSON {   \&quot;firstName\&quot;: \&quot;Alice\&quot;,   \&quot;properties\&quot;:   {     \&quot;my:property\&quot;: \&quot;The value\&quot;   } } &#x60;&#x60;&#x60; **Note:** setting properties of type d:content and d:category are not supported.
        /// </summary>
        /// <param name="personId">The identifier of a person.</param>
        /// <param name="personBodyUpdate">The person details.</param>
        /// <param name="fields">A list of field names.  You can use this parameter to restrict the fields returned within a response if, for example, you want to save on overall bandwidth.  The list applies to a returned individual entity or entries within a collection.  If the API method also supports the **include** parameter, then the fields specified in the **include** parameter are returned in addition to those specified in the **fields** parameter. </param>
        /// <returns>PersonEntry</returns>
        public PersonEntry UpdatePerson(string personId, PersonBodyUpdate personBodyUpdate, List <string> fields)
        {
            // verify the required parameter 'personId' is set
            if (personId == null)
            {
                throw new ApiException(400, "Missing required parameter 'personId' when calling UpdatePerson");
            }

            // verify the required parameter 'personBodyUpdate' is set
            if (personBodyUpdate == null)
            {
                throw new ApiException(400, "Missing required parameter 'personBodyUpdate' when calling UpdatePerson");
            }


            var path = "/people/{personId}";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "personId" + "}", ApiClient.ParameterToString(personId));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            if (fields != null)
            {
                queryParams.Add("fields", ApiClient.ParameterToString(fields));       // query parameter
            }
            postBody = ApiClient.Serialize(personBodyUpdate);                         // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { "basicAuth" };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling UpdatePerson: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling UpdatePerson: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((PersonEntry)ApiClient.Deserialize(response.Content, typeof(PersonEntry), response.Headers));
        }
Ejemplo n.º 2
0
        public async Task <PersonEntryFixed> UpdateUser([FromRoute] string userId, [FromBody] UserUpdate body)
        {
            var update = new PersonBodyUpdate
            {
                Email      = body.Email,
                FirstName  = body.FirstName,
                LastName   = body.LastName,
                Properties = new Dictionary <string, object>
                {
                    { SpisumNames.Properties.Group, body.MainGroup },
                    { SpisumNames.Properties.UserJob, body.UserJob },
                    { SpisumNames.Properties.UserOrgAddress, body.UserOrgAddress },
                    { SpisumNames.Properties.UserOrgId, body.UserOrgId },
                    { SpisumNames.Properties.UserOrgName, body.UserOrgName },
                    { SpisumNames.Properties.UserOrgUnit, body.UserOrgUnit },
                    { SpisumNames.Properties.UserName, $"{body.FirstName} {body.LastName}".Trim() },
                    { SpisumNames.Properties.UserId, body.UserId }
                }
            };

            if (!string.IsNullOrWhiteSpace(body.Password))
            {
                update.Password = body.Password;
            }

            var userInfo = await _alfrescoHttpClient.UpdatePerson(userId, update);

            var userGroupsInfo = await _alfrescoHttpClient.GetPersonGroups(userId);

            var userGroups = userGroupsInfo?.List?.Entries?.Select(x => x.Entry?.Id)?.Where(
                x => Array.IndexOf(new[] { SpisumNames.Groups.MainGroup, SpisumNames.Groups.Everyone }, x) == -1 && !x.StartsWith(SpisumNames.Prefixes.UserGroup)
                )?.ToList() ?? new List <string>();

            var allGroupsInfo = await _alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.MainGroup,
                                                                          ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));

            var allGroups  = allGroupsInfo?.List?.Entries?.Select(x => x.Entry?.Id)?.ToList() ?? new List <string>();
            var signGroups = body.SignGroups ?? new List <string>();

            var groupList = body.Groups?.ToList() ?? new List <string>();

            groupList.AddUnique(body.MainGroup);
            groupList.AddRangeUnique(signGroups);

            // remove all groups included in main groups
            for (int i = userGroups.Count - 1; i >= 0; i--)
            {
                var group = userGroups[i];
                if (allGroups.Exists(x => x.StartsWith(@group)) && !groupList.Contains(@group) ||
                    @group.EndsWith(SpisumNames.Postfixes.Sign) && !signGroups.Contains(@group))
                {
                    try
                    {
                        await _alfrescoHttpClient.DeleteGroupMember(@group, userId);

                        userGroups.RemoveAt(i);
                    }
                    catch
                    {
                    }
                }
            }

            foreach (var group in groupList.Where(x => !userGroups.Contains(x)))
            {
                try
                {
                    await _alfrescoHttpClient.CreateGroupMember(@group, new GroupMembershipBodyCreate { Id = userInfo.Entry.Id, MemberType = GroupMembershipBodyCreateMemberType.PERSON });
                }
                catch
                {
                }
            }

            foreach (var group in signGroups.Where(x => !userGroups.Contains(x + SpisumNames.Postfixes.Sign)))
            {
                try
                {
                    await _initialUser.CheckCreateGroupAndAddPerson(userInfo.Entry.Id, @group + SpisumNames.Postfixes.Sign);
                }
                catch
                {
                }
            }

            return(userInfo);
        }