submissions: move pipeline restriction to accept rather than create

This commit is contained in:
Quaternions 2025-03-28 19:10:29 -07:00
parent 2c75cfa67f
commit f2d8c49647
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -20,6 +20,7 @@ var(
model.StatusSubmitted,
model.StatusUnderConstruction,
}
// prevent two mapfixes with same asset id
ActiveSubmissionStatuses = []model.Status{
model.StatusUploading,
model.StatusValidated,
@ -29,6 +30,13 @@ var(
model.StatusSubmitted,
model.StatusUnderConstruction,
}
// limit mapfixes in the pipeline to one per target map
ActiveAcceptedSubmissionStatuses = []model.Status{
model.StatusUploading,
model.StatusValidated,
model.StatusValidating,
model.StatusAccepted,
}
)
var (
@ -96,23 +104,6 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
}
}
// Check if an active submission with the same target asset id exists
if request.TargetAssetID.IsSet() && request.TargetAssetID.Value != 0{
filter := datastore.Optional()
filter.Add("target_asset_id", request.TargetAssetID.Value)
filter.Add("status_id", ActiveSubmissionStatuses)
active_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{
Number: 1,
Size: 1,
},model.SubmissionListSortDisabled)
if err != nil {
return nil, err
}
if len(active_submissions) != 0{
return nil, ErrActiveSubmissionSameTargetAssetID
}
}
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
ID: 0,
DisplayName: request.DisplayName,
@ -529,6 +520,23 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params
return ErrAcceptOwnSubmission
}
// Check if an active submission with the same target asset id exists
if submission.TargetAssetID != 0 {
filter := datastore.Optional()
filter.Add("target_asset_id", submission.TargetAssetID)
filter.Add("status_id", ActiveAcceptedSubmissionStatuses)
active_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{
Number: 1,
Size: 1,
},model.SubmissionListSortDisabled)
if err != nil {
return err
}
if len(active_submissions) != 0{
return ErrActiveSubmissionSameTargetAssetID
}
}
// transaction
smap := datastore.Optional()
smap.Add("status_id", model.StatusValidating)