Esempio 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);
            }
Esempio 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);
                    }
                }
            }
Esempio 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);
                }
            }
Esempio 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);
                        }
                    }
                }
            }
Esempio 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);
            }
Esempio n. 6
0
 internal IEnumerable <int> GetAllParentGroupIds(SecurityGroup group)
 {
     return(Flattener.GetAllParentGroupIdsExclusive(group));
 }
Esempio n. 7
0
 internal IEnumerable <int> GetAllUsersInGroup(SecurityGroup group)
 {
     return(Flattener.GetAllUserIds(group));
 }
Esempio n. 8
0
 private static IEnumerable <int> GetDirectOnlyParentGroups(SecurityGroup group)
 {
     return(group.ParentGroups
            .Select(g => g.Id)
            .ToArray());
 }
Esempio n. 9
0
 private static IEnumerable <int> GetAllParentGroups(SecurityContext context, SecurityGroup group)
 {
     return(context.Cache.GetAllParentGroupIds(group));
 }