From 1fb6afbc0399cba02989c9ae180e33262e887dbc Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 13 Mar 2023 14:04:16 +0100 Subject: [PATCH] Add setting to disable domain warnings (#13954) * Add appsetting and return if domain warning are disabled * Fix unit tests * Add default value --------- Co-authored-by: Zeegaan --- .../Configuration/Models/ContentSettings.cs | 7 ++ .../Controllers/ContentController.cs | 69 ++++++++++++++++++- .../Controllers/ContentControllerTests.cs | 5 +- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 7e82fe2e95..290836d31e 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -158,6 +158,7 @@ public class ContentSettings internal const bool StaticDisableDeleteWhenReferenced = false; internal const bool StaticDisableUnpublishWhenReferenced = false; internal const bool StaticAllowEditInvariantFromNonDefault = false; + internal const bool StaticShowDomainWarnings = true; /// /// Gets or sets a value for the content notification settings. @@ -267,4 +268,10 @@ public class ContentSettings /// Gets or sets the allowed external host for media. If empty only relative paths are allowed. /// public string[] AllowedMediaHosts { get; set; } = Array.Empty(); + + /// + /// Gets or sets a value indicating whether to show domain warnings. + /// + [DefaultValue(StaticShowDomainWarnings)] + public bool ShowDomainWarnings { get; set; } = StaticShowDomainWarnings; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 642db289a0..0b1dfa38d3 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -5,8 +5,10 @@ using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Actions; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.ContentApps; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Dictionary; @@ -65,6 +67,7 @@ public class ContentController : ContentControllerBase private readonly ISqlContext _sqlContext; private readonly IUmbracoMapper _umbracoMapper; private readonly IUserService _userService; + private readonly ContentSettings _contentSettings; [ActivatorUtilitiesConstructor] public ContentController( @@ -91,7 +94,8 @@ public class ContentController : ContentControllerBase ICoreScopeProvider scopeProvider, IAuthorizationService authorizationService, IContentVersionService contentVersionService, - ICultureImpactFactory cultureImpactFactory) + ICultureImpactFactory cultureImpactFactory, + IOptions contentSettings) : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer) { _propertyEditors = propertyEditors; @@ -115,7 +119,63 @@ public class ContentController : ContentControllerBase _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)); + _contentSettings = contentSettings.Value; + } + + [Obsolete("Use constructor that accepts ContentSettings as a parameter, scheduled for removal in V13")] + 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, + ICultureImpactFactory cultureImpactFactory) + : this( + cultureDictionary, + loggerFactory, + shortStringHelper, + eventMessages, + localizedTextService, + propertyEditors, + contentService, + userService, + backofficeSecurityAccessor, + contentTypeService, + umbracoMapper, + publishedUrlProvider, + domainService, + dataTypeService, + localizationService, + fileService, + notificationService, + actionCollection, + sqlContext, + serializer, + scopeProvider, + authorizationService, + contentVersionService, + cultureImpactFactory, + StaticServiceProvider.Instance.GetRequiredService>()) + { } [Obsolete("Use constructor that accepts ICultureImpactService as a parameter, scheduled for removal in V12")] @@ -1710,6 +1770,11 @@ public class ContentController : ContentControllerBase /// internal void AddDomainWarnings(IContent? persistedContent, string[]? culturesPublished, SimpleNotificationModel globalNotifications) { + if (_contentSettings.ShowDomainWarnings is false) + { + return; + } + // Don't try to verify if no cultures were published if (culturesPublished is null) { diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs index 7046972d83..0a1b2f3240 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -4,9 +4,11 @@ using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Actions; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Dictionary; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Mapping; @@ -266,7 +268,8 @@ public class ContentControllerTests Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of()); + Mock.Of(), + new OptionsWrapper(new ContentSettings())); return controller; }