mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-14 09:11:28 +00:00
Add ability to change user's permissions from admin panel user list
This commit is contained in:
parent
ff12f5f7d5
commit
1037a6eddb
6 changed files with 44 additions and 3 deletions
|
@ -101,4 +101,26 @@ public class AdminUserController : ControllerBase
|
|||
|
||||
return this.Redirect($"/user/{targetedUser.UserId}");
|
||||
}
|
||||
|
||||
[HttpPost("setPermissionLevel")]
|
||||
public async Task<IActionResult> SetUserPermissionLevel([FromRoute] int id, [FromForm] PermissionLevel role)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
||||
if (role != PermissionLevel.Banned)
|
||||
{
|
||||
targetedUser.PermissionLevel = role;
|
||||
await this.database.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Redirect($"/admin/user/{id}/ban");
|
||||
}
|
||||
|
||||
return this.Redirect("/admin/users");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue