Merge branch 'v11/dev' into contrib

This commit is contained in:
Sebastiaan Janssen
2023-05-03 09:56:43 +02:00
22 changed files with 231 additions and 168 deletions

View File

@@ -7,26 +7,56 @@ using System.Security.Principal;
namespace Umbraco.Extensions;
/// <summary>
/// Extension methods for <see cref="IIdentity" />.
/// </summary>
public static class AuthenticationExtensions
{
/// <summary>
/// Ensures that the thread culture is set based on the back office user's culture
/// Ensures that the thread culture is set based on the back office user's culture.
/// </summary>
/// <param name="identity">The identity.</param>
public static void EnsureCulture(this IIdentity identity)
{
CultureInfo? culture = GetCulture(identity);
if (!(culture is null))
if (culture is not null)
{
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture;
}
}
/// <summary>
/// Gets the culture string from the back office user.
/// </summary>
/// <param name="identity">The identity.</param>
/// <returns>
/// The culture string.
/// </returns>
public static string? GetCultureString(this IIdentity identity)
{
if (identity is ClaimsIdentity umbIdentity &&
umbIdentity.VerifyBackOfficeIdentity(out _) &&
umbIdentity.IsAuthenticated)
{
return umbIdentity.GetCultureString();
}
return null;
}
/// <summary>
/// Gets the culture from the back office user.
/// </summary>
/// <param name="identity">The identity.</param>
/// <returns>
/// The culture.
/// </returns>
public static CultureInfo? GetCulture(this IIdentity identity)
{
if (identity is ClaimsIdentity umbIdentity && umbIdentity.VerifyBackOfficeIdentity(out _) &&
umbIdentity.IsAuthenticated && umbIdentity.GetCultureString() is not null)
string? culture = identity.GetCultureString();
if (!string.IsNullOrEmpty(culture))
{
return CultureInfo.GetCultureInfo(umbIdentity.GetCultureString()!);
return CultureInfo.GetCultureInfo(culture);
}
return null;

View File

@@ -1146,6 +1146,8 @@ public class ContentService : RepositoryService, IContentService
var allLangs = _languageRepository.GetMany().ToList();
// Change state to publishing
content.PublishedState = PublishedState.Publishing;
var savingNotification = new ContentSavingNotification(content, evtMsgs);
if (scope.Notifications.PublishCancelable(savingNotification))
{