From 07ef22bc02c49a479e38b7603709cdfa597fbdd3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 27 Dec 2024 17:42:29 -0800 Subject: [PATCH] submissions: limit active submissions to 20 --- pkg/service/submissions.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index e73809f..10be8cf 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -9,6 +9,10 @@ import ( "git.itzana.me/strafesnet/maps-service/pkg/model" ) +var( + ActiveSubmissionsLimit = 20 +) + // POST /submissions func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) { userInfo, ok := ctx.Value("UserInfo").(UserInfo) @@ -21,6 +25,21 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio return nil, err } + filter := datastore.Optional() + filter.Add("submitter", int64(userId)) + filter.Add("status_id", []model.Status{model.StatusChangesRequested, model.StatusSubmitted, model.StatusUnderConstruction}) + active_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{ + Number: 1, + Size: int32(ActiveSubmissionsLimit), + }) + if err != nil { + return nil, err + } + + if ActiveSubmissionsLimit <= len(active_submissions) { + return nil, ErrPermissionDenied + } + submission, err := svc.DB.Submissions().Create(ctx, model.Submission{ ID: 0, DisplayName: request.DisplayName,