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

@ -41,6 +41,9 @@ func (r *Repository) GetUserByEmail(email string) (*User, error) {
}
func (r *Repository) GetUserByID(id string) (*User, error) {
if r == nil {
return nil, errors.New("repository unavailable")
}
u := &User{}
err := r.db.QueryRow(`
SELECT id, email, password_hash, role, created_at, updated_at
@ -501,8 +504,8 @@ func (r *Repository) ListReports(userID string) ([]Report, error) {
}
func (r *Repository) DeleteReport(id, userID string) error {
_, err := r.db.Exec(`DELETE FROM reports WHERE id=$1 AND user_id=$2`, id, userID)
return err
var deleted string
return r.db.QueryRow(`DELETE FROM reports WHERE id=$1 AND user_id=$2 RETURNING id`, id, userID).Scan(&deleted)
}
func (r *Repository) GetReport(id, userID string) (*Report, error) {