backend: Extend issue and proposal access to admins
This commit is contained in:
1 parent
34f2d57bd3
commit
ea3de2e444
16 files changed
+184
-127
No files matched your search
@@ -80,10 +80,11 @@ public sealed partial class IssueService
|
||||
public async Task<IReadOnlyList<AssignableUserDto>> GetAssignableAsync(CancellationToken ct)
|
||||
{
|
||||
var actor = await GetActorAsync(ct);
|
||||
if (actor.Role != UserRole.Management)
|
||||
throw new ForbiddenException("Přehled řešitelů je určen vedení.");
|
||||
if (!Issue.CanAssign(actor.Role))
|
||||
throw new ForbiddenException("Přehled řešitelů je určen vedení a administrátorům.");
|
||||
|
||||
var users = await db.Users.Where(u => u.IsActive && (u.Role == UserRole.Management || u.Role == UserRole.FacilityManager))
|
||||
var users = await db.Users.Where(u => u.IsActive &&
|
||||
(u.Role == UserRole.Management || u.Role == UserRole.FacilityManager || u.Role == UserRole.Admin))
|
||||
.OrderBy(u => u.LastName).ThenBy(u => u.FirstName).ThenBy(u => u.Id)
|
||||
.Select(u => new
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed partial class IssueService(
|
||||
CheckVersion(issue, request.RowVersion);
|
||||
var assignee = await db.Users.AsNoTracking().SingleOrDefaultAsync(u => u.Id == request.AssigneeId && u.IsActive, ct);
|
||||
if (assignee is null || !Issue.CanBeAssigned(assignee.Role))
|
||||
throw new BadRequestException("Vyberte aktivního správce budov nebo člena vedení.");
|
||||
throw new BadRequestException("Vyberte aktivního správce budov, člena vedení nebo administrátora.");
|
||||
if (issue.AssigneeId == assignee.Id)
|
||||
throw new ConflictException("Závada je již přiřazena tomuto řešiteli.");
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ public sealed class NotificationWriter(IAppDbContext db, TimeProvider clock)
|
||||
{
|
||||
var reporterId = issue.ReporterId;
|
||||
var eligibleUsers = db.Users.Where(u =>
|
||||
u.Id == reporterId || u.Role == UserRole.FacilityManager || u.Role == UserRole.Management);
|
||||
u.Id == reporterId || u.Role == UserRole.FacilityManager || u.Role == UserRole.Management ||
|
||||
u.Role == UserRole.Admin);
|
||||
return QueueAsync(eligibleUsers, actorId, recipientIds,
|
||||
id => new Notification(issue, id, type, title, issue.Title), ct);
|
||||
}
|
||||
|
||||
@@ -28,20 +28,20 @@ public sealed partial class ProposalService(
|
||||
|
||||
public async Task<ProposalDetail> EditAsync(int id, SaveProposalRequest request, CancellationToken ct)
|
||||
{
|
||||
await GetActorRoleAsync(ct);
|
||||
var role = await GetActorRoleAsync(ct);
|
||||
var (title, description) = ValidateDetails(request);
|
||||
await using (var transaction = await db.BeginWriteAsync(ct))
|
||||
{
|
||||
var proposal = await LockProposalAsync(id, ct);
|
||||
if (!proposal.IsAuthor(currentUser.Id))
|
||||
throw new ForbiddenException("Návrh může upravit jen jeho autor.");
|
||||
if (!proposal.CanEditAs(currentUser.Id, role))
|
||||
throw new ForbiddenException("Návrh může upravit jeho autor nebo administrátor.");
|
||||
if (!proposal.IsEditable)
|
||||
throw new ConflictException("Návrh lze upravit jen ve stavu Podán.");
|
||||
|
||||
if (proposal.CategoryId != request.CategoryId)
|
||||
await RequireActiveCategoryAsync(request.CategoryId, ct);
|
||||
|
||||
proposal.Edit(currentUser.Id, title, description, request.CategoryId);
|
||||
proposal.Edit(currentUser.Id, role, title, description, request.CategoryId);
|
||||
AddEvent(proposal, ProposalEventType.Updated);
|
||||
await db.SaveChangesAsync(ct);
|
||||
await transaction.CommitAsync(ct);
|
||||
@@ -53,8 +53,8 @@ public sealed partial class ProposalService(
|
||||
public async Task<ProposalDetail> ChangeStatusAsync(int id, ChangeProposalStatusRequest request, CancellationToken ct)
|
||||
{
|
||||
var role = await GetActorRoleAsync(ct);
|
||||
if (role != UserRole.Management)
|
||||
throw new ForbiddenException("Stav návrhu může změnit jen vedení školy.");
|
||||
if (!Proposal.CanReview(role))
|
||||
throw new ForbiddenException("Stav návrhu může změnit vedení školy nebo administrátor.");
|
||||
|
||||
var target = ParseStatus(request.Status);
|
||||
var note = string.IsNullOrWhiteSpace(request.Note) ? null : request.Note.Trim();
|
||||
|
||||
Reference in new issue
Block a user