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

@@ -17,7 +17,8 @@ public sealed class ProposalWorkflowTests(BackendFixture fixture) : IClassFixtur
public async Task VotesAndDecisionsAreReflectedInTheProposalAndItsHistory()
{
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 authorUser = await fixture.RegisterAsync(anonymous);
using var author = fixture.CreateClient((await LoginAsync(anonymous, authorUser.Email)).AccessToken);
var managerSession = await fixture.RegisterStaffAsync(anonymous, admin, "MANAGEMENT");
@@ -34,6 +35,10 @@ public sealed class ProposalWorkflowTests(BackendFixture fixture) : IClassFixtur
await ExpectAsync(manager.PutAsJsonAsync(path, edit, Cancellation), HttpStatusCode.Forbidden);
proposal = await ReadAsync<ProposalDetail>(author.PutAsJsonAsync(path, edit, Cancellation));
Assert.Equal((edit.CategoryId, edit.Description, "UPDATED"), (proposal.CategoryId, proposal.Description, proposal.Events[^1].EventType));
var adminEdit = edit with { Description = "Otevřít do 22 hodin ve všední dny." };
proposal = await ReadAsync<ProposalDetail>(admin.PutAsJsonAsync(path, adminEdit, Cancellation));
Assert.Equal((adminEdit.Description, authorUser.Id, administrator.User.Id),
(proposal.Description, proposal.AuthorId, proposal.Events[^1].ActorId));
var other = await ReadAsync<ProposalDetail>(author.PostAsJsonAsync(Proposals, edit with
{
Title = "Vybavení studovny",
@@ -57,21 +62,21 @@ public sealed class ProposalWorkflowTests(BackendFixture fixture) : IClassFixtur
HttpStatusCode.Forbidden);
await ExpectAsync(manager.PostAsJsonAsync(path + "/status", new ChangeProposalStatusRequest("REJECTED", " "), Cancellation),
HttpStatusCode.BadRequest);
await ExpectAsync(manager.PostAsJsonAsync(path + "/status", new ChangeProposalStatusRequest("IMPLEMENTED", null), Cancellation),
await ExpectAsync(admin.PostAsJsonAsync(path + "/status", new ChangeProposalStatusRequest("IMPLEMENTED", null), Cancellation),
HttpStatusCode.Conflict);
var review = await ReadAsync<ProposalDetail>(manager.PostAsJsonAsync(path + "/status",
var review = await ReadAsync<ProposalDetail>(admin.PostAsJsonAsync(path + "/status",
new ChangeProposalStatusRequest("UNDER_REVIEW", null), Cancellation));
Assert.Equal("UNDER_REVIEW", review.Status);
var accepted = await ReadAsync<ProposalDetail>(manager.PostAsJsonAsync(path + "/status",
new ChangeProposalStatusRequest("ACCEPTED", " Schváleno. "), Cancellation));
Assert.Equal(("ACCEPTED", "Schváleno."), (accepted.Status, accepted.Events[^1].Note));
await ExpectAsync(author.PutAsJsonAsync(path, edit, Cancellation), HttpStatusCode.Conflict);
await ExpectAsync(admin.PutAsJsonAsync(path, edit, Cancellation), HttpStatusCode.Conflict);
await ExpectAsync(manager.DeleteAsync(path + "/vote", Cancellation), HttpStatusCode.Conflict);
var inbox = await ReadAsync<PagedResult<NotificationDto>>(author.GetAsync("/api/v1/notifications", Cancellation));
Assert.Equal(2, inbox.Items.Count(item => item.ProposalId == proposal.Id && item.Type == "PROPOSAL_STATUS_CHANGED"));
var top = Assert.Single(await ReadAsync<TopProposal[]>(
manager.GetAsync($"/api/v1/statistics/proposals/top?limit=1&from={from}&to={to}", Cancellation)));
admin.GetAsync($"/api/v1/statistics/proposals/top?limit=1&from={from}&to={to}", Cancellation)));
Assert.Equal((proposal.Id, 1L), (top.Id, top.Score));
}