Glyma.SharePoint.Security.GlymaSecurityGroupCollection.FilterGroups C# (CSharp) Method

FilterGroups() private method

Filters the GlymaSPSecurityGroup dictionary so that groups only return for the highest permission level they've been granted.
private FilterGroups ( ) : IList>.IDictionary
return IList>.IDictionary
        internal IDictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> FilterGroups()
        {
            IDictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> result = new Dictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>>();

            IList<GlymaSecurityGroup> mapManagersGroups = _groups[GlymaPermissionLevel.GlymaMapManager];
            IList<GlymaSecurityGroup> mapAuthorGroups = _groups[GlymaPermissionLevel.GlymaMapAuthor];
            IList<GlymaSecurityGroup> mapReaderGroups = _groups[GlymaPermissionLevel.GlymaMapReader];
            IList<GlymaSecurityGroup> oldMapReaderGroups = _groups[GlymaPermissionLevel.GlymaMapReaderOld];
            IList<GlymaSecurityGroup> oldMapAuthorGroups = _groups[GlymaPermissionLevel.GlymaMapAuthorOld];

            //The Project Managers group doesn't get filtered
            result.Add(GlymaPermissionLevel.GlymaProjectManager, _groups[GlymaPermissionLevel.GlymaProjectManager]);

            //Filter the Old Map Readers
            IList<GlymaSecurityGroup> filteredOldMapReaderGroups = new List<GlymaSecurityGroup>();
            foreach (GlymaSecurityGroup oldMapReader in oldMapReaderGroups)
            {
                if (!ExistsInHigherPermissionLevel(oldMapReader, GlymaPermissionLevel.GlymaMapReader))
                {
                    filteredOldMapReaderGroups.Add(oldMapReader);
                }
            }
            result.Add(GlymaPermissionLevel.GlymaMapReader, filteredOldMapReaderGroups);

            //Filter the Map Readers
            IList<GlymaSecurityGroup> filteredMapReaderGroups = new List<GlymaSecurityGroup>();
            foreach (GlymaSecurityGroup mapReader in mapReaderGroups)
            {
                if (!ExistsInHigherPermissionLevel(mapReader, GlymaPermissionLevel.GlymaMapReader))
                {
                    filteredMapReaderGroups.Add(mapReader);
                }
            }
            foreach (GlymaSecurityGroup filteredMapReader in filteredMapReaderGroups)
            {
                if (!result[GlymaPermissionLevel.GlymaMapReader].Contains(filteredMapReader))
                {
                    result[GlymaPermissionLevel.GlymaMapReader].Add(filteredMapReader);
                }
            }

            //Filter the Old Map Authors
            IList<GlymaSecurityGroup> filteredOldMapAuthorGroups = new List<GlymaSecurityGroup>();
            foreach (GlymaSecurityGroup oldMapAuthor in oldMapAuthorGroups)
            {
                if (!ExistsInHigherPermissionLevel(oldMapAuthor, GlymaPermissionLevel.GlymaMapAuthor))
                {
                    filteredOldMapAuthorGroups.Add(oldMapAuthor);
                }
            }
            result.Add(GlymaPermissionLevel.GlymaMapAuthor, filteredOldMapAuthorGroups);

            //Filter the Map Authors
            IList<GlymaSecurityGroup> filteredMapAuthorGroups = new List<GlymaSecurityGroup>();
            foreach (GlymaSecurityGroup mapAuthor in mapAuthorGroups)
            {
                if (!ExistsInHigherPermissionLevel(mapAuthor, GlymaPermissionLevel.GlymaMapAuthor))
                {
                    filteredMapAuthorGroups.Add(mapAuthor);
                }
            }
            foreach (GlymaSecurityGroup filteredMapAuthor in filteredMapAuthorGroups)
            {
                if (!result[GlymaPermissionLevel.GlymaMapAuthor].Contains(filteredMapAuthor))
                {
                    result[GlymaPermissionLevel.GlymaMapAuthor].Add(filteredMapAuthor);
                }
            }

            //Filter the Map Managers
            IList<GlymaSecurityGroup> filteredMapManagersGroups = new List<GlymaSecurityGroup>();
            foreach (GlymaSecurityGroup mapManager in mapManagersGroups)
            {
                if (!ExistsInHigherPermissionLevel(mapManager, GlymaPermissionLevel.GlymaMapManager))
                {
                    filteredMapManagersGroups.Add(mapManager);
                }
            }
            result.Add(GlymaPermissionLevel.GlymaMapManager, filteredMapManagersGroups);

            return result;
        }

Usage Example

        internal GetAllSecurityGroupsResponse GetAllGlymaSecurityGroups()
        {
            GetAllSecurityGroupsResponse result = new GetAllSecurityGroupsResponse() { HasError = false };

            IList<string> permissionLevelNames = new List<string>();
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaProjectManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthor));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReader));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReaderOld));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthorOld));

            Dictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> results = new Dictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>>();
            foreach (string permissionLevelName in permissionLevelNames)
            {
                GlymaPermissionLevel permissionLevel = GlymaPermissionLevelHelper.GetPermissionLevelByName(permissionLevelName);
                GetSecurityGroupsResponse response = GetSecurityGroups(permissionLevel);
                if (!response.HasError)
                {
                    IList<GlymaSecurityGroup> groups = response.Result;
                    if (results.ContainsKey(permissionLevel))
                    {
                        foreach (GlymaSecurityGroup group in groups)
                        {
                            if (!results[permissionLevel].Contains(group))
                            {
                                results[permissionLevel].Add(group);
                            }
                        }
                    }
                    else
                    {
                        results.Add(permissionLevel, groups);
                    }
                }
                else
                {
                    result.HasError = true;
                    result.ErrorMessage = response.ErrorMessage;
                    break; //an error occurred so stop at this point
                }
            }
            if (!result.HasError)
            {
                GlymaSecurityGroupCollection groups = new GlymaSecurityGroupCollection(this, results);
                IDictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> filteredGroups = groups.FilterGroups();
                result.Result = filteredGroups;
            }

            return result;
        }
All Usage Examples Of Glyma.SharePoint.Security.GlymaSecurityGroupCollection::FilterGroups