mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: prevent moderators from modifiying higher roles(admin)
This commit is contained in:
@@ -60,6 +60,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
if (!userRoles.Any(r => r == 1 || r == 255) && user.UUID != Guid.Parse(uuidClaim))
|
if (!userRoles.Any(r => r == 1 || r == 255) && user.UUID != Guid.Parse(uuidClaim))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
if (user.Roles.Contains(255) && !userRoles.Contains(255))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
user.DisplayName = updatedUser.DisplayName ?? user.DisplayName;
|
user.DisplayName = updatedUser.DisplayName ?? user.DisplayName;
|
||||||
if (userRoles.Any(r => r == 255) || user.UUID == Guid.Parse(uuidClaim)) // only admins or self
|
if (userRoles.Any(r => r == 255) || user.UUID == Guid.Parse(uuidClaim)) // only admins or self
|
||||||
@@ -71,6 +73,7 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
{
|
{
|
||||||
user.Roles = updatedUser.Roles ?? user.Roles;
|
user.Roles = updatedUser.Roles ?? user.Roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
return Ok(new { message = "User updated successfully." });
|
return Ok(new { message = "User updated successfully." });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user