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,6 +1,10 @@
|
||||
using Distribution.Models;
|
||||
|
||||
namespace Distribution.Infra.Authorization;
|
||||
|
||||
public interface IPermissionRepository
|
||||
{
|
||||
Task<bool> HasPermissionAsync(Guid roleId, string permissionCode);
|
||||
Task<List<string>> GetRolePermissionsAsync(Guid roleId);
|
||||
Task<List<Permission>> GetAllAsync();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using Distribution.Models;
|
||||
|
||||
namespace Distribution.Infra.Authorization;
|
||||
|
||||
public interface IPermissionService
|
||||
{
|
||||
Task<bool> HasPermissionAsync(Guid roleId, string permissionCode);
|
||||
Task<List<string>> GetRolePermissionsAsync(Guid roleId);
|
||||
Task<List<Permission>> GetAllAsync();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Distribution.Data;
|
||||
using Distribution.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Distribution.Infra.Authorization;
|
||||
@@ -10,4 +11,15 @@ public class PermissionRepository(AppDBContext context) : IPermissionRepository
|
||||
.Where(rp => rp.FK_RoleId == roleId && rp.IsActive)
|
||||
.Join(context.Permissions.Where(p => p.IsActive), rp => rp.FK_PermissionId, p => p.Id, (rp, p) => p.Code)
|
||||
.AnyAsync(code => code == permissionCode);
|
||||
|
||||
public Task<List<string>> GetRolePermissionsAsync(Guid roleId) =>
|
||||
context.RolePermissions
|
||||
.Where(rp => rp.FK_RoleId == roleId && rp.IsActive)
|
||||
.Select(rp => rp.Permission)
|
||||
.Where(p => p.IsActive)
|
||||
.Select(p => p.Code)
|
||||
.ToListAsync();
|
||||
|
||||
public Task<List<Permission>> GetAllAsync() =>
|
||||
context.Permissions.Where(p => p.IsActive).ToListAsync();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
using Distribution.Models;
|
||||
|
||||
namespace Distribution.Infra.Authorization;
|
||||
|
||||
public class PermissionService(IPermissionRepository repo) : IPermissionService
|
||||
{
|
||||
public Task<bool> HasPermissionAsync(Guid roleId, string permissionCode) =>
|
||||
repo.HasPermissionAsync(roleId, permissionCode);
|
||||
|
||||
public Task<List<string>> GetRolePermissionsAsync(Guid roleId) =>
|
||||
repo.GetRolePermissionsAsync(roleId);
|
||||
|
||||
public Task<List<Permission>> GetAllAsync() =>
|
||||
repo.GetAllAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user