diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs index 44f0b31c25..503d58de8c 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using System.Runtime.Serialization; namespace Umbraco.Cms.Core.Models.ContentEditing @@ -16,8 +13,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { Tabs = new List>(); Notifications = new List(); + AllowedActions = Enumerable.Empty(); } + [DataMember(Name = "AllowedActions", IsRequired = true)] + public IEnumerable AllowedActions { get; set; } + [DataMember(Name = "name", IsRequired = true)] public string? Name { get; set; } diff --git a/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs index 2f330b581f..a498bdb072 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs @@ -1,9 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models.ContentEditing; +using Umbraco.Cms.Core.Models.Membership; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Models.Mapping @@ -12,11 +16,17 @@ namespace Umbraco.Cms.Core.Models.Mapping { private readonly ILocalizationService _localizationService; private readonly ILocalizedTextService _localizedTextService; + private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - public ContentVariantMapper(ILocalizationService localizationService, ILocalizedTextService localizedTextService) + public ContentVariantMapper(ILocalizationService localizationService, ILocalizedTextService localizedTextService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); + _backOfficeSecurityAccessor = backOfficeSecurityAccessor; + } + public ContentVariantMapper(ILocalizationService localizationService, ILocalizedTextService localizedTextService) + : this(localizationService, localizedTextService, StaticServiceProvider.Instance.GetRequiredService()) + { } public IEnumerable Map(IContent source, MapperContext context) where TVariant : ContentVariantDisplay @@ -147,6 +157,29 @@ namespace Umbraco.Cms.Core.Models.Mapping } variantDisplay.Segment = segment; variantDisplay.Language = language; + + // Map allowed actions + IEnumerable? userGroups = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Groups; + bool hasAccess = false; + if (userGroups is not null) + { + foreach (var group in userGroups) + { + if ((variantDisplay.Language is not null && group.AllowedLanguages.Contains(variantDisplay.Language.Id)) || group.AllowedLanguages.Any() is false) + { + hasAccess = true; + break; + } + } + + if (hasAccess) + { + variantDisplay.AllowedActions = new[] + { + "C", "A", "D", "M", "O", "S", "K", "T", "P", "I", "U", "R", "Z", ":", "7", "ï", "N" + }; + } + } variantDisplay.Name = content.GetCultureName(language?.IsoCode); variantDisplay.DisplayName = GetDisplayName(language, segment); diff --git a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs index 24cd1c5cbe..66bc3a807c 100644 --- a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs +++ b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs @@ -175,6 +175,7 @@ namespace Umbraco.Cms.Web.BackOffice.Mapping target.State = _stateMapper.Map(source, context); target.Tabs = _tabsAndPropertiesMapper.Map(source, context); target.UpdateDate = source.UpdateDate; + target.AllowedActions = new[] {"F"}; } private void Map(IContent source, ContentVariantScheduleDisplay target, MapperContext context)