From d491aeeba628d2969aec631db86352b83e0b5656 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 1 Sep 2023 13:16:39 -0400 Subject: [PATCH] include User Settings when calling UserService --- Oqtane.Server/Controllers/UserController.cs | 16 +++++++++++++++- Oqtane.Shared/Models/User.cs | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index f26ece369..e57635cbe 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -26,16 +26,18 @@ public class UserController : Controller private readonly IUserManager _userManager; private readonly ISiteRepository _sites; private readonly IUserPermissions _userPermissions; + private readonly ISettingRepository _settings; private readonly IJwtManager _jwtManager; private readonly ILogManager _logger; - public UserController(IUserRepository users, ITenantManager tenantManager, IUserManager userManager, ISiteRepository sites, IUserPermissions userPermissions, IJwtManager jwtManager, ILogManager logger) + public UserController(IUserRepository users, ITenantManager tenantManager, IUserManager userManager, ISiteRepository sites, IUserPermissions userPermissions, ISettingRepository settings, IJwtManager jwtManager, ILogManager logger) { _users = users; _tenantManager = tenantManager; _userManager = userManager; _sites = sites; _userPermissions = userPermissions; + _settings = settings; _jwtManager = jwtManager; _logger = logger; } @@ -52,6 +54,12 @@ public User Get(int id, string siteid) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; } + else + { + List settings = _settings.GetSettings(EntityNames.User, user.UserId).ToList(); + user.Settings = settings.Where(item => !item.IsPrivate || _userPermissions.GetUser(User).UserId == user.UserId) + .ToDictionary(setting => setting.SettingName, setting => setting.SettingValue); + } return Filter(user); } else @@ -75,6 +83,12 @@ public User Get(string name, string email, string siteid) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; } + else + { + List settings = _settings.GetSettings(EntityNames.User, user.UserId).ToList(); + user.Settings = settings.Where(item => !item.IsPrivate || _userPermissions.GetUser(User).UserId == user.UserId) + .ToDictionary(setting => setting.SettingName, setting => setting.SettingValue); + } return Filter(user); } else diff --git a/Oqtane.Shared/Models/User.cs b/Oqtane.Shared/Models/User.cs index d7436b4c8..1b9a518d3 100644 --- a/Oqtane.Shared/Models/User.cs +++ b/Oqtane.Shared/Models/User.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; namespace Oqtane.Models @@ -105,5 +106,11 @@ public string FolderPath /// [NotMapped] public bool EmailConfirmed { get; set; } + + /// + /// Public User Settings + /// + [NotMapped] + public Dictionary Settings { get; set; } } }