fix: prevent moderators from modifiying higher roles(admin)

This commit is contained in:
2026-01-07 10:24:51 -05:00
parent d514e456bf
commit 3711885a38
@@ -60,6 +60,8 @@ namespace SharpbinV3.Server.Controllers
return NotFound();
if (!userRoles.Any(r => r == 1 || r == 255) && user.UUID != Guid.Parse(uuidClaim))
return Forbid();
if (user.Roles.Contains(255) && !userRoles.Contains(255))
return Forbid();
user.DisplayName = updatedUser.DisplayName ?? user.DisplayName;
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;
}
await _db.SaveChangesAsync();
return Ok(new { message = "User updated successfully." });
}