Exemplo n.º 1
0
            internal static List <int> GetAllUserIds(SecurityGroup group)
            {
                var allChildGroups = new List <SecurityGroup>();

                CollectAllChildGroups(group, allChildGroups);

                var userIds = new List <int>();

                foreach (var g in allChildGroups)
                {
                    foreach (var u in g.UserMemberIds)
                    {
                        if (!userIds.Contains(u))
                        {
                            userIds.Add(u);
                        }
                    }
                }
                return(userIds);
            }
Exemplo n.º 2
0
            internal void AddUserToGroup(int userId, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable)
            {
                // collect all relevant groupId from the parent axis
                var allParentGroupIds = GetAllParentGroupIdsInclusive(parentGroup);

                // ensure user
                if (!usersTable.TryGetValue(userId, out var user))
                {
                    user = new List <int>();
                    usersTable.Add(userId, user);
                }

                // complete the user (distinct groupId list) with the relevant groups (allParentGroupIds)
                foreach (var parentGroupId in allParentGroupIds)
                {
                    if (!user.Contains(parentGroupId))
                    {
                        user.Add(parentGroupId);
                    }
                }
            }
Exemplo n.º 3
0
            private void CollectAllChildGroups(SecurityGroup group, List <SecurityGroup> allChildGroups)
            {
                // avoid infinite loop because of circular reference
                if (allChildGroups.Contains(group))
                {
                    return;
                }
                // stop if there isn't any parent
                if (group.Groups == null)
                {
                    return;
                }

                // collect
                allChildGroups.Add(group);

                // do recursion
                foreach (var childGroup in group.Groups)
                {
                    CollectAllChildGroups(childGroup, allChildGroups);
                }
            }
Exemplo n.º 4
0
            internal void AddGroupToGroup(SecurityGroup group, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable)
            {
                var allUserIds        = GetAllUserIds(group);
                var allParentGroupIds = GetAllParentGroupIdsInclusive(parentGroup);

                foreach (var userId in allUserIds)
                {
                    if (!usersTable.TryGetValue(userId, out var user))
                    {
                        user = new List <int>();
                        usersTable.Add(userId, user);
                    }

                    foreach (var parentGroupId in allParentGroupIds)
                    {
                        if (!user.Contains(parentGroupId))
                        {
                            user.Add(parentGroupId);
                        }
                    }
                }
            }
Exemplo n.º 5
0
            internal void RemoveUserFromGroup(int userId, SecurityGroup parentGroup, Dictionary <int, List <int> > usersTable, IDictionary <int, SecurityGroup> groupsTable)
            {
                var allParents = GetAllParentGroupIdsInclusive(parentGroup);

                RemoveUserFromGroup(userId, allParents, usersTable, groupsTable);
            }
Exemplo n.º 6
0
 internal IEnumerable <int> GetAllParentGroupIds(SecurityGroup group)
 {
     return(Flattener.GetAllParentGroupIdsExclusive(group));
 }
Exemplo n.º 7
0
 internal IEnumerable <int> GetAllUsersInGroup(SecurityGroup group)
 {
     return(Flattener.GetAllUserIds(group));
 }
Exemplo n.º 8
0
 private static IEnumerable <int> GetDirectOnlyParentGroups(SecurityGroup group)
 {
     return(group.ParentGroups
            .Select(g => g.Id)
            .ToArray());
 }
Exemplo n.º 9
0
 private static IEnumerable <int> GetAllParentGroups(SecurityContext context, SecurityGroup group)
 {
     return(context.Cache.GetAllParentGroupIds(group));
 }