feat: add user and role view sheets with detailed information display
- Created UserViewSheet component to display user details including username, full name, role, status, and timestamps. - Created RoleViewSheet component to display role details including name, level, status, creation date, and associated permissions. - Introduced permissions configuration in a new permissions.ts file, defining categories and permission codes for better management. - Implemented middleware for authentication, ensuring access control for protected routes.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Distribution.Features.User;
|
||||
|
||||
public record CreateUserRequest(
|
||||
string Username,
|
||||
[EmailAddress] string Username,
|
||||
string Password,
|
||||
string FullName,
|
||||
Guid RoleId,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using Distribution.Features.Auth;
|
||||
using Distribution.Infra.UoW;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Distribution.Features.User;
|
||||
|
||||
public class UserService(IUserRepository repo, IUnitOfWork uow)
|
||||
public class UserService(IUserRepository repo, IUnitOfWork uow, IAuthHexClient authHex)
|
||||
{
|
||||
private readonly PasswordHasher<Models.User> _hasher = new();
|
||||
|
||||
private static UserResponse ToResponse(Models.User u) =>
|
||||
new(u.Id, u.Username, u.FullName, u.FK_RoleId, u.Role?.Name ?? string.Empty,
|
||||
u.FK_ReportsToUserId, u.IsActive, u.CreatedAt, u.UpdatedAt);
|
||||
@@ -33,12 +31,30 @@ public class UserService(IUserRepository repo, IUnitOfWork uow)
|
||||
FK_RoleId = request.RoleId,
|
||||
FK_ReportsToUserId = request.ReportsToUserId
|
||||
};
|
||||
user.PasswordHash = _hasher.HashPassword(user, request.Password);
|
||||
|
||||
await uow.BeginAsync(ct);
|
||||
try
|
||||
{
|
||||
await repo.AddAsync(user);
|
||||
|
||||
var authResult = await authHex.CallAsync("registerUser", new
|
||||
{
|
||||
userId = user.Id,
|
||||
userName = request.Username,
|
||||
email = request.Username,
|
||||
fullname = request.FullName,
|
||||
password = request.Password,
|
||||
roleId = request.RoleId,
|
||||
userTypeId = "00000001-0000-0000-0000-200000000000",
|
||||
sendCredentialsEmail = false
|
||||
}, reference: user.Id.ToString(), ct: ct);
|
||||
|
||||
if (!authResult.Success)
|
||||
{
|
||||
await uow.RollbackAsync(ct);
|
||||
throw new InvalidOperationException($"AuthHex registration failed: {authResult.Message}");
|
||||
}
|
||||
|
||||
await uow.CommitAsync(ct);
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in New Issue
Block a user