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