submissions: reject reset unless validator is stale

This commit is contained in:
Quaternions 2025-03-19 18:05:34 -07:00
parent b4be174d98
commit 73e5c76e75

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"time"
"git.itzana.me/strafesnet/go-grpc/maps"
"git.itzana.me/strafesnet/maps-service/pkg/api"
@ -459,6 +460,16 @@ func (svc *Service) ActionSubmissionValidated(ctx context.Context, params api.Ac
return ErrPermissionDenied
}
// check when submission was updated
submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID)
if err != nil {
return err
}
if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) {
// the last time the submission was updated must be longer than 10 seconds ago
return ErrPermissionDenied
}
// transaction
smap := datastore.Optional()
smap.Add("status_id", model.StatusValidated)
@ -530,6 +541,16 @@ func (svc *Service) ActionSubmissionAccepted(ctx context.Context, params api.Act
return ErrPermissionDenied
}
// check when submission was updated
submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID)
if err != nil {
return err
}
if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) {
// the last time the submission was updated must be longer than 10 seconds ago
return ErrPermissionDenied
}
// transaction
smap := datastore.Optional()
smap.Add("status_id", model.StatusAccepted)