mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-16 20:56:03 +00:00
29cc51ee0c
Implements message reactions and reaction packs (domain models, services, admin HTTP API, media processing via ImageSharp and limits) and adds reliable push delivery (ChatPushNotification, ChatPushDispatcher, ChatPushWorker, improved ChatNotificationService). Enhances message reading (ReadChat API, unread counts, concurrency-safe receipts) and tightens session security (access-token session validation in JWT, hub filter, SessionAuthorization). Improves SignalR behavior (session groups, reaction/channel events, hub/error mappings). Adds EF migrations, many controller fixes (Forbid handling, password API), tests (Govor.Server.Tests), docs, CI and tooling updates (Dockerfile → .NET 10, GH Actions matrix for sqlite/postgres, Govor.Server.slnx, global.json), and small infra changes (AutoMapper bump, NullPushProvider, storage/token handling).
92 lines
2.5 KiB
C#
92 lines
2.5 KiB
C#
using Govor.Application.Infrastructure.AdminsStuff;
|
|
using Govor.Contracts.Responses.Admins;
|
|
using Govor.Domain.Models.Users;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Govor.Contracts.Requests;
|
|
|
|
namespace Govor.API.Controllers.AdminStuff;
|
|
|
|
|
|
[ApiController]
|
|
[Route("api/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class UsersController : Controller
|
|
{
|
|
private readonly ILogger<UsersController> _logger;
|
|
private readonly IUsersAdministration _users;
|
|
|
|
public UsersController(
|
|
ILogger<UsersController> logger,
|
|
IUsersAdministration users)
|
|
{
|
|
_logger = logger;
|
|
_users = users;
|
|
}
|
|
|
|
[HttpGet("all")]
|
|
public async Task<IActionResult> AllUsers()
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation("Getting all users by administrator");
|
|
var read = await _users.GetAllUsersAsync();
|
|
|
|
return Ok(BuildUserDtos(read));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> GetUserById(Guid id)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation($"Getting user {id} by administrator");
|
|
var read = await _users.GetUserById(id);
|
|
if (read is null)
|
|
return NotFound();
|
|
return Ok(BuildUserDtos([read]).First());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost("user/{id:guid}/password")]
|
|
public async Task<IActionResult> SetNewPassword(Guid id, [FromBody] SetPasswordRequest request)
|
|
{
|
|
try
|
|
{
|
|
if (await _users.GetUserById(id) is null)
|
|
return NotFound();
|
|
await _users.SetPasswordAsync(id, request.Password);
|
|
return NoContent();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex.Message);
|
|
}
|
|
}
|
|
|
|
private List<UserResponse> BuildUserDtos(IEnumerable<User> users) => users.Select(user => new UserResponse
|
|
{
|
|
Id = user.Id,
|
|
Username = user.Username,
|
|
Description = user.Description,
|
|
WasOnline = user.WasOnline,
|
|
IconId = user.IconId,
|
|
InviteId = user.InviteId,
|
|
CreatedOn = user.CreatedOn,
|
|
IsAdmin = user.Invite?.IsAdmin ?? false,
|
|
}).ToList();
|
|
|
|
}
|