submissions: limit active submissions to 20
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8bf2c92df3
commit
07ef22bc02
@ -9,6 +9,10 @@ import (
|
|||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
ActiveSubmissionsLimit = 20
|
||||||
|
)
|
||||||
|
|
||||||
// POST /submissions
|
// POST /submissions
|
||||||
func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) {
|
func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) {
|
||||||
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
||||||
@ -21,6 +25,21 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
|
|||||||
return nil, err
|
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{
|
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
DisplayName: request.DisplayName,
|
DisplayName: request.DisplayName,
|
||||||
|
Loading…
Reference in New Issue
Block a user