feat: admins can change user's roles

refactor: banned role has priority over all other roles when displaying
chore: npm run format
This commit is contained in:
2026-01-06 14:07:55 -05:00
parent fe54ff15ce
commit 99feb2795a
8 changed files with 188 additions and 112 deletions
@@ -67,6 +67,10 @@ namespace SharpbinV3.Server.Controllers
user.Email = updatedUser.Email ?? user.Email;
user.Visibility = updatedUser.Visibility ?? user.Visibility;
}
if (userRoles.Any(r => r == 255))
{
user.Roles = updatedUser.Roles ?? user.Roles;
}
await _db.SaveChangesAsync();
return Ok(new { message = "User updated successfully." });
}
@@ -8,6 +8,7 @@ namespace SharpbinV3.Server.DTOs
public string? DisplayName { get; set; }
public string? Email { get; set; }
public int? Visibility { get; set; } = 0;
public int[]? Roles { get; set; }
public IEnumerable<ValidationResult> Validate()
{
@@ -30,6 +31,18 @@ namespace SharpbinV3.Server.DTOs
if (Visibility < 0 || Visibility > 2)
results.Add(new ValidationResult("Visibility must be between 0 and 2.", [nameof(Visibility)]));
}
if (Roles != null)
{
if (Roles.Length == 0)
results.Add(new ValidationResult("Roles cannot be an empty array.", [nameof(Roles)]));
int[] validRoles = [0, 1, 255, 403];
foreach (var role in Roles)
{
if (!validRoles.Contains(role))
results.Add(new ValidationResult($"Invalid role: {role}.", [nameof(Roles)]));
}
}
return results;
}