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

@ -125,14 +125,19 @@ func (p *Pipeline) GenerateForAll(ctx context.Context) error {
}
// GenerateReportAsync crée le rapport en DB (status=generating) et lance la génération en arrière-plan.
func (p *Pipeline) GenerateReportAsync(reportID, excerpt, question string, mgr *ReportManager) {
func (p *Pipeline) GenerateReportAsync(ownerID, reportID, excerpt, question string, mgr *ReportManager) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
mgr.Register(reportID, cancel)
if err := mgr.RegisterForReport(ownerID, reportID, reportID, cancel, func() (bool, error) { report, err := p.repo.GetReport(reportID, ownerID); return report != nil, err }); err != nil {
return
}
go func() {
defer cancel()
defer mgr.Remove(reportID)
defer mgr.Remove(ownerID, reportID)
if ctx.Err() != nil {
return
}
answer, err := p.callProviderForReport(ctx, excerpt, question)
if err != nil {
if ctx.Err() != nil {
@ -164,12 +169,20 @@ func (p *Pipeline) callProviderForReport(ctx context.Context, excerpt, question
// history contient tous les messages précédents (user + assistant), dans l'ordre.
func (p *Pipeline) GenerateReportMessageAsync(messageID string, report *models.Report, history []models.ReportMessage, mgr *ReportManager) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
mgr.Register(messageID, cancel)
if err := mgr.RegisterForReport(report.UserID, report.ID, messageID, cancel, func() (bool, error) {
current, err := p.repo.GetReport(report.ID, report.UserID)
return current != nil, err
}); err != nil {
return
}
go func() {
defer cancel()
defer mgr.Remove(messageID)
defer mgr.Remove(report.UserID, messageID)
if ctx.Err() != nil {
return
}
answer, err := p.callProviderForConversation(ctx, report, history)
if err != nil {
if ctx.Err() != nil {