public override IEnumerable <TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) { if (definition.PartDefinition.Name != TerritoryHierarchyPart.PartName) { yield break; } var settings = definition.Settings.GetModel <TerritoryHierarchyPartSettings>(); if (string.IsNullOrWhiteSpace(settings.TerritoryType)) { settings.TerritoryType = _territoriesService.GetTerritoryTypes().FirstOrDefault()?.Name; } yield return(DefinitionTemplate(ViewModel(settings))); }
protected override DriverResult Editor(TerritoryHierarchyPart part, dynamic shapeHelper) { var shapes = new List <DriverResult>(); //part.Id == 0: new item if (part.Id != 0) { //if the part is fully configured add a shape that allows managing the territories in the hierarchy if (!string.IsNullOrWhiteSpace(part.TerritoryType)) { if (_territoriesService.GetTerritoryTypes().Any(tt => tt.Name == part.TerritoryType)) { // add the shape for the territories in the hierachy shapes.Add(ContentShape("Parts_TerritoryHierarchy_TerritoryManager", () => shapeHelper.EditorTemplate( TemplateName: "Parts/TerritoryHierarchyTerritoryManager", Model: new TerritoryHierarchyTerritoryManagerViewModel(part) { TopLevelCount = _territoriesService .GetTerritoriesQuery(part, null, VersionOptions.Latest) .Count() }, Prefix: Prefix ))); } else { _notifier.Warning(T("You are not allowed to manage the territories for this hierarchy.")); } } } //add a shape for configuration of the part //Some configuration options may be locked depending on the territories in the hierarchy //e.g. once there are territories, we cannot change the TerritoryType anymore shapes.Add(ContentShape("Parts_TerritoryHierarchy_TerritoryTypeSelection", () => shapeHelper.EditorTemplate( TemplateName: "Parts/TerritoryHierarchyTerritoryTypeSelection", Model: TypeSelectionVM(part), Prefix: Prefix ))); return(Combined(shapes.ToArray())); }
/// <summary> /// This method gets all the territory types the current user is allowed to manage. /// </summary> /// <returns>Returns the types the user is allowed to manage. Returns null if the user lacks the correct /// permissions to be invoking these actions.</returns> private IEnumerable <ContentTypeDefinition> GetAllowedTerritoryTypes() { var allowedTypes = _territoriesService.GetTerritoryTypes(); if (!allowedTypes.Any() && //no dynamic permissions !_authorizer.Authorize(TerritoriesPermissions.ManageTerritories)) { return(null); } return(allowedTypes); }
public void TerritoryManagePermissionsAreSameNumberAsTerritoryTypesForUserWithAllPermissions() { Assert.That(_territoriesService.GetTerritoryTypes().Count(), Is.EqualTo(3)); Assert.That(_permissionProvider.ListTerritoryTypePermissions().Count(), Is.EqualTo(3)); }