示例#1
0
 public bool CanEditSettingsJson(
     IReadOnlyDictionary <string, RoleCached> userGroups,
     CategoryCached category)
 {
     return(authorizationService.HasAccess(userGroups, category, OperationKeys.MaterialEditSettingsJson));
 }
 public bool CanCache(CategoryCached category, int?page = null)
 {
     return(false);
 }
示例#3
0
 public bool CanBlockComments(
     IReadOnlyDictionary <string, RoleCached> userGroups,
     CategoryCached category)
 {
     return(authorizationService.HasAccess(userGroups, category, OperationKeys.MaterialBlockCommentsAny));
 }
示例#4
0
 public bool CanCache(CategoryCached category, RequestOptions options)
 {
     return((!options.PageNumber.HasValue || options.PageNumber.Value == 1) && category.IsCacheContent);
 }
示例#5
0
        public virtual CategoryInfoWithAccesses GetCategoryInfoWithAccesses(
            CategoryCached category,
            IReadOnlyDictionary <string, RoleCached> roles)
        {
            if (!authorizationService.HasAccess(roles, category, OperationKeys.MaterialAndCommentsRead) &&
                category.Id != categoriesCache.RootCategory.Id)
            {
                return(null);
            }

            CategoryInfoWithAccesses categoryInfo = new CategoryInfoWithAccesses
            {
                Id                          = category.Id,
                Name                        = category.Name,
                UrlPath                     = category.UrlPath,
                ShowInBreadcrumbs           = category.ShowInBreadcrumbs,
                Title                       = category.Title,
                SubTitle                    = category.SubTitle,
                Icon                        = category.Icon,
                Header                      = category.Header,
                IsMaterialsContainer        = category.IsMaterialsContainer,
                SortNumber                  = category.SortNumber,
                LayoutName                  = category.LayoutName,
                IsMaterialsSubTitleEditable = category.IsMaterialsSubTitleEditable,
                IsMaterialsNameEditable     = category.IsMaterialsNameEditable,
                SettingsJson                = category.SettingsJson,
                IsHidden                    = category.IsHidden,

                CategoryPersonalAccess = DetectPersonalAccesses(category, roles)
            };


            if (category.SubCategories == null)
            {
                return(categoryInfo);
            }

            IEnumerable <CategoryCached> where;
            if (roles.Any(x => x.Value.Name == RoleNames.Admin))             // Admin can see all categories, including hidden
            {
                where = category.SubCategories;
            }
            else
            {
                where = category.SubCategories.Where(x => !x.IsHidden);
            }

            if (!where.Any())
            {
                return(categoryInfo);
            }

            categoryInfo.SubCategories = new List <CategoryInfoWithAccesses>(category.SubCategories.Count);

            foreach (var child in where.OrderBy(x => x.SortNumber))
            {
                var childInfo = GetCategoryInfoWithAccesses(child, roles);
                if (childInfo == null)
                {
                    continue;
                }

                categoryInfo.SubCategories.Add(childInfo);
            }

            return(categoryInfo);
        }
        public HashSet <int> HasAccess(IReadOnlyDictionary <string, RoleCached> roles, CategoryCached category,
                                       IEnumerable <int> operationKeys)
        {
            if (roles.ContainsKey(RoleNames.Admin))
            {
                operationKeys.ToHashSet();
            }

            HashSet <int> operationKeysReturn = new HashSet <int>();

            foreach (int operationKey in operationKeys)
            {
                if (HasAccess(roles, category, operationKey))
                {
                    operationKeysReturn.Add(operationKey);
                }
            }

            return(operationKeysReturn);
        }
 public bool CanCache(CategoryCached category, int?page = null)
 {
     return(category.IsCacheContent);
 }
 public bool CanGet(IReadOnlyDictionary <string, RoleCached> roles, CategoryCached category)
 {
     return(authorizationService.HasAccess(roles, category, OperationKeys.MaterialAndCommentsRead));
 }