backend: Extend issue and proposal access to admins

This commit is contained in:
GonnaHetzMe committed 2026-12-04 10:19:13 +01:00
1 parent 34f2d57bd3
commit ea3de2e444
16 files changed
+184 -127

No files matched your search

@@ -15,7 +15,8 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
public async Task ReporterAndAssigneesCanResolveAnIssueAndManagementCanReportOnIt()
{
using var anonymous = fixture.CreateClient();
using var admin = fixture.CreateClient((await LoginAsync(anonymous, AdminEmail)).AccessToken);
var administrator = await LoginAsync(anonymous, AdminEmail);
using var admin = fixture.CreateClient(administrator.AccessToken);
var author = await fixture.RegisterAsync(anonymous);
using var reporter = fixture.CreateClient((await LoginAsync(anonymous, author.Email)).AccessToken);
var management = await fixture.RegisterStaffAsync(anonymous, admin, "MANAGEMENT");
@@ -37,9 +38,20 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
new EditIssueRequest(issue.Title, "Projektor nereaguje ani po restartu.", issue.CategoryId,
issue.BuildingId, issue.LocationDetail, issue.RowVersion), Cancellation));
Assert.Equal("Projektor nereaguje ani po restartu.", issue.Description);
issue = await ReadAsync<IssueDetail>(admin.PutAsJsonAsync(path,
new EditIssueRequest(issue.Title, issue.Description, issue.CategoryId,
issue.BuildingId, "A102", issue.RowVersion), Cancellation));
Assert.Equal(("A102", author.Id), (issue.LocationDetail, issue.ReporterId));
var assign = new AssignIssueRequest(firstAssignee.User.Id, null, issue.RowVersion);
await ExpectAsync(reporter.PostAsJsonAsync(path + "/assign", assign, Cancellation), HttpStatusCode.Forbidden);
issue = await PostIssueAsync(manager, path + "/assign", assign);
issue = await PostIssueAsync(admin, path + "/assign", assign);
Assert.Equal(firstAssignee.User.Id, issue.AssigneeId);
Assert.Contains("ASSIGN", (await ReadAsync<IssueDetail>(admin.GetAsync(path, Cancellation))).AllowedActions);
var adminIssues = await ReadAsync<PagedResult<IssueSummary>>(admin.GetAsync("/api/v1/issues", Cancellation));
Assert.Contains(adminIssues.Items, item => item.Id == issue.Id);
var assignable = await ReadAsync<AssignableUserDto[]>(admin.GetAsync("/api/v1/users/assignable", Cancellation));
Assert.Contains(assignable, user => user.Id == firstAssignee.User.Id);
Assert.Contains(assignable, user => user.Id == administrator.User.Id);
await ExpectAsync(firstSolver.PostAsJsonAsync(path + "/start",
new IssueVersionRequest(assign.RowVersion), Cancellation), HttpStatusCode.Conflict);
@@ -49,10 +61,10 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
Assert.Equal("ISSUE_ASSIGNED", Assert.Single(await InboxAsync(secondSolver, issue.Id)).Type);
Assert.Equal(reporterNotifications, await InboxAsync(reporter, issue.Id));
issue = await PostIssueAsync(secondSolver, path + "/start", new IssueVersionRequest(issue.RowVersion));
issue = await PostIssueAsync(admin, path + "/start", new IssueVersionRequest(issue.RowVersion));
Assert.Equal("IN_PROGRESS", issue.Status);
reporterNotifications = await InboxAsync(reporter, issue.Id);
issue = await PostIssueAsync(manager, path + "/assign", new AssignIssueRequest(firstAssignee.User.Id, null, issue.RowVersion));
issue = await PostIssueAsync(admin, path + "/assign", new AssignIssueRequest(firstAssignee.User.Id, null, issue.RowVersion));
Assert.Equal("ASSIGNED", issue.Status);
var reassignment = Assert.Single((await InboxAsync(reporter, issue.Id)).Except(reporterNotifications));
Assert.Equal("ISSUE_STATUS_CHANGED", reassignment.Type);
@@ -60,16 +72,17 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
issue = await PostIssueAsync(firstSolver, path + "/start", new IssueVersionRequest(issue.RowVersion));
const string commentText = "Porucha stále trvá.";
var comment = await ReadAsync<IssueEventDto>(reporter.PostAsJsonAsync(path + "/comments",
var comment = await ReadAsync<IssueEventDto>(admin.PostAsJsonAsync(path + "/comments",
new CommentRequest(commentText), Cancellation));
Assert.Equal(administrator.User.Id, comment.ActorId);
issue = await ReadAsync<IssueDetail>(firstSolver.GetAsync(path, Cancellation));
issue = await PostIssueAsync(firstSolver, path + "/submit-for-verification", new VerifyIssueRequest(issue.RowVersion, null));
Assert.Equal("PENDING_VERIFICATION", issue.Status);
issue = await PostIssueAsync(reporter, path + "/reopen", new IssueReasonRequest(issue.RowVersion, "Porucha se vrátila."));
issue = await PostIssueAsync(admin, path + "/reopen", new IssueReasonRequest(issue.RowVersion, "Porucha se vrátila."));
Assert.Equal("IN_PROGRESS", issue.Status);
Assert.Contains(await InboxAsync(firstSolver, issue.Id), notification => notification.Type == "ISSUE_REOPENED");
issue = await PostIssueAsync(firstSolver, path + "/submit-for-verification", new VerifyIssueRequest(issue.RowVersion, "Ověřeno."));
issue = await PostIssueAsync(reporter, path + "/confirm", new IssueVersionRequest(issue.RowVersion));
issue = await PostIssueAsync(admin, path + "/submit-for-verification", new VerifyIssueRequest(issue.RowVersion, "Ověřeno."));
issue = await PostIssueAsync(admin, path + "/confirm", new IssueVersionRequest(issue.RowVersion));
Assert.Equal("RESOLVED", issue.Status);
var events = await ReadAsync<IssueEventDto[]>(reporter.GetAsync(path + "/events", Cancellation));
Assert.Equal(commentText, Assert.Single(events, entry => entry.Id == comment.Id).Note);
@@ -81,6 +94,17 @@ public sealed class IssueWorkflowTests(BackendFixture fixture) : IClassFixture<B
var rejected = await PostIssueAsync(manager, $"/api/v1/issues/{openIssue.Id}/reject",
new IssueReasonRequest(openIssue.RowVersion, "Duplicitní hlášení."));
Assert.Equal("REJECTED", rejected.Status);
var officeIssue = await PostIssueAsync(reporter, "/api/v1/issues",
request with { Title = "Porucha v kanceláři" }, HttpStatusCode.Created);
var officePath = $"/api/v1/issues/{officeIssue.Id}";
officeIssue = await PostIssueAsync(manager, officePath + "/assign",
new AssignIssueRequest(administrator.User.Id, null, officeIssue.RowVersion));
Assert.Equal(administrator.User.Id, officeIssue.AssigneeId);
Assert.Equal("ISSUE_ASSIGNED", Assert.Single(await InboxAsync(admin, officeIssue.Id)).Type);
var rejectedByAdmin = await PostIssueAsync(admin, officePath + "/reject",
new IssueReasonRequest(officeIssue.RowVersion, "Hlášení je duplicitní."));
Assert.Equal("REJECTED", rejectedByAdmin.Status);
}
private static async Task VerifyReadsAsync(HttpClient reporter, HttpClient manager, IssueDetail resolved, IssueDetail open)