diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts index f056886..de94dc2 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/models/user-management.api.models.ts @@ -60,15 +60,15 @@ export interface GroupOfUser { export interface UserRep { id?: number, + repUserId?: number, userId: number, repGroupId?: number, groupId?: number, addedWho: string, - repUserId?: number, + repUser?: User user?: User, repGroup?: Group, - group?: Group, - repUser?: User + group?: Group, } export interface DirGroup { diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.prod.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.prod.ts index 68c3399..0f8d432 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.prod.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/environments/environment.prod.ts @@ -214,6 +214,10 @@ export const env = { value: "yyyy-MM-dd", name: "yyyy-MM-dd", } + ], + languages: [ + { value: "de-DE", name: "de-DE" }, + { value: "en-US", name: "en-US" } ] } }; diff --git a/DigitalData.UserManager.API/Controllers/AuthController.cs b/DigitalData.UserManager.API/Controllers/AuthController.cs index 617b681..cfd43e6 100644 --- a/DigitalData.UserManager.API/Controllers/AuthController.cs +++ b/DigitalData.UserManager.API/Controllers/AuthController.cs @@ -21,15 +21,16 @@ namespace DigitalData.UserManager.API.Controllers private readonly IDirectorySearchService _dirSearchService; private readonly IStringLocalizer _localizer; private readonly ILogger _logger; - - public AuthController(IUserService userService, IGroupOfUserService gouService, IDirectorySearchService directorySearchService, IStringLocalizer localizer, ILogger logger) + private readonly IConfiguration _config; + public AuthController(IUserService userService, IGroupOfUserService gouService, IDirectorySearchService directorySearchService, IStringLocalizer localizer, ILogger logger, IConfiguration configuration) { _userService = userService; _gouService = gouService; _dirSearchService = directorySearchService; _localizer = localizer; _logger = logger; - } + _config = configuration; + } [AllowAnonymous] [HttpGet("check")] @@ -57,10 +58,13 @@ namespace DigitalData.UserManager.API.Controllers if (!isValid) return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFound])); - var gouMsg = await _gouService.HasGroup(login.Username, "PM_USER", caseSensitive: false); + var allowedGroupName = _config.GetSection("AllowedGroupName").Get() + ?? throw new InvalidOperationException("Allowed group names configuration is missing."); + + var gouMsg = await _gouService.HasGroup(login.Username, allowedGroupName, caseSensitive: false); if (!gouMsg.IsSuccess) return Unauthorized(Result.Fail().Message(_localizer[Key.UnauthorizedUser])); - + //find the user var uRes = await _userService.ReadByUsernameAsync(login.Username); if (!uRes.IsSuccess || uRes.Data is null) diff --git a/DigitalData.UserManager.API/Controllers/ConstantsController.cs b/DigitalData.UserManager.API/Controllers/ConstantsController.cs deleted file mode 100644 index 645a595..0000000 --- a/DigitalData.UserManager.API/Controllers/ConstantsController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using DigitalData.UserManager.API.Models; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; - -namespace DigitalData.UserManager.API.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class ConstantsController : ControllerBase - { - private readonly Constants _constants; - public ConstantsController(IOptions constantsOptions) - { - _constants = constantsOptions.Value; - } - - [HttpGet] - public IActionResult GetConstant(string? name = null) - { - if(name is null) - return Ok(_constants); - - - return Ok(_constants[name]); - } - } -} \ No newline at end of file diff --git a/DigitalData.UserManager.API/DigitalData.UserManager.API.csproj b/DigitalData.UserManager.API/DigitalData.UserManager.API.csproj index 79a0e4c..4920854 100644 --- a/DigitalData.UserManager.API/DigitalData.UserManager.API.csproj +++ b/DigitalData.UserManager.API/DigitalData.UserManager.API.csproj @@ -61,6 +61,7 @@ + diff --git a/DigitalData.UserManager.API/Models/Constants.cs b/DigitalData.UserManager.API/Models/Constants.cs deleted file mode 100644 index 66656db..0000000 --- a/DigitalData.UserManager.API/Models/Constants.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Reflection; - -namespace DigitalData.UserManager.API.Models -{ - public class Constants - { - public IEnumerable UserLanguages { get; init; } = Array.Empty(); - - public object? this[string propertyName] => GetType() - .GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)? - .GetValue(this, null); - } -} \ No newline at end of file diff --git a/DigitalData.UserManager.API/Program.cs b/DigitalData.UserManager.API/Program.cs index 8b6a88e..61ead86 100644 --- a/DigitalData.UserManager.API/Program.cs +++ b/DigitalData.UserManager.API/Program.cs @@ -9,8 +9,6 @@ using DigitalData.Core.API; using DigitalData.UserManager.API.Controllers; using DigitalData.UserManager.Application.Services; using Microsoft.Data.SqlClient; -using System.Reflection.Metadata; -using DigitalData.UserManager.API.Models; var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger(); logger.Debug("init main"); @@ -80,8 +78,6 @@ try { builder.Services.AddCookieBasedLocalizer(); - builder.ConfigureBySection(); - var app = builder.Build(); cnn_str = new(() => diff --git a/DigitalData.UserManager.API/appsettings.json b/DigitalData.UserManager.API/appsettings.json index 4c1f4c9..8820afc 100644 --- a/DigitalData.UserManager.API/appsettings.json +++ b/DigitalData.UserManager.API/appsettings.json @@ -71,13 +71,8 @@ "Key": "JGPwHVD0BQmC7upi5OV11PzzIk47ugTJoqBV/et5w40=", "IV": "gMuetIjlPvJnSzu+i7I3xg==" }, + "AllowedGroupName": "UM_ADMINS", // Delete below in production "UseEncryptor": true, - "UseSwagger": true, - "Constants": { - "UserLanguages": [ - "de-DE", - "en-US" - ] - } + "UseSwagger": true } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/DTOs/Base/BaseReadDto.cs b/DigitalData.UserManager.Application/DTOs/Base/BaseReadDto.cs index 1a37358..3265439 100644 --- a/DigitalData.UserManager.Application/DTOs/Base/BaseReadDto.cs +++ b/DigitalData.UserManager.Application/DTOs/Base/BaseReadDto.cs @@ -2,5 +2,6 @@ namespace DigitalData.UserManager.Application.DTOs.Base { + // TODO: use getter - setter methods for a simple inheritance. public record BaseReadDto(int Id, string? AddedWho, DateTime? AddedWhen, string? ChangedWho, DateTime? ChangedWhen) : BaseDTO(Id); } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/DTOs/User/UserReadDto.cs b/DigitalData.UserManager.Application/DTOs/User/UserReadDto.cs index fbfef1b..eac5982 100644 --- a/DigitalData.UserManager.Application/DTOs/User/UserReadDto.cs +++ b/DigitalData.UserManager.Application/DTOs/User/UserReadDto.cs @@ -4,6 +4,7 @@ using DigitalData.EmailProfilerDispatcher.Abstraction.Attributes; namespace DigitalData.UserManager.Application.DTOs.User { + //TODO: inherit from base read dto public record UserReadDto() { public int Id { get; set; }