feat: мультироль
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s

This commit is contained in:
2026-05-11 21:29:16 +03:00
parent 3b0bbfc858
commit 6824d7ce7d
29 changed files with 1350 additions and 95 deletions
@@ -137,23 +137,26 @@ public class UsersController : ControllerBase
public async Task<ActionResult> GetAll([FromQuery] UserFilterRequest filter) =>
Ok(await _users.GetAllAsync(filter));
/// <summary>Изменить роль пользователя.</summary>
/// <summary>Изменить набор ролей пользователя.</summary>
/// <remarks>Только Admin. Доступные роли: Student, Teacher, Admin.</remarks>
/// <param name="id">ID пользователя.</param>
/// <param name="role">Новая роль.</param>
/// <response code="204">Роль успешно изменена.</response>
/// <param name="roles">Новый набор ролей пользователя.</param>
/// <response code="204">Роли успешно изменены.</response>
/// <response code="401">Требуется аутентификация.</response>
/// <response code="403">Требуется роль Admin.</response>
/// <response code="404">Пользователь не найден.</response>
[Authorize(Roles = "Admin")]
[HttpPatch("{id:int}/role")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> SetRole(int id, [FromBody] UserRole role)
public async Task<IActionResult> SetRole(int id, [FromBody] IReadOnlyCollection<UserRole> roles)
{
await _users.SetRoleAsync(id, role);
if (roles.Count == 0)
return BadRequest("At least one role is required.");
await _users.SetRolesAsync(id, roles);
return NoContent();
}