mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 05:26:34 +00:00
add edit role functionality
This commit is contained in:
@@ -173,6 +173,11 @@ app.MapPut("/users/queue-offsets/set",
|
||||
.RequireAuthorization()
|
||||
.WithOpenApi(op => new OpenApiOperation(op) { Summary = "Sets user's queue offsets" });
|
||||
|
||||
app.MapPut("/users/{email}/set-role/{role}", async (string email, RoleEnum role, IUserService userService, CancellationToken ct)
|
||||
=> await userService.ChangeRole(email, role, ct))
|
||||
.RequireAuthorization(apiAdminPolicy)
|
||||
.WithOpenApi(op => new OpenApiOperation(op) { Summary = "Set user's role" });
|
||||
|
||||
app.MapPut("/users/{email}/enable", async (string email, IUserService userService, CancellationToken ct)
|
||||
=> await userService.SetEnableStatus(email, true, ct))
|
||||
.RequireAuthorization(apiAdminPolicy)
|
||||
|
||||
@@ -16,6 +16,7 @@ public interface IUserService
|
||||
Task UpdateQueueOffsets(string email, UserQueueOffsets queueOffsets, CancellationToken ct = default);
|
||||
Task<IEnumerable<User>> GetUsers(string? searchEmail, RoleEnum? searchRole, CancellationToken ct = default);
|
||||
Task<string> CheckHardwareHash(User user, string hardware, CancellationToken ct = default);
|
||||
Task ChangeRole(string email, RoleEnum newRole, CancellationToken ct = default);
|
||||
Task SetEnableStatus(string email, bool isEnabled, CancellationToken ct = default);
|
||||
Task RemoveUser(string email, CancellationToken ct = default);
|
||||
}
|
||||
@@ -131,6 +132,15 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
|
||||
}, ct));
|
||||
}
|
||||
|
||||
public async Task ChangeRole(string email, RoleEnum newRole, CancellationToken ct = default)
|
||||
{
|
||||
await dbFactory.RunAdmin(async db =>
|
||||
await db.Users.UpdateAsync(x => x.Email == email, u => new User
|
||||
{
|
||||
Role = newRole
|
||||
}, ct));
|
||||
}
|
||||
|
||||
public async Task SetEnableStatus(string email, bool isEnabled, CancellationToken ct = default)
|
||||
{
|
||||
await dbFactory.RunAdmin(async db =>
|
||||
|
||||
Reference in New Issue
Block a user