fix(security): synchronize report lifecycle and current roles

Revalidate admin roles from the database and serialize report generation registration with owner-scoped deletion.

Refs #9

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 21:35:38 +01:00
parent 0ebc531124
commit 609dbff7c1
16 changed files with 668 additions and 35 deletions

View File

@ -1,6 +1,8 @@
package handlers
import (
"database/sql"
"errors"
"net/http"
"strings"
@ -50,7 +52,7 @@ func (h *Handler) CreateReport(c *gin.Context) {
}
// Lancer la génération en arrière-plan
h.pipeline.GenerateReportAsync(report.ID, excerpt, req.Question, h.reportManager)
h.pipeline.GenerateReportAsync(userID, report.ID, excerpt, req.Question, h.reportManager)
c.JSON(http.StatusCreated, report)
}
@ -68,10 +70,19 @@ func (h *Handler) ListReports(c *gin.Context) {
func (h *Handler) DeleteReport(c *gin.Context) {
userID := c.GetString("userID")
id := c.Param("id")
// Annuler la goroutine si elle tourne encore
h.reportManager.Cancel(id)
if err := h.repo.DeleteReport(id, userID); err != nil {
httputil.InternalError(c, err)
err := h.reportManager.WithReport(userID, id, func() error {
if err := h.repo.DeleteReport(id, userID); err != nil {
return err
}
h.reportManager.CancelReport(userID, id)
return nil
})
if errors.Is(err, sql.ErrNoRows) {
httputil.NotFound(c)
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "report deletion failed"})
return
}
c.Status(http.StatusNoContent)