fixed ManageUser allowing to add roles to oneself

This commit is contained in:
Mia Rose Winter 2024-01-22 11:18:46 +01:00
parent c8f0cea89b
commit 8e2589dbc1
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -1,5 +1,4 @@
@page "/manage/users"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Wave.Data
@using Humanizer
@ -93,12 +92,17 @@
}
private async Task Add() {
if (User is null) return;
var user = await UserManager.FindByNameAsync(UserName);
if (user is null) {
Toast.ShowError(Localizer["Error_UserNotFound"]);
return;
}
if (user.Id == User.Id) {
Toast.ShowError(Localizer["Error_EditSelf"]);
return;
}
if (!await RoleManager.RoleExistsAsync(CurrentRole.ToString())) {
var result = await RoleManager.CreateAsync(new IdentityRole(CurrentRole.ToString()));