Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeegaan committed Oct 14, 2021
1 parent 4c616dc commit 7379387
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ public async Task PostSave_Validate_Variants_Empty_Name()
[Test]
public async Task PostSave_Validates_Domains_Exist()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
localizationService.Save(new LanguageBuilder()
.WithCultureInfo("da-DK")
Expand Down Expand Up @@ -445,17 +444,21 @@ public async Task PostSave_Validates_Domains_Exist()
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
ContentItemDisplay display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
ILocalizedTextService localizedTextService = GetRequiredService<ILocalizedTextService>();
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";

Expand Down Expand Up @@ -504,11 +507,14 @@ public async Task PostSave_Validates_All_Cultures_Has_Domains()
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
ContentItemDisplay display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);

ILocalizedTextService localizedTextService = GetRequiredService<ILocalizedTextService>();
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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ private ContentController CreateContentController(IDomainService domainService)
Mock.Of<ISqlContext>(),
Mock.Of<IJsonSerializer>(),
Mock.Of<IScopeProvider>(),
Mock.Of<IAuthorizationService>()
Mock.Of<IAuthorizationService>(),
Mock.Of<IUserDataService>()
);

return controller;
Expand Down
12 changes: 9 additions & 3 deletions src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class ContentController : ContentControllerBase
private readonly Lazy<IDictionary<string, ILanguage>> _allLangs;
private readonly ILogger<ContentController> _logger;
private readonly IScopeProvider _scopeProvider;
private readonly IUserDataService _userDataService;

public object Domains { get; private set; }

Expand All @@ -90,7 +91,8 @@ public ContentController(
ISqlContext sqlContext,
IJsonSerializer serializer,
IScopeProvider scopeProvider,
IAuthorizationService authorizationService)
IAuthorizationService authorizationService,
IUserDataService userDataService)
: base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer)
{
_propertyEditors = propertyEditors;
Expand All @@ -112,6 +114,7 @@ public ContentController(
_logger = loggerFactory.CreateLogger<ContentController>();
_scopeProvider = scopeProvider;
_allLangs = new Lazy<IDictionary<string, ILanguage>>(() => _localizationService.GetAllLanguages().ToDictionary(x => x.IsoCode, x => x, StringComparer.InvariantCultureIgnoreCase));
_userDataService = userDataService;
}

/// <summary>
Expand Down Expand Up @@ -1470,14 +1473,17 @@ internal void AddDomainWarnings(IContent persistedContent, string[] culturesPubl
{
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;
Expand Down

0 comments on commit 7379387

Please sign in to comment.