Exemplo n.º 1
0
        private IEnumerable <UserGroup> GetUserGroupsOfUserContributor(DataSourceRequest request, UserGroupType userGroupType, UserContext userContext, OwnerLevel viewLevel)
        {
            var siteContext  = _siteContextAccessor.GetContext();
            var accessLevels = new AccessLevel[] { AccessLevel.Contributor, AccessLevel.FullAccess };
            var list         = new List <UserGroup>();

            // Get the client and site groups that the user has a membership to.
            var userQuery   = _userGroupManager.GetUserGroupsAssignedToUserWithAccessLevelQuery(userContext.UserId, accessLevels, userGroupType);
            var userResults = userQuery.ToDataSourceResult(request);

            list.AddRange(userResults.Data.Cast <UserGroup>());

            // Get the groups that have been created by this user
            var ownerQuery   = _userGroupManager.GetUserGroupsOfOwnerAndTypeQuery(OwnerLevel.User, userContext.UserId, userGroupType);
            var ownerResults = ownerQuery.ToDataSourceResult(request);

            list.AddRange(ownerResults.Data.Cast <UserGroup>());

            var corpId = new CorpGlobalClaimValueResolver().Resolve();

            if (viewLevel.Equals(OwnerLevel.Client))
            {
                // Get the client groups if the user has that claim
                if (userContext.SecurityClaims.Find(ClientClaimTypes.AppNotificationsSend, siteContext.Client.Id) ||
                    userContext.SecurityClaims.Find(ClientClaimTypes.AppNotificationsSend, corpId) ||
                    userContext.SecurityClaims.Find(ClientClaimTypes.PrimaryAdmin, siteContext.Client.Id) ||
                    userContext.SecurityClaims.Find(ClientClaimTypes.PrimaryAdmin, corpId) ||
                    userContext.SecurityClaims.Find(CorpClaimTypes.CorpPrimaryAdmin, corpId))
                {
                    var clientQuery   = _userGroupManager.GetUserGroupsOfOwnerAndTypeQuery(OwnerLevel.Client, siteContext.Client.Id, userGroupType);
                    var clientResults = clientQuery.ToDataSourceResult(request);
                    list.AddRange(clientResults.Data.Cast <UserGroup>());
                }
            }

            if (viewLevel.Equals(OwnerLevel.Site))
            {
                // Get the site groups if the user has that claim
                if (userContext.SecurityClaims.Find(SiteClaimTypes.SiteNotificationsSend, siteContext.Client.Id) ||
                    userContext.SecurityClaims.Find(SiteClaimTypes.SiteNotificationsSend, siteContext.SiteId) ||
                    userContext.SecurityClaims.Find(SiteClaimTypes.SiteNotificationsSend, corpId) ||
                    userContext.SecurityClaims.Find(SiteClaimTypes.SitePrimaryAdmin, siteContext.Client.Id) ||
                    userContext.SecurityClaims.Find(SiteClaimTypes.SitePrimaryAdmin, siteContext.SiteId) ||
                    userContext.SecurityClaims.Find(SiteClaimTypes.SitePrimaryAdmin, corpId) ||
                    userContext.SecurityClaims.Find(CorpClaimTypes.CorpPrimaryAdmin, corpId))
                {
                    var siteQuery   = _userGroupManager.GetUserGroupsOfOwnerAndTypeQuery(OwnerLevel.Site, siteContext.SiteId, userGroupType);
                    var siteResults = siteQuery.ToDataSourceResult(request);
                    list.AddRange(siteResults.Data.Cast <UserGroup>());
                }
            }

            var list2 = list.GroupBy(x => x.Id).Select(x => x.First());

            return(list2.OrderBy(x => x.Name).ToList());
        }
        private JsonResult GetUserGroups([DataSourceRequest] DataSourceRequest request, string ownerLevel, string ownerId, UserGroupType userGroupType)
        {
            var oLevel       = ownerLevel.ToEnum <OwnerLevel>();
            var accessLevels = new AccessLevel[] { AccessLevel.Contributor, AccessLevel.FullAccess };
            var userQuery    = _userGroupManager.GetUserGroupsAssignedToUserWithAccessLevelQuery(ownerId, accessLevels, userGroupType);
            var ownerQuery   = _userGroupManager.GetUserGroupsOfOwnerAndTypeQuery(oLevel, ownerId, userGroupType);

            var userResults  = userQuery.ToDataSourceResult(request);
            var ownerResults = ownerQuery.ToDataSourceResult(request);

            // note that the ToDataSourceResult function has issues with IQuereiables resulting from a Union function.
            var list = new List <UserGroup>();

            list.AddRange(userResults.Data.Cast <UserGroup>());
            foreach (UserGroup item in ownerResults.Data)
            {
                if (!list.Where(x => x.Id == item.Id).Any())
                {
                    list.Add(item);
                }
            }

            var result = list.ToDataSourceResult(request);

            return(Json(result));
        }
Exemplo n.º 3
0
        public async Task <JsonResult> Data([DataSourceRequest] DataSourceRequest request, string ownerLevel, string ownerId, string userGroupType)
        {
            var oLevel = ownerLevel.ToEnum <OwnerLevel>();
            var ugType = userGroupType.ToEnum <UserGroupType>();
            var query  = _userGroupManager.GetUserGroupsOfOwnerAndTypeQuery(oLevel, ownerId, ugType);
            var result = query.ToDataSourceResult(request);

            return(Json(result));
        }