Allow admins to delete suggestions in Reveal

This commit is contained in:
2026-01-29 01:58:59 +01:00
parent af84fc50d4
commit a89ea5874b
2 changed files with 12 additions and 7 deletions

View File

@@ -98,15 +98,19 @@ public static class SuggestEndpoints
return Results.Created($"/api/suggestions/{suggestion.Id}", new { suggestion.Id }); return Results.Created($"/api/suggestions/{suggestion.Id}", new { suggestion.Id });
}); });
app.MapDelete("/api/suggestions/{id:int}", async (int id, HttpContext ctx, AppDbContext db) => app.MapDelete("/api/suggestions/{id:int}", async (int id, HttpContext ctx, AppDbContext db, IConfiguration config) =>
{ {
var phase = await EndpointHelpers.GetPhase(db);
if (phase != Phase.Suggest)
return EndpointHelpers.PhaseMismatch(Phase.Suggest, phase);
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db); var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
if (player is null) return Results.Unauthorized(); if (player is null) return Results.Unauthorized();
var suggestion = await db.Suggestions.FirstOrDefaultAsync(s => s.Id == id && s.PlayerId == player.Id); var isAdmin = await EndpointHelpers.IsAdmin(ctx, db, config);
var phase = await EndpointHelpers.GetPhase(db);
if (!isAdmin && phase != Phase.Suggest)
return EndpointHelpers.PhaseMismatch(Phase.Suggest, phase);
var suggestion = isAdmin
? await db.Suggestions.FirstOrDefaultAsync(s => s.Id == id)
: await db.Suggestions.FirstOrDefaultAsync(s => s.Id == id && s.PlayerId == player.Id);
if (suggestion == null) if (suggestion == null)
return Results.NotFound(new { error = "Suggestion not found." }); return Results.NotFound(new { error = "Suggestion not found." });

View File

@@ -155,7 +155,8 @@ function renderAllSuggestions() {
if (!list) return; if (!list) return;
list.innerHTML = ""; list.innerHTML = "";
const allowEdit = !!state.me?.isAdmin; const allowEdit = !!state.me?.isAdmin;
state.allSuggestions.forEach((s) => list.appendChild(buildCard(s, { showAuthor: true, allowEdit }))); const allowDelete = !!state.me?.isAdmin && (state.phase === "Reveal" || state.phase === "Suggest");
state.allSuggestions.forEach((s) => list.appendChild(buildCard(s, { showAuthor: true, allowEdit, allowDelete })));
} }
function renderVotes() { function renderVotes() {