示例#1
0
 /// <summary>
 /// Refresh the rules so any changes are reflected immediately without site restart
 /// </summary>
 private void RefreshRules()
 {
     using (var context = _factory.EnsureUmbracoContext())
     {
         Rules      = new List <KeepOutRule>();
         RulesPages = new List <string>();
         var rulesFolder = context.UmbracoContext.Content.GetById(KeepOutRulesFolderId);
         var rules       = rulesFolder.Children
                           .Where(x => x.IsPublished() && x.ContentType.Alias == "keepOutSecurityRule")
                           .OrderBy(x => x.CreateDate);
         foreach (var rule in rules)
         {
             var coverageColour     = rule.Properties.Single(x => x.Alias == "coverageColour").GetValue() as ColorPickerValueConverter.PickedColor;
             var deniedMemberGroups = new List <string>();
             var memberGroupIds     = rule.Properties.Single(x => x.Alias == "deniedMemberGroups").GetValue().ToString().Split(new [] { ',' }).ToList();
             foreach (var memberGroupId in memberGroupIds)
             {
                 var intMemberGroupId = int.Parse(memberGroupId);
                 var memberGroup      = _memberGroupService.GetById(intMemberGroupId);
                 deniedMemberGroups.Add(memberGroup.Name);
             }
             var noAccessPage = rule.Properties.Single(x => x.Alias == "noAccessPage").GetValue() as IPublishedContent;
             var pageToSecure = rule.Properties.Single(x => x.Alias == "pageToSecure").GetValue() as IPublishedContent;
             var keepOutRule  = new KeepOutRule
             {
                 CoverageColour     = "keepout-" + coverageColour.Label,
                 DeniedMemberGroups = deniedMemberGroups,
                 NoAccessPage       = noAccessPage.Id,
                 PageToSecure       = pageToSecure.Id
             };
             Rules.Add(keepOutRule);
             RulesPages.Add(keepOutRule.PageToSecure.ToString());
         }
     }
 }
示例#2
0
        /// <summary>
        /// Refresh the rules so any changes are reflected immediately without site restart
        /// </summary>
        private void RefreshRules()
        {
            var cs = ApplicationContext.Current.Services.ContentService;

            Rules      = new List <KeepOutRule>();
            RulesPages = new List <string>();
            var rules = cs.GetChildren(KeepOutRulesFolder.Id).Where(x => x.ContentType.Alias == "keepOutSecurityRule").ToList();

            foreach (var rule in rules)
            {
                var keepOutRule = new KeepOutRule(rule);
                Rules.Add(keepOutRule);
                RulesPages.Add(keepOutRule.PageToSecure.ToString());
                LogHelper.Debug <KeepOutHandler>("Rule was added");
            }
        }