Added allowedLanguagesIds to UserDetail

This commit is contained in:
Bjarke Berg
2022-08-01 14:57:25 +02:00
parent 38c42c2479
commit c73cb30c58
3 changed files with 16 additions and 0 deletions

View File

@@ -59,4 +59,10 @@ public class UserDetail : UserProfile
/// </summary>
[DataMember(Name = "allowedSections")]
public IEnumerable<string>? AllowedSections { get; set; }
/// <summary>
/// A list of language culcure codes the user is allowed to view.
/// </summary>
[DataMember(Name = "allowedLanguageIds")]
public IEnumerable<int>? AllowedLanguageIds { get; set; }
}

View File

@@ -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;

View File

@@ -188,6 +188,15 @@ public static class UserExtensions
/// <summary>
/// Calculate start nodes, combining groups' and user's, and excluding what's in the bin
/// </summary>
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;