From 7379387b2eb2b795f70ba360caf8a063aeb442fe Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Thu, 14 Oct 2021 13:30:22 +0200 Subject: [PATCH] Added logging --- .../Controllers/ContentControllerTests.cs | 10 ++++++++-- .../Controllers/ContentControllerTests.cs | 3 ++- .../Controllers/ContentController.cs | 12 +++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs index 31761923d0..d913d62372 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -412,7 +412,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers [Test] public async Task PostSave_Validates_Domains_Exist() { - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); ILocalizationService localizationService = GetRequiredService(); localizationService.Save(new LanguageBuilder() .WithCultureInfo("da-DK") @@ -445,17 +444,21 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); ContentItemDisplay display = JsonConvert.DeserializeObject(body); + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + ILocalizedTextService localizedTextService = GetRequiredService(); + var expectedMessage = localizedTextService.Localize("speechBubbles", "publishWithNoDomains", new []{"en-US"}); + Assert.Multiple(() => { Assert.IsNotNull(display); Assert.AreEqual(1, display.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); + Assert.AreEqual(expectedMessage, display.Notifications.FirstOrDefault(x => x.NotificationType == NotificationStyle.Warning)?.Message); }); } [Test] public async Task PostSave_Validates_All_Cultures_Has_Domains() { - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); var enString = "en-US"; var dkString = "da-DK"; @@ -504,11 +507,14 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); ContentItemDisplay display = JsonConvert.DeserializeObject(body); + ILocalizedTextService localizedTextService = GetRequiredService(); + var expectedMessage = localizedTextService.Localize("speechBubbles", "publishWithMissingDomain", new []{"en-US"}); Assert.Multiple(() => { Assert.NotNull(display); Assert.AreEqual(1, display.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); + Assert.AreEqual(expectedMessage, display.Notifications.FirstOrDefault(x => x.NotificationType == NotificationStyle.Warning)?.Message); }); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs index 42b9eb2ddc..24a943265e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -261,7 +261,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of() + Mock.Of(), + Mock.Of() ); return controller; diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 3f051d0a35..a05aa25238 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -65,6 +65,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers private readonly Lazy> _allLangs; private readonly ILogger _logger; private readonly IScopeProvider _scopeProvider; + private readonly IUserDataService _userDataService; public object Domains { get; private set; } @@ -90,7 +91,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers ISqlContext sqlContext, IJsonSerializer serializer, IScopeProvider scopeProvider, - IAuthorizationService authorizationService) + IAuthorizationService authorizationService, + IUserDataService userDataService) : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer) { _propertyEditors = propertyEditors; @@ -112,6 +114,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers _logger = loggerFactory.CreateLogger(); _scopeProvider = scopeProvider; _allLangs = new Lazy>(() => _localizationService.GetAllLanguages().ToDictionary(x => x.IsoCode, x => x, StringComparer.InvariantCultureIgnoreCase)); + _userDataService = userDataService; } /// @@ -1470,14 +1473,17 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { assignedDomains.UnionWith(_domainService.GetAssignedDomains(ancestorID, true)); } - + foreach (var data in _userDataService.GetUserData()) + { + _logger.LogWarning($"{data.Name} : {data.Data}"); + } // No domains at all, add a warning, to add domains. if (assignedDomains.Count == 0) { globalNotifications.AddWarningNotification( _localizedTextService.Localize("auditTrails", "publish"), _localizedTextService.Localize("speechBubbles", "publishWithNoDomains")); - + _logger.LogWarning("NOT REGISTRED DOMAIN FOR: {Cultures}"); _logger.LogWarning("The root node {RootNodeName} was published with multiple cultures, but no domains are configured, this will cause routing and caching issues, please register domains for: {Cultures}", persistedContent.Name, string.Join(", ", publishedCultures)); return;