backend: Add concurrency checks to admin user edits

This commit is contained in:
GonnaHetzMe committed 2026-12-04 18:25:30 +01:00
1 parent 91d0c06c83
commit bd8eb65e56
18 files changed
+216 -23

No files matched your search

@@ -1,5 +1,6 @@
using Helpdesk.Application.Abstractions;
using Helpdesk.Application.Common;
using Helpdesk.Domain.Auth;
using Microsoft.EntityFrameworkCore;
namespace Helpdesk.Application.Notifications;
@@ -14,6 +15,11 @@ public sealed class PushDeviceService(IAppDbContext db, ICurrentUser currentUser
if (user is not { IsActive: true, IsDeleted: false })
throw new UnauthorizedException("Účet není aktivní.");
// Po čekání na zámek mohl správce relaci odhlásit a odstranit všechna její zařízení.
if (!await db.AuthTokens.AnyAsync(t => t.Jti == currentUser.TokenId && t.UserId == user.Id &&
t.TokenType == TokenType.Access && t.RevokedAt == null, ct))
throw new UnauthorizedException("Přihlášení vypršelo. Přihlaste se znovu.");
await db.RegisterPushDeviceAsync(user.Id, token, ct);
await transaction.CommitAsync(ct);
}