Esempio n. 1
0
 public async Task Delete([FromRoute] string groupId)
 {
     if (Array.IndexOf(new[] {
         SpisumNames.Groups.DispatchGroup,
         SpisumNames.Groups.MainGroup,
         SpisumNames.Groups.MailroomGroup,
         SpisumNames.Groups.RepositoryGroup,
         SpisumNames.Groups.RolesGroup,
         SpisumNames.Groups.SpisumAdmin
     }, groupId) == -1)
     {
         await _alfrescoHttpClient.DeleteGroupMember(SpisumNames.Groups.MainGroup, groupId);
     }
     else
     {
         throw new ForbiddenException("403", "This Group can't be deleted");
     }
 }
Esempio 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);
        }