submissions: improve error granularity

This commit is contained in:
Quaternions 2025-03-26 11:56:57 -07:00
parent 636bb1fb94
commit 7d57d1ac4d
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"time" "time"
"git.itzana.me/strafesnet/go-grpc/maps" "git.itzana.me/strafesnet/go-grpc/maps"
@ -37,6 +38,14 @@ var (
ErrActiveSubmissionSameTargetAssetID = errors.New("There is an active submission with the same TargetAssetID") ErrActiveSubmissionSameTargetAssetID = errors.New("There is an active submission with the same TargetAssetID")
ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released") ErrReleaseInvalidStatus = errors.New("Only submissions with Uploaded status can be released")
ErrReleaseNoTargetAssetID = errors.New("Only submissions with a TargetAssetID can be released") ErrReleaseNoTargetAssetID = errors.New("Only submissions with a TargetAssetID can be released")
ErrAcceptOwnSubmission = fmt.Errorf("%w: You cannot accept your own submission as the submitter", ErrPermissionDenied)
ErrDelayReset = errors.New("Please give the validator at least 10 seconds to operate before attempting to reset the status")
ErrPermissionDeniedNotSubmitter = fmt.Errorf("%w: You must be the submitter to perform this action", ErrPermissionDenied)
ErrPermissionDeniedNeedSubmissionPublish = fmt.Errorf("%w: Need Role SubmissionPublish", ErrPermissionDenied)
ErrPermissionDeniedNeedRoleSubmissionReview = fmt.Errorf("%w: Need Role SubmissionReview", ErrPermissionDenied)
ErrPermissionDeniedNeedRoleMapDownload = fmt.Errorf("%w: Need Role MapDownload", ErrPermissionDenied)
ErrPermissionDeniedNeedRoleScriptWrite = fmt.Errorf("%w: Need Role ScriptWrite", ErrPermissionDenied)
ErrPermissionDeniedNeedRoleMaptest = fmt.Errorf("%w: Need Role Maptest", ErrPermissionDenied)
) )
// POST /submissions // POST /submissions
@ -216,7 +225,7 @@ func (svc *Service) SetSubmissionCompleted(ctx context.Context, params api.SetSu
} }
// check if caller has MaptestGame role (request must originate from a maptest roblox game) // check if caller has MaptestGame role (request must originate from a maptest roblox game)
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedRoleMaptest
} }
pmap := datastore.Optional() pmap := datastore.Optional()
@ -247,7 +256,7 @@ func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.Update
} }
// check if caller is the submitter // check if caller is the submitter
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNotSubmitter
} }
// check if Status is ChangesRequested|Submitted|UnderConstruction // check if Status is ChangesRequested|Submitted|UnderConstruction
@ -276,7 +285,7 @@ func (svc *Service) ActionSubmissionReject(ctx context.Context, params api.Actio
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedRoleSubmissionReview
} }
// transaction // transaction
@ -302,7 +311,7 @@ func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params a
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedRoleSubmissionReview
} }
// transaction // transaction
@ -334,7 +343,7 @@ func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.Actio
} }
// check if caller is the submitter // check if caller is the submitter
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNotSubmitter
} }
// transaction // transaction
@ -366,7 +375,7 @@ func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.Actio
} }
// check if caller is the submitter // check if caller is the submitter
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNotSubmitter
} }
// transaction // transaction
@ -392,7 +401,7 @@ func (svc *Service) ActionSubmissionTriggerUpload(ctx context.Context, params ap
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedSubmissionPublish
} }
// transaction // transaction
@ -457,7 +466,7 @@ func (svc *Service) ActionSubmissionValidated(ctx context.Context, params api.Ac
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedSubmissionPublish
} }
// check when submission was updated // check when submission was updated
@ -467,7 +476,7 @@ func (svc *Service) ActionSubmissionValidated(ctx context.Context, params api.Ac
} }
if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) { if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) {
// the last time the submission was updated must be longer than 10 seconds ago // the last time the submission was updated must be longer than 10 seconds ago
return ErrPermissionDenied return ErrDelayReset
} }
// transaction // transaction
@ -493,7 +502,7 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedRoleSubmissionReview
} }
// read submission (this could be done with a transaction WHERE clause) // read submission (this could be done with a transaction WHERE clause)
@ -508,7 +517,7 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params
} }
// check if caller is NOT the submitter // check if caller is NOT the submitter
if has_role { if has_role {
return ErrPermissionDenied return ErrAcceptOwnSubmission
} }
// transaction // transaction
@ -553,7 +562,7 @@ func (svc *Service) ActionSubmissionAccepted(ctx context.Context, params api.Act
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedRoleSubmissionReview
} }
// check when submission was updated // check when submission was updated
@ -563,7 +572,7 @@ func (svc *Service) ActionSubmissionAccepted(ctx context.Context, params api.Act
} }
if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) { if time.Now().Before(submission.UpdatedAt.Add(time.Second*10)) {
// the last time the submission was updated must be longer than 10 seconds ago // the last time the submission was updated must be longer than 10 seconds ago
return ErrPermissionDenied return ErrDelayReset
} }
// transaction // transaction
@ -590,7 +599,7 @@ func (svc *Service) ReleaseSubmissions(ctx context.Context, request []api.Releas
} }
// check if caller has required role // check if caller has required role
if !has_role { if !has_role {
return ErrPermissionDenied return ErrPermissionDeniedNeedSubmissionPublish
} }
idList := make([]int64, len(request)) idList := make([]int64, len(request))