Пример #1
0
        private PageDirectoryRoute MapRoute(PageDirectory dbDirectory)
        {
            MissingIncludeException.ThrowIfNull(dbDirectory, d => d.PageDirectoryLocales);
            MissingIncludeException.ThrowIfNull(dbDirectory, d => d.AccessRules);

            var route = new PageDirectoryRoute();

            route.Name                  = dbDirectory.Name;
            route.PageDirectoryId       = dbDirectory.PageDirectoryId;
            route.ParentPageDirectoryId = dbDirectory.ParentPageDirectoryId;
            route.UrlPath               = dbDirectory.UrlPath;

            route.LocaleVariations = dbDirectory
                                     .PageDirectoryLocales
                                     .Select(d => new PageDirectoryRouteLocale()
            {
                LocaleId = d.LocaleId,
                UrlPath  = d.UrlPath
            })
                                     .ToList();

            route.AccessRuleSets = new List <EntityAccessRuleSet>();
            var accessRuleSet = _entityAccessRuleSetMapper.Map(dbDirectory);

            if (accessRuleSet != null)
            {
                route.AccessRuleSets.Add(accessRuleSet);
            }

            // FullUrlPaths set elsewhere

            return(route);
        }
        public EntityAccessRuleSet Map <TAccessRule>(IEntityAccessRestrictable <TAccessRule> entity)
            where TAccessRule : IEntityAccessRule
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            MissingIncludeException.ThrowIfNull(entity, e => e.AccessRules);

            if (!entity.AccessRules.Any())
            {
                // no rules, so return null rather than an empty ruleset
                return(null);
            }

            var violationAction = EnumParser.ParseOrNull <AccessRuleViolationAction>(entity.AccessRuleViolationActionId);

            if (violationAction == null)
            {
                _logger.LogWarning(
                    "AccessRuleViolationAction of value {AccessRuleViolationAction} could not be parsed on rule type {TAccessRule}.",
                    entity.AccessRuleViolationActionId,
                    typeof(TAccessRule).Name
                    );
            }


            var result = new EntityAccessRuleSet()
            {
                ViolationAction = violationAction ?? AccessRuleViolationAction.Error
            };

            if (!string.IsNullOrWhiteSpace(entity.UserAreaCodeForSignInRedirect))
            {
                var userArea = _userAreaDefinitionRepository.GetRequiredByCode(entity.UserAreaCodeForSignInRedirect);
                result.UserAreaCodeForSignInRedirect = userArea.UserAreaCode;
            }

            result.AccessRules = entity
                                 .AccessRules
                                 .OrderByDefault()
                                 .Select(r => MapAccessRule(r))
                                 .ToArray();

            return(result);
        }
Пример #3
0
        public PageDirectoryMicroSummary Map(PageDirectory pageDirectory)
        {
            if (pageDirectory == null)
            {
                return(null);
            }
            MissingIncludeException.ThrowIfNull(pageDirectory, c => c.PageDirectoryPath);

            var result = new PageDirectoryMicroSummary()
            {
                Depth                 = pageDirectory.PageDirectoryPath.Depth,
                FullUrlPath           = "/" + pageDirectory.PageDirectoryPath.FullUrlPath,
                Name                  = pageDirectory.Name,
                PageDirectoryId       = pageDirectory.PageDirectoryId,
                ParentPageDirectoryId = pageDirectory.ParentPageDirectoryId
            };

            return(result);
        }