diff --git a/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs b/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs index 88b31ee4a2..38ec7281a4 100644 --- a/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs +++ b/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs @@ -59,4 +59,10 @@ public class UserDetail : UserProfile /// [DataMember(Name = "allowedSections")] public IEnumerable? AllowedSections { get; set; } + + /// + /// A list of language culcure codes the user is allowed to view. + /// + [DataMember(Name = "allowedLanguageIds")] + public IEnumerable? AllowedLanguageIds { get; set; } } diff --git a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs index 3a04f118be..9174ee7004 100644 --- a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs @@ -440,6 +440,7 @@ public class UserMapDefinition : IMapDefinition private void Map(IUser source, UserDetail target, MapperContext context) { target.AllowedSections = source.AllowedSections; + target.AllowedLanguageIds = source.CalculateAllowedLanguageIds(_localizationService); target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileManager, _imageUrlGenerator); target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString(); target.Email = source.Email; diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 87f91978e0..f17f6e4de0 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -188,6 +188,15 @@ public static class UserExtensions /// /// Calculate start nodes, combining groups' and user's, and excluding what's in the bin /// + public static int[]? CalculateAllowedLanguageIds(this IUser user, ILocalizationService localizationService) + { + var hasAccessToAllLanguages = user.Groups.Any(x => x.HasAccessToAllLanguages); + + return hasAccessToAllLanguages + ? localizationService.GetAllLanguages().Select(x => x.Id).ToArray() + : user.Groups.SelectMany(x => x.AllowedLanguages).Distinct().ToArray(); + } + public static int[]? CalculateContentStartNodeIds(this IUser user, IEntityService entityService, AppCaches appCaches) { var cacheKey = CacheKeys.UserAllContentStartNodesPrefix + user.Id;