mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-04-19 20:18:13 +02:00
Compare commits
No commits in common. "d6c0ad1138721a1a00356345156ab79c313bddb0" and "c6e11efdf207b74f13dad7d0d8475b64290ecc23" have entirely different histories.
d6c0ad1138
...
c6e11efdf2
|
@ -114,9 +114,4 @@ public class RoleRepository(IDbContextFactory<AuthorityContext> contextFactory)
|
||||||
return HandleException("Failed to delete role!", e);
|
return HandleException("Failed to delete role!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ListResult<AuthorityRoleItem>> GetUserRolesAsync(AuthorityUser user, int limit = 20, int offset = 0, string search = "", CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return ListResult<AuthorityRoleItem>.Failed("Not implemented!");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,11 +1,10 @@
|
||||||
using DotBased.AspNet.Authority.Models.Authority;
|
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Managers;
|
namespace DotBased.AspNet.Authority.Managers;
|
||||||
|
|
||||||
public partial class AuthorityManager
|
public partial class AuthorityManager
|
||||||
{
|
{
|
||||||
public async Task<ListResult<AuthorityGroupItem>> GetUserGroupsAsync(AuthorityUser user, CancellationToken cancellationToken = default)
|
/*
|
||||||
{
|
* - Validate User & Group
|
||||||
return ListResult<AuthorityGroupItem>.Failed("Not implemented!");
|
* - Check if user is already in group (if already in group return)
|
||||||
}
|
* - Add to UsersGroups table
|
||||||
|
*/
|
||||||
}
|
}
|
|
@ -1,36 +1,34 @@
|
||||||
using DotBased.AspNet.Authority.Models;
|
|
||||||
using DotBased.AspNet.Authority.Models.Authority;
|
using DotBased.AspNet.Authority.Models.Authority;
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Managers;
|
namespace DotBased.AspNet.Authority.Managers;
|
||||||
|
|
||||||
public partial class AuthorityManager
|
public partial class AuthorityManager
|
||||||
{
|
{
|
||||||
public async Task<AuthorityResult<AuthorityRole>> CreateRoleAsync(AuthorityRole role, CancellationToken cancellationToken = default)
|
public async Task<Result<AuthorityRole>> CreateRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
role.Version = GenerateVersion();
|
return Result<AuthorityRole>.Failed("Not implemented!");
|
||||||
var createResult = await roleRepository.CreateRoleAsync(role, cancellationToken);
|
|
||||||
return AuthorityResult<AuthorityRole>.FromResult(createResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result> DeleteRoleAsync(AuthorityRole role, CancellationToken cancellationToken = default)
|
public async Task<Result> DeleteRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
var result = await roleRepository.DeleteRoleAsync(role, cancellationToken);
|
return Result.Failed("Not implemented!");
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result<AuthorityRole>> UpdateRoleAsync(AuthorityRole role, CancellationToken cancellationToken = default)
|
public async Task<Result<AuthorityRole>> UpdateRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
var result = await roleRepository.UpdateRoleAsync(role, cancellationToken);
|
return Result<AuthorityRole>.Failed("Not implemented!");
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ListResult<AuthorityRoleItem>> GetRolesAsync(int limit = 20, int offset = 0, string search = "", CancellationToken cancellationToken = default)
|
public async Task<ListResult<AuthorityRole>> GetRolesAsync(int limit = 20, int offset = 0, string search = "", CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
var searchResult = await roleRepository.GetRolesAsync(limit, offset, search, cancellationToken);
|
/*
|
||||||
return searchResult;
|
* 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 = default)
|
public async Task AddRoleToUserAsync(AuthorityUser user, AuthorityRole role, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
- Validate User & Role
|
- Validate User & Role
|
||||||
|
@ -39,11 +37,11 @@ public partial class AuthorityManager
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveRoleFromUserAsync(AuthorityRole role, AuthorityUser user, CancellationToken cancellationToken = default)
|
public async Task RemoveRoleFromUserAsync(AuthorityRole role, AuthorityUser user, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddRoleToGroupAsync(AuthorityRole role, AuthorityGroup group, CancellationToken cancellationToken = default)
|
public async Task AddRoleToGroupAsync(AuthorityRole role, AuthorityGroup group, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,34 +50,16 @@ public partial class AuthorityManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user to get the roles from</param>
|
/// <param name="user">The user to get the roles from</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
public async Task<ListResult<AuthorityRole>> GetUserRolesAsync(AuthorityUser user, CancellationToken cancellationToken = default)
|
public async Task<ListResult<AuthorityRole>> GetUserRolesAsync(AuthorityUser user, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
var usrValidation = await IsValidUserAsync(user, cancellationToken);
|
/*
|
||||||
if (!usrValidation.Success)
|
* - Validate user
|
||||||
{
|
* - Get user groups (id)
|
||||||
return ListResult<AuthorityRole>.Failed("Invalid user");
|
* - Get roles contained from user
|
||||||
}
|
* - Get roles contained from groups (if any)
|
||||||
|
* - Order by (for paging)
|
||||||
|
*/
|
||||||
|
|
||||||
List<AuthorityRole> roles = [];
|
|
||||||
var usrRoles = await GetUserRolesAsync(user, cancellationToken);
|
|
||||||
if (usrRoles.Success)
|
|
||||||
{
|
|
||||||
roles.AddRange(usrRoles.Items);
|
|
||||||
}
|
|
||||||
var usrGroups = await GetUserGroupsAsync(user, cancellationToken);
|
|
||||||
if (usrGroups.Success)
|
|
||||||
{
|
|
||||||
var groupRolesResult = await GetGroupRolesAsync(usrGroups.Items.Select(g => g.Id).ToList(), cancellationToken);
|
|
||||||
if (groupRolesResult.Success)
|
|
||||||
{
|
|
||||||
roles.AddRange(groupRolesResult.Items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ListResult<AuthorityRole>.Ok(roles, roles.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ListResult<AuthorityRole>> GetGroupRolesAsync(List<Guid> groupIds, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return ListResult<AuthorityRole>.Failed("Not implemented!");
|
return ListResult<AuthorityRole>.Failed("Not implemented!");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,9 @@ public partial class AuthorityManager
|
||||||
var passwordValidation = await ValidatePasswordAsync(user, password);
|
var passwordValidation = await ValidatePasswordAsync(user, password);
|
||||||
if (!passwordValidation.Success)
|
if (!passwordValidation.Success)
|
||||||
{
|
{
|
||||||
return AuthorityResult<AuthorityUser>.Failed(passwordValidation.Errors, ResultFailReason.Validation);
|
List<ValidationError> errors = [];
|
||||||
|
errors.AddRange(passwordValidation.Errors);
|
||||||
|
return AuthorityResult<AuthorityUser>.Failed(errors, ResultFailReason.Validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.PasswordHash = await PasswordHasher.HashPasswordAsync(password);
|
user.PasswordHash = await PasswordHasher.HashPasswordAsync(password);
|
||||||
|
@ -88,10 +90,6 @@ public partial class AuthorityManager
|
||||||
var deleteResult = await UserRepository.DeleteUserAsync(model, cancellationToken);
|
var deleteResult = await UserRepository.DeleteUserAsync(model, cancellationToken);
|
||||||
return deleteResult;
|
return deleteResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result> IsValidUserAsync(AuthorityUser user, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
var usrResult = await userRepository.GetVersionAsync(user, cancellationToken);
|
|
||||||
return usrResult;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ public class AuthorityResult<TResultValue> : Result<TResultValue>
|
||||||
Reason = ResultFailReason.Unknown;
|
Reason = ResultFailReason.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthorityResult(bool success, string errorMessage = "", TResultValue? value = default, ResultFailReason reason = ResultFailReason.None, IReadOnlyList<ValidationError>? errors = null) : base(success, errorMessage, value, null)
|
public AuthorityResult(bool success, string errorMessage = "", TResultValue? value = default, ResultFailReason reason = ResultFailReason.None, List<ValidationError>? errors = null) : base(success, errorMessage, value, null)
|
||||||
{
|
{
|
||||||
Success = success;
|
Success = success;
|
||||||
Message = errorMessage;
|
Message = errorMessage;
|
||||||
|
@ -20,7 +20,7 @@ public class AuthorityResult<TResultValue> : Result<TResultValue>
|
||||||
ValidationErrors = errors;
|
ValidationErrors = errors;
|
||||||
}
|
}
|
||||||
public ResultFailReason Reason { get; }
|
public ResultFailReason Reason { get; }
|
||||||
public IReadOnlyList<ValidationError>? ValidationErrors { get; }
|
public List<ValidationError>? ValidationErrors { get; }
|
||||||
|
|
||||||
|
|
||||||
public static AuthorityResult<TResultValue> Ok(TResultValue? value) => new AuthorityResult<TResultValue>(true, value:value);
|
public static AuthorityResult<TResultValue> Ok(TResultValue? value) => new AuthorityResult<TResultValue>(true, value:value);
|
||||||
|
@ -28,7 +28,7 @@ public class AuthorityResult<TResultValue> : Result<TResultValue>
|
||||||
public static AuthorityResult<TResultValue> Error(string errorMessage, ResultFailReason reason = ResultFailReason.Error) =>
|
public static AuthorityResult<TResultValue> Error(string errorMessage, ResultFailReason reason = ResultFailReason.Error) =>
|
||||||
new AuthorityResult<TResultValue>(false, errorMessage, reason:reason);
|
new AuthorityResult<TResultValue>(false, errorMessage, reason:reason);
|
||||||
|
|
||||||
public static AuthorityResult<TResultValue> Failed(IReadOnlyList<ValidationError> errors, ResultFailReason reason = ResultFailReason.None)
|
public static AuthorityResult<TResultValue> Failed(List<ValidationError> errors, ResultFailReason reason = ResultFailReason.None)
|
||||||
=> new AuthorityResult<TResultValue>(false, errors:errors, reason:reason);
|
=> new AuthorityResult<TResultValue>(false, errors:errors, reason:reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user