public List <VGAudit> GetVisitorGroups() { return(_vgRepo.List().Select(vg => new VGAudit() { Name = vg.Name, CriteriaCount = vg.Criteria.Count, Id = vg.Id, Usages = VisitorGroupUse.ListForVisitorGroup(vg.Id.ToString()).ToList() }).ToList()); }
public void CreateKeyFragment_GenerateKeyFragmentFromSpecificVisitorGroup_ReturnStringWithVisitorGroupValue(IContent content, ICacheableSettings cacheableSettings, IViewDataContainer viewDataContainer, [Frozen] IVisitorGroupService visitorGroupService, [Frozen] IVisitorGroupRepository visitorGroupRepository, [Frozen] IEnumerable <VisitorGroup> visitorGroups, VisitorGroupKeyFragmentFactory visitorGroupKeyFragmentFactory) { var htmlHelper = new HtmlHelper(A.Fake <ViewContext>(), viewDataContainer); var visitorGroup = visitorGroups.First(); A.CallTo(() => visitorGroupRepository.List()).Returns(visitorGroups); A.CallTo(visitorGroupService) .Where(call => call.Method.Name == "IsUserInVisitorGroup" && (call.Arguments.ElementAtOrDefault(1) as string) == visitorGroup.Name) .WithReturnType <bool>() .Returns(true); A.CallTo(() => cacheableSettings.VaryBy).Returns(new[] { VaryBy.VisitorGroups }); A.CallTo(() => cacheableSettings.Parameters).Returns(new Dictionary <string, string> { { VaryBy.VisitorGroups, string.Join(",", visitorGroups.Select(vg => vg.Name)) } }); visitorGroupKeyFragmentFactory.CreateKeyFragment(htmlHelper, content, cacheableSettings).Should().Be($"{visitorGroup.Name}", "Because the returned value should be the specific role name from the visitor group "); }
public ActionResult RemoveAllVisitorGroups() { try { Debug.WriteLine("RemoveAllPulseVisitorGroups(): START"); // Get IVisitorGroupRepository IVisitorGroupRepository visitorGroupRepository = ServiceLocator.Current.GetInstance <IVisitorGroupRepository>(); // Create a list of GUIDs to delete List <Guid> toDeleteList = new List <Guid>(); // List trough all Visitor Group items foreach (VisitorGroup item in visitorGroupRepository.List()) { // Check if item contains Addon Name in Type Name VisitorGroupCriterion criteria = item.Criteria.Where(x => x.TypeName.Contains(Global.AddonName) || x.TypeName.Contains("PulseEpiserverConnector")).FirstOrDefault(); // Add it to the list for later deleting if (criteria != null) { Debug.WriteLine("Type name: " + criteria.TypeName); toDeleteList.Add(item.Id); } } // Delete all Visitor Group items if (toDeleteList.Any()) { foreach (Guid delete in toDeleteList) { visitorGroupRepository.Delete(delete); } } Debug.WriteLine("RemoveAllPulseVisitorGroups(): END"); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { Debug.WriteLine("RemoveAllPulseVisitorGroups(): Error: " + ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
/// <summary> /// Adds any Episerver visitor groups roles setup as security groups to claims identity /// </summary> /// <param name="identity"></param> /// <param name="httpContextBase"></param> /// <returns></returns> public async Task AddVisitorGroupRolesAsClaimsAsync(ClaimsIdentity identity, HttpContextBase httpContextBase = null) { if (identity == null || string.IsNullOrWhiteSpace(identity.Name)) { throw new ArgumentNullException(nameof(identity)); } var httpContext = httpContextBase ?? new HttpContextWrapper(HttpContext.Current); httpContext.User = httpContext.User ?? new ClaimsPrincipal(identity); // its null when user is authenticated... var visitorGroups = _visitorGroupRepository.List(); foreach (var visitorGroup in visitorGroups) { if (_visitorGroupRoleRepository.TryGetRole(visitorGroup.Name, out var virtualRoleObject) && virtualRoleObject.IsMatch(httpContext.User, httpContext)) { identity.AddClaim(new Claim(ClaimTypes.Role, virtualRoleObject.Name)); } } await Task.FromResult(0); }
public List <VisitorGroup> GetAllVisitorGroups() { return(_visitorGroupRepository.List().ToList()); }
public Stream ExportContent(ContentExport contentExport, ContentReference root) { var exporter = _dataExporterAccessor(); var exportedContentTypes = new HashSet <int>(); var sources = new List <ExportSource>(); if ((contentExport & ContentExport.ExportContentTypes) == ContentExport.ExportContentTypes) { _contentTypeRepository.List().ForEach(x => { exporter.AddContentType(x); exportedContentTypes.Add(x.ID); }); } if ((contentExport & ContentExport.ExportFrames) == ContentExport.ExportFrames) { _frameRepository().List().ForEach(exporter.AddFrame); } if ((contentExport & ContentExport.ExportTabDefinitions) == ContentExport.ExportTabDefinitions) { _tabDefinitionRepository.List().ForEach(exporter.AddTabDefinition); } if ((contentExport & ContentExport.ExportDynamicPropertyDefinitions) == ContentExport.ExportDynamicPropertyDefinitions) { _propertyDefinitionRepository.ListDynamic().ForEach(exporter.AddDynamicProperty); } if ((contentExport & ContentExport.ExportCategories) == ContentExport.ExportCategories) { ExportCategories(exporter, _categoryRepository.GetRoot()); } if ((contentExport & ContentExport.ExportPages) == ContentExport.ExportPages) { sources.Add(new ExportSource(root, ExportSource.RecursiveLevelInfinity)); } if ((contentExport & ContentExport.ExportVisitorGroups) == ContentExport.ExportVisitorGroups) { _visitorGroupRepository.List().ForEach(exporter.AddVisitorGroup); } var options = new ExportOptions { IncludeReferencedContentTypes = (contentExport & ContentExport.ExportContentTypeDependencies) == ContentExport.ExportContentTypeDependencies, ExportPropertySettings = (contentExport & ContentExport.ExportPropertySettings) == ContentExport.ExportPropertySettings, ExcludeFiles = false, AutoCloseStream = false }; var stream = new MemoryStream(); exporter.Export(stream, sources, options); ((DefaultDataExporter)exporter)?.Close(); stream.Position = 0; return(stream); }