From c94ee7c1ec886ab172e644bf7da042fe03bfe235 Mon Sep 17 00:00:00 2001 From: Zeegaan Date: Tue, 5 Jul 2022 12:40:33 +0200 Subject: [PATCH] Fix up wierd formatting --- .../ContentEditing/ContentVariationDisplay.cs | 6 +- .../Models/ContentRepositoryExtensions.cs | 35 +++-- .../Models/Mapping/UserMapDefinition.cs | 109 +++++++------- .../Models/Membership/UserGroupExtensions.cs | 2 +- .../Persistence/Constants-DatabaseSchema.cs | 2 +- src/Umbraco.Core/Services/ContentService.cs | 76 +++++----- .../Migrations/Upgrade/UmbracoPlan.cs | 4 +- .../Persistence/Factories/UserGroupFactory.cs | 22 ++- .../Controllers/ContentController.cs | 138 +++++++++--------- .../Filters/ContentSaveValidationAttribute.cs | 50 +++---- .../Mapping/ContentMapDefinition.cs | 2 +- 11 files changed, 222 insertions(+), 224 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs index c588fb1c1c..6418a7bca7 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs @@ -13,11 +13,11 @@ public class ContentVariantDisplay : ITabbedContent, ICo { Tabs = new List>(); Notifications = new List(); - AllowedActions = Enumerable.Empty(); + AllowedActions = Enumerable.Empty(); } - [DataMember(Name = "allowedActions", IsRequired = true)] - public IEnumerable AllowedActions { get; set; } + [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/ContentRepositoryExtensions.cs b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs index ecf63f48b6..d76194aa64 100644 --- a/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs +++ b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs @@ -293,18 +293,18 @@ public static class ContentRepositoryExtensions /// public static bool PublishCulture(this IContent content, CultureImpact? impact) { - if (impact == null) - { - throw new ArgumentNullException(nameof(impact)); - } + if (impact == null) + { + throw new ArgumentNullException(nameof(impact)); + } // the variation should be supported by the content type properties // if the content type is invariant, only '*' and 'null' is ok // if the content type varies, everything is ok because some properties may be invariant if (!content.ContentType.SupportsPropertyVariation(impact.Culture, "*", true)) - { - throw new NotSupportedException($"Culture \"{impact.Culture}\" is not supported by content type \"{content.ContentType.Alias}\" with variation \"{content.ContentType.Variations}\"."); - } + { + throw new NotSupportedException($"Culture \"{impact.Culture}\" is not supported by content type \"{content.ContentType.Alias}\" with variation \"{content.ContentType.Variations}\"."); + } // set names if (impact.ImpactsAllCultures) @@ -314,11 +314,11 @@ public static class ContentRepositoryExtensions { var name = content.GetCultureName(culture); if (string.IsNullOrWhiteSpace(name)) - { + { return false; - } + } - content.SetPublishInfo(culture, name, DateTime.Now); + content.SetPublishInfo(culture, name, DateTime.Now); } } else if (impact.ImpactsOnlyInvariantCulture) @@ -333,9 +333,9 @@ public static class ContentRepositoryExtensions { var name = content.GetCultureName(impact.Culture); if (string.IsNullOrWhiteSpace(name)) - { + { return false; - } + } content.SetPublishInfo(impact.Culture, name, DateTime.Now); } @@ -343,19 +343,18 @@ public static class ContentRepositoryExtensions // set values // property.PublishValues only publishes what is valid, variation-wise, // but accepts any culture arg: null, all, specific - foreach (IProperty property in content.Properties) + foreach (IProperty property in content.Properties) { // for the specified culture (null or all or specific) property.PublishValues(impact.Culture); // maybe the specified culture did not impact the invariant culture, so PublishValues // above would skip it, yet it *also* impacts invariant properties - if (impact.ImpactsAlsoInvariantProperties && - (property.PropertyType.VariesByCulture() is false || impact.ImpactsOnlyDefaultCulture)) - { - property.PublishValues(null); - } + if (impact.ImpactsAlsoInvariantProperties && (property.PropertyType.VariesByCulture() is false || impact.ImpactsOnlyDefaultCulture)) + { + property.PublishValues(null); } + } content.PublishedState = PublishedState.Publishing; return true; diff --git a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs index 2b5882b71a..eec5717dd3 100644 --- a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs @@ -32,20 +32,20 @@ public class UserMapDefinition : IMapDefinition private readonly IShortStringHelper _shortStringHelper; private readonly ILocalizedTextService _textService; private readonly IUserService _userService; - private readonly ILocalizationService _localizationService; + private readonly ILocalizationService _localizationService; - public UserMapDefinition( - ILocalizedTextService textService, - IUserService userService, - IEntityService entityService, - ISectionService sectionService, - AppCaches appCaches, - ActionCollection actions, - IOptions globalSettings, - MediaFileManager mediaFileManager, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator, - ILocalizationService localizationService) + public UserMapDefinition( + ILocalizedTextService textService, + IUserService userService, + IEntityService entityService, + ISectionService sectionService, + AppCaches appCaches, + ActionCollection actions, + IOptions globalSettings, + MediaFileManager mediaFileManager, + IShortStringHelper shortStringHelper, + IImageUrlGenerator imageUrlGenerator, + ILocalizationService localizationService) { _sectionService = sectionService; _entityService = entityService; @@ -57,33 +57,34 @@ public class UserMapDefinition : IMapDefinition _mediaFileManager = mediaFileManager; _shortStringHelper = shortStringHelper; _imageUrlGenerator = imageUrlGenerator; - _localizationService = localizationService; - } - [Obsolete("Please use constructor that takes an ILocalizationService instead")] - public UserMapDefinition( - ILocalizedTextService textService, - IUserService userService, - IEntityService entityService, - ISectionService sectionService, - AppCaches appCaches, - ActionCollection actions, - IOptions globalSettings, - MediaFileManager mediaFileManager, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator) - : this( - textService, - userService, - entityService, - sectionService, - appCaches, - actions, - globalSettings, - mediaFileManager, - shortStringHelper, - imageUrlGenerator, - StaticServiceProvider.Instance.GetRequiredService()) - { + _localizationService = localizationService; + } + + [Obsolete("Please use constructor that takes an ILocalizationService instead")] + public UserMapDefinition( + ILocalizedTextService textService, + IUserService userService, + IEntityService entityService, + ISectionService sectionService, + AppCaches appCaches, + ActionCollection actions, + IOptions globalSettings, + MediaFileManager mediaFileManager, + IShortStringHelper shortStringHelper, + IImageUrlGenerator imageUrlGenerator) + : this( + textService, + userService, + entityService, + sectionService, + appCaches, + actions, + globalSettings, + mediaFileManager, + shortStringHelper, + imageUrlGenerator, + StaticServiceProvider.Instance.GetRequiredService()) + { } public void DefineMaps(IUmbracoMapper mapper) @@ -264,10 +265,10 @@ public class UserMapDefinition : IMapDefinition target.Path = "-1," + source.Id; target.IsSystemUserGroup = source.IsSystemUserGroup(); - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); + MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); } - // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications + // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications // Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -IsSystemUserGroup private void Map(IUserGroup source, UserGroupBasic target, MapperContext context) { @@ -281,7 +282,7 @@ public class UserMapDefinition : IMapDefinition target.UserCount = source.UserCount; target.IsSystemUserGroup = source.IsSystemUserGroup(); - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); + MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); } // Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -AssignedPermissions @@ -303,7 +304,7 @@ public class UserMapDefinition : IMapDefinition } } - // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications -Udi + // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications -Udi // Umbraco.Code.MapAll -Trashed -AdditionalData -Users -AssignedPermissions private void Map(IUserGroup source, UserGroupDisplay target, MapperContext context) { @@ -318,7 +319,7 @@ public class UserMapDefinition : IMapDefinition target.UserCount = source.UserCount; target.IsSystemUserGroup = source.IsSystemUserGroup(); - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); + MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); // Important! Currently we are never mapping to multiple UserGroupDisplay objects but if we start doing that // this will cause an N+1 and we'll need to change how this works. @@ -453,19 +454,19 @@ public class UserMapDefinition : IMapDefinition // helpers private void MapUserGroupBasic(UserGroupBasic target, IEnumerable sourceAllowedLanguages, IEnumerable sourceAllowedSections, int? sourceStartContentId, int? sourceStartMediaId, MapperContext context) { - var allLanguages = _localizationService.GetAllLanguages(); - var applicableLanguages = Enumerable.Empty(); + var allLanguages = _localizationService.GetAllLanguages(); + var applicableLanguages = Enumerable.Empty(); - if (sourceAllowedLanguages.Any()) - { - applicableLanguages = allLanguages.Where(x => sourceAllowedLanguages.Contains(x.Id)); - } + if (sourceAllowedLanguages.Any()) + { + applicableLanguages = allLanguages.Where(x => sourceAllowedLanguages.Contains(x.Id)); + } - target.Languages = context.MapEnumerable(applicableLanguages).WhereNotNull(); + target.Languages = context.MapEnumerable(applicableLanguages).WhereNotNull(); - var allSections = _sectionService.GetSections(); - target.Sections = context.MapEnumerable(allSections.Where(x => sourceAllowedSections.Contains(x.Alias))).WhereNotNull(); + var allSections = _sectionService.GetSections(); + target.Sections = context.MapEnumerable(allSections.Where(x => sourceAllowedSections.Contains(x.Alias))).WhereNotNull(); if (sourceStartMediaId > 0) { diff --git a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs index 08e3cccbfb..97e43c7d7a 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs @@ -14,7 +14,7 @@ public static class UserGroupExtensions } // otherwise create one - return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon, group.StartContentId, group.StartMediaId, group.Alias, group.AllowedLanguages, group.AllowedSections, group.Permissions); + return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon, group.StartContentId, group.StartMediaId, group.Alias, group.AllowedLanguages, group.AllowedSections, group.Permissions); } public static bool IsSystemUserGroup(this IUserGroup group) => diff --git a/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs b/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs index f5a0427320..420f36c759 100644 --- a/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs +++ b/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs @@ -56,7 +56,7 @@ public static partial class Constants public const string UserGroup2Node = TableNamePrefix + "UserGroup2Node"; public const string UserGroup2NodePermission = TableNamePrefix + "UserGroup2NodePermission"; public const string UserGroup2Language = TableNamePrefix + "UserGroup2Language"; - public const string ExternalLogin = TableNamePrefix + "ExternalLogin"; + public const string ExternalLogin = TableNamePrefix + "ExternalLogin"; public const string TwoFactorLogin = TableNamePrefix + "TwoFactorLogin"; public const string ExternalLoginToken = TableNamePrefix + "ExternalLoginToken"; diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index ce742c6ec7..5e3d84a384 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -31,24 +31,24 @@ public class ContentService : RepositoryService, IContentService private readonly ILogger _logger; private readonly Lazy _propertyValidationService; private readonly IShortStringHelper _shortStringHelper; - private readonly ICultureImpactService _cultureImpactService; + private readonly ICultureImpactService _cultureImpactService; private IQuery? _queryNotTrashed; #region Constructors public ContentService( - ICoreScopeProvider provider, - ILoggerFactory loggerFactory, + ICoreScopeProvider provider, + ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, - IDocumentRepository documentRepository, - IEntityRepository entityRepository, + IDocumentRepository documentRepository, + IEntityRepository entityRepository, IAuditRepository auditRepository, - IContentTypeRepository contentTypeRepository, - IDocumentBlueprintRepository documentBlueprintRepository, + IContentTypeRepository contentTypeRepository, + IDocumentBlueprintRepository documentBlueprintRepository, ILanguageRepository languageRepository, - Lazy propertyValidationService, - IShortStringHelper shortStringHelper, - ICultureImpactService cultureImpactService) + Lazy propertyValidationService, + IShortStringHelper shortStringHelper, + ICultureImpactService cultureImpactService) : base(provider, loggerFactory, eventMessagesFactory) { _documentRepository = documentRepository; @@ -63,34 +63,34 @@ public class ContentService : RepositoryService, IContentService _logger = loggerFactory.CreateLogger(); } - [Obsolete("Use constructor that takes ICultureImpactService as a parameter, scheduled for removal in V12")] - public ContentService( - ICoreScopeProvider provider, - ILoggerFactory loggerFactory, - IEventMessagesFactory eventMessagesFactory, - IDocumentRepository documentRepository, - IEntityRepository entityRepository, - IAuditRepository auditRepository, - IContentTypeRepository contentTypeRepository, - IDocumentBlueprintRepository documentBlueprintRepository, - ILanguageRepository languageRepository, - Lazy propertyValidationService, - IShortStringHelper shortStringHelper) - : this( - provider, - loggerFactory, - eventMessagesFactory, - documentRepository, - entityRepository, - auditRepository, - contentTypeRepository, - documentBlueprintRepository, - languageRepository, - propertyValidationService, - shortStringHelper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } + [Obsolete("Use constructor that takes ICultureImpactService as a parameter, scheduled for removal in V12")] + public ContentService( + ICoreScopeProvider provider, + ILoggerFactory loggerFactory, + IEventMessagesFactory eventMessagesFactory, + IDocumentRepository documentRepository, + IEntityRepository entityRepository, + IAuditRepository auditRepository, + IContentTypeRepository contentTypeRepository, + IDocumentBlueprintRepository documentBlueprintRepository, + ILanguageRepository languageRepository, + Lazy propertyValidationService, + IShortStringHelper shortStringHelper) + : this( + provider, + loggerFactory, + eventMessagesFactory, + documentRepository, + entityRepository, + auditRepository, + contentTypeRepository, + documentBlueprintRepository, + languageRepository, + propertyValidationService, + shortStringHelper, + StaticServiceProvider.Instance.GetRequiredService()) + { + } #endregion diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index 52dca5680f..6fafa80319 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -289,7 +289,7 @@ public class UmbracoPlan : MigrationPlan // TO 10.0.0 To("{B7E0D53C-2B0E-418B-AB07-2DDE486E225F}"); - // TO 10.1.0 - To("{D0B3D29D-F4D5-43E3-BA67-9D49256F3266}"); + // TO 10.1.0 + To("{D0B3D29D-F4D5-43E3-BA67-9D49256F3266}"); } } diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/UserGroupFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/UserGroupFactory.cs index 587a8cb832..5edc443476 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/UserGroupFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/UserGroupFactory.cs @@ -10,14 +10,12 @@ internal static class UserGroupFactory { public static IUserGroup BuildEntity(IShortStringHelper shortStringHelper, UserGroupDto dto) { - var userGroup = new UserGroup( - shortStringHelper, - dto.UserCount, - dto.Alias, - dto.Name, - dto.DefaultPermissions.IsNullOrWhiteSpace() - ? Enumerable.Empty() - : dto.DefaultPermissions!.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList(), + var userGroup = new UserGroup( + shortStringHelper, + dto.UserCount, + dto.Alias, + dto.Name, + dto.DefaultPermissions.IsNullOrWhiteSpace() ? Enumerable.Empty() : dto.DefaultPermissions!.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList(), dto.Icon); try @@ -36,10 +34,10 @@ internal static class UserGroupFactory } } - foreach (UserGroup2LanguageDto language in dto.UserGroup2LanguageDtos) - { - userGroup.AddAllowedLanguage(language.LanguageId); - } + foreach (UserGroup2LanguageDto language in dto.UserGroup2LanguageDtos) + { + userGroup.AddAllowedLanguage(language.LanguageId); + } userGroup.ResetDirtyProperties(false); return userGroup; diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 3c23cc607f..c5d233ae0a 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -66,7 +66,7 @@ public class ContentController : ContentControllerBase private readonly IUmbracoMapper _umbracoMapper; private readonly IUserService _userService; - [ActivatorUtilitiesConstructor] + [ActivatorUtilitiesConstructor] public ContentController( ICultureDictionary cultureDictionary, ILoggerFactory loggerFactory, @@ -90,8 +90,8 @@ public class ContentController : ContentControllerBase IJsonSerializer serializer, ICoreScopeProvider scopeProvider, IAuthorizationService authorizationService, - IContentVersionService contentVersionService, - ICultureImpactService cultureImpactService) + IContentVersionService contentVersionService, + ICultureImpactService cultureImpactService) : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer) { _propertyEditors = propertyEditors; @@ -111,68 +111,68 @@ public class ContentController : ContentControllerBase _sqlContext = sqlContext; _authorizationService = authorizationService; _contentVersionService = contentVersionService; - _cultureImpactService = cultureImpactService; + _cultureImpactService = cultureImpactService; _logger = loggerFactory.CreateLogger(); _scopeProvider = scopeProvider; _allLangs = new Lazy>(() => - _localizationService.GetAllLanguages() - .ToDictionary(x => x.IsoCode, x => x, StringComparer.InvariantCultureIgnoreCase)); + _localizationService.GetAllLanguages().ToDictionary(x => x.IsoCode, x => x, StringComparer.InvariantCultureIgnoreCase)); } + [Obsolete("Use constructor that accepts ICultureImpactService as a parameter, scheduled for removal in V12")] + public ContentController( + ICultureDictionary cultureDictionary, + ILoggerFactory loggerFactory, + IShortStringHelper shortStringHelper, + IEventMessagesFactory eventMessages, + ILocalizedTextService localizedTextService, + PropertyEditorCollection propertyEditors, + IContentService contentService, + IUserService userService, + IBackOfficeSecurityAccessor backofficeSecurityAccessor, + IContentTypeService contentTypeService, + IUmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IDomainService domainService, + IDataTypeService dataTypeService, + ILocalizationService localizationService, + IFileService fileService, + INotificationService notificationService, + ActionCollection actionCollection, + ISqlContext sqlContext, + IJsonSerializer serializer, + ICoreScopeProvider scopeProvider, + IAuthorizationService authorizationService, + IContentVersionService contentVersionService) + : this( + cultureDictionary, + loggerFactory, + shortStringHelper, + eventMessages, + localizedTextService, + propertyEditors, + contentService, + userService, + backofficeSecurityAccessor, + contentTypeService, + umbracoMapper, + publishedUrlProvider, + domainService, + dataTypeService, + localizationService, + fileService, + notificationService, + actionCollection, + sqlContext, + serializer, + scopeProvider, + authorizationService, + contentVersionService, + StaticServiceProvider.Instance.GetRequiredService()) + { + } + public object? Domains { get; private set; } - [Obsolete("Use constructor that accepts ICultureImpactService as a parameter, scheduled for removal in V12")] - public ContentController( - ICultureDictionary cultureDictionary, - ILoggerFactory loggerFactory, - IShortStringHelper shortStringHelper, - IEventMessagesFactory eventMessages, - ILocalizedTextService localizedTextService, - PropertyEditorCollection propertyEditors, - IContentService contentService, - IUserService userService, - IBackOfficeSecurityAccessor backofficeSecurityAccessor, - IContentTypeService contentTypeService, - IUmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider, - IDomainService domainService, - IDataTypeService dataTypeService, - ILocalizationService localizationService, - IFileService fileService, - INotificationService notificationService, - ActionCollection actionCollection, - ISqlContext sqlContext, - IJsonSerializer serializer, - ICoreScopeProvider scopeProvider, - IAuthorizationService authorizationService, - IContentVersionService contentVersionService) - : this( - cultureDictionary, - loggerFactory, - shortStringHelper, - eventMessages, - localizedTextService, - propertyEditors, - contentService, - userService, - backofficeSecurityAccessor, - contentTypeService, - umbracoMapper, - publishedUrlProvider, - domainService, - dataTypeService, - localizationService, - fileService, - notificationService, - actionCollection, - sqlContext, - serializer, - scopeProvider, - authorizationService, - contentVersionService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } /// /// Return content for the specified ids @@ -898,12 +898,12 @@ public class ContentController : ContentControllerBase // we will continue to save if model state is invalid, however we cannot save if critical data is missing. if (!ModelState.IsValid) { - // Don't try and save if we do not have access - if (ModelState.Keys.Contains(Constants.ModelStateErrorKeys.PermissionError)) - { - var forDisplay = mapToDisplay(contentItem.PersistedContent); - return ValidationProblem(forDisplay, ModelState); - } + // Don't try and save if we do not have access + if (ModelState.Keys.Contains(Constants.ModelStateErrorKeys.PermissionError)) + { + var forDisplay = mapToDisplay(contentItem.PersistedContent); + return ValidationProblem(forDisplay, ModelState); + } // check for critical data validation issues, we can't continue saving if this data is invalid if (!passesCriticalValidationRules) @@ -950,10 +950,10 @@ public class ContentController : ContentControllerBase //The default validation language will be either: The default languauge, else if the content is brand new and the default culture is // not marked to be saved, it will be the first culture in the list marked for saving. var defaultCulture = _allLangs.Value.Values.FirstOrDefault(x => x.IsDefault)?.IsoCode; - var cultureForInvariantErrors = _cultureImpactService.GetCultureForInvariantErrors( - contentItem.PersistedContent, - contentItem.Variants.Where(x => x.Save).Select(x => x.Culture).ToArray(), - defaultCulture); + var cultureForInvariantErrors = _cultureImpactService.GetCultureForInvariantErrors( + contentItem.PersistedContent, + contentItem.Variants.Where(x => x.Save).Select(x => x.Culture).ToArray(), + defaultCulture); //get the updated model var isBlueprint = contentItem.PersistedContent?.Blueprint ?? false; @@ -1847,7 +1847,7 @@ public class ContentController : ContentControllerBase foreach (ContentVariantSave variant in cultureVariants.Where(x => x.Publish)) { // publishing any culture, implies the invariant culture - var valid = persistentContent.PublishCulture(_cultureImpactService.ImpactExplicit(variant.Culture, defaultCulture.InvariantEquals(variant.Culture))); + var valid = persistentContent.PublishCulture(_cultureImpactService.ImpactExplicit(variant.Culture, defaultCulture.InvariantEquals(variant.Culture))); if (!valid) { AddVariantValidationError(variant.Culture, variant.Segment, "speechBubbles", "contentCultureValidationError"); diff --git a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs index 77a5ce0bd8..fb8629c461 100644 --- a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; @@ -38,17 +38,17 @@ internal sealed class ContentSaveValidationAttribute : TypeFilterAttribute ILoggerFactory loggerFactory, IContentService contentService, IPropertyValidationService propertyValidationService, - IAuthorizationService authorizationService, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - ILocalizationService localizationService) + IAuthorizationService authorizationService, + IBackOfficeSecurityAccessor backOfficeSecurityAccessor, + ILocalizationService localizationService) { _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService)); _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService)); _authorizationService = authorizationService; - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - _localizationService = localizationService; + _backOfficeSecurityAccessor = backOfficeSecurityAccessor; + _localizationService = localizationService; } public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) @@ -144,29 +144,29 @@ internal sealed class ContentSaveValidationAttribute : TypeFilterAttribute IContent? contentToCheck = null; int contentIdToCheck; - // First check if user has Access to that language - IUser? currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser; - bool hasAccess = false; - if (currentUser is null) - { - return false; - } + // First check if user has Access to that language + IUser? currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser; + bool hasAccess = false; + if (currentUser is null) + { + return false; + } - foreach (IReadOnlyUserGroup group in currentUser.Groups) + foreach (IReadOnlyUserGroup group in currentUser.Groups) + { + IEnumerable languages = _localizationService.GetAllLanguages().Where(x => group.AllowedLanguages.Contains(x.Id)); + if (group.AllowedLanguages.Count() is 0 || + languages.Select(x => x.IsoCode).Intersect(contentItem?.Variants.Where(x => x.Save || x.Publish).Select(x => x.Culture) ?? Enumerable.Empty()).Count() is not 0) { - IEnumerable languages = _localizationService.GetAllLanguages().Where(x => group.AllowedLanguages.Contains(x.Id)); - if (group.AllowedLanguages.Count() is 0 || - languages.Select(x => x.IsoCode).Intersect(contentItem?.Variants.Where(x => x.Save || x.Publish).Select(x => x.Culture) ?? Enumerable.Empty()).Count() is not 0) - { - hasAccess = true; - } + hasAccess = true; } + } - if (!hasAccess && contentItem?.Variants.First().Culture is not null) - { - actionContext.ModelState.AddModelError(Constants.ModelStateErrorKeys.PermissionError, "User does not have access to save language"); - return false; - } + if (!hasAccess && contentItem?.Variants.First().Culture is not null) + { + actionContext.ModelState.AddModelError(Constants.ModelStateErrorKeys.PermissionError, "User does not have access to save language"); + return false; + } switch (contentItem?.Action) { diff --git a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs index 7cb9fb4611..4336609809 100644 --- a/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs +++ b/src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs @@ -299,7 +299,7 @@ internal class ContentMapDefinition : IMapDefinition target.State = _stateMapper.Map(source, context); target.Tabs = _tabsAndPropertiesMapper.Map(source, context); target.UpdateDate = source.UpdateDate; - target.AllowedActions = new[] { ActionBrowse.ActionLetter.ToString() }; + target.AllowedActions = new[] { ActionBrowse.ActionLetter.ToString() }; } private void Map(IContent source, ContentVariantScheduleDisplay target, MapperContext context)