[CHANGE] Building data structure

This commit is contained in:
max
2025-01-27 01:21:09 +01:00
parent 3ccd3106c1
commit c27890a31f
118 changed files with 356 additions and 51 deletions

View File

@@ -2,5 +2,9 @@ namespace DotBased.AspNet.Authority.Managers;
public partial class AuthorityManager
{
/*
* - Validate User & Group
* - Check if user is already in group (if already in group return)
* - Add to UsersGroups table
*/
}

43
DotBased.AspNet.Authority/Managers/AuthorityManager.cs Normal file → Executable file
View File

@@ -9,36 +9,25 @@ using Microsoft.Extensions.Options;
namespace DotBased.AspNet.Authority.Managers;
public partial class AuthorityManager
public partial class AuthorityManager(
IOptions<AuthorityOptions> options,
IServiceProvider services,
ICryptographer cryptographer,
IUserRepository userRepository,
IRoleRepository roleRepository,
IPasswordHasher passwordHasher)
{
public AuthorityManager(
IOptions<AuthorityOptions> options,
IServiceProvider services,
ICryptographer cryptographer,
IUserRepository userRepository,
IRoleRepository roleRepository,
IPasswordHasher passwordHasher)
{
_logger = LogService.RegisterLogger<AuthorityManager>();
Options = options.Value;
Services = services;
Cryptographer = cryptographer;
UserRepository = userRepository;
RoleRepository = roleRepository;
PasswordHasher = passwordHasher;
}
private readonly ILogger _logger = LogService.RegisterLogger<AuthorityManager>();
private readonly ILogger _logger;
public IServiceProvider Services { get; } = services;
public AuthorityOptions Options { get; } = options.Value;
public ICryptographer Cryptographer { get; } = cryptographer;
public IUserRepository UserRepository { get; } = userRepository;
public IRoleRepository RoleRepository { get; } = roleRepository;
public IPasswordHasher PasswordHasher { get; } = passwordHasher;
public IServiceProvider Services { get; }
public AuthorityOptions Options { get; }
public ICryptographer Cryptographer { get; }
public IUserRepository UserRepository { get; }
public IRoleRepository RoleRepository { get; }
public IPasswordHasher PasswordHasher { get; }
public IEnumerable<IPasswordValidator> PasswordValidators { get; } = [];
public IEnumerable<IUserValidator> UserValidators { get; } = [];

View File

@@ -19,9 +19,22 @@ public partial class AuthorityManager
return Result<AuthorityRole>.Failed("Not implemented!");
}
public async Task<ListResult<AuthorityRole>> GetRolesAsync(int limit = 20, int offset = 0, string search = "", CancellationToken? cancellationToken = null)
{
/*
* Search by role name & id
* Order by name, created date, creator? (paging)
*/
return ListResult<AuthorityRole>.Failed("Not implemented!");
}
public async Task AddRoleToUserAsync(AuthorityUser user, AuthorityRole role, CancellationToken? cancellationToken = null)
{
/*
- Validate User & Role
- Check if role is already in linked to user (if user already has the role, return)
- Add to UsersRoles table
*/
}
public async Task RemoveRoleFromUserAsync(AuthorityRole role, AuthorityUser user, CancellationToken? cancellationToken = null)
@@ -31,4 +44,22 @@ public partial class AuthorityManager
public async Task AddRoleToGroupAsync(AuthorityRole role, AuthorityGroup group, CancellationToken? cancellationToken = null)
{
}
/// <summary>
/// Get all roles (including group roles) that the user has.
/// </summary>
/// <param name="user">The user to get the roles from</param>
/// <param name="cancellationToken"></param>
public async Task<ListResult<AuthorityRole>> GetUserRolesAsync(AuthorityUser user, CancellationToken? cancellationToken = null)
{
/*
* - Validate user
* - Get user groups (id)
* - Get roles contained from user
* - Get roles contained from groups (if any)
* - Order by (for paging)
*/
return ListResult<AuthorityRole>.Failed("Not implemented!");
}
}

View File