diff --git a/pkg/cmds/serve.go b/pkg/cmds/serve.go index 5003cc6..b59f6bb 100644 --- a/pkg/cmds/serve.go +++ b/pkg/cmds/serve.go @@ -2,16 +2,16 @@ package cmds import ( "fmt" + "git.itzana.me/strafesnet/go-grpc/auth" "git.itzana.me/strafesnet/maps-service/pkg/api" "git.itzana.me/strafesnet/maps-service/pkg/datastore/gormstore" "git.itzana.me/strafesnet/maps-service/pkg/service" + "github.com/nats-io/nats.go" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "net/http" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "git.itzana.me/strafesnet/go-grpc/auth" - "github.com/nats-io/nats.go" + "net/http" ) func NewServeCommand() *cli.Command { @@ -93,8 +93,8 @@ func serve(ctx *cli.Context) error { } _, err = js.AddStream(&nats.StreamConfig{ - Name:"maptest", - Subjects: []string{"maptest.>"}, + Name: "maptest", + Subjects: []string{"maptest.>"}, Retention: nats.WorkQueuePolicy, }) if err != nil { @@ -102,7 +102,7 @@ func serve(ctx *cli.Context) error { } svc := &service.Service{ - DB: db, + DB: db, Nats: js, } diff --git a/pkg/datastore/datastore.go b/pkg/datastore/datastore.go index 52a1ee5..89c0b07 100644 --- a/pkg/datastore/datastore.go +++ b/pkg/datastore/datastore.go @@ -7,7 +7,7 @@ import ( ) var ( - ErrNotExist = errors.New("resource does not exist") + ErrNotExist = errors.New("resource does not exist") ErroNoRowsAffected = errors.New("query did not affect any rows") ) diff --git a/pkg/datastore/gormstore/scripts.go b/pkg/datastore/gormstore/scripts.go index 135c3de..d792f3c 100644 --- a/pkg/datastore/gormstore/scripts.go +++ b/pkg/datastore/gormstore/scripts.go @@ -53,7 +53,7 @@ func (env *Scripts) Update(ctx context.Context, id int64, values datastore.Optio // the update can only occur if the status matches one of the provided values. func (env *Scripts) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.Status, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Script{}).Where("id = ?", id).Where("status IN ?",statuses).Updates(values.Map()).Error; err != nil { + if err := env.db.Model(&model.Script{}).Where("id = ?", id).Where("status IN ?", statuses).Updates(values.Map()).Error; err != nil { if err == gorm.ErrRecordNotFound { return datastore.ErrNotExist } diff --git a/pkg/datastore/gormstore/submissions.go b/pkg/datastore/gormstore/submissions.go index 43893bb..7e71c60 100644 --- a/pkg/datastore/gormstore/submissions.go +++ b/pkg/datastore/gormstore/submissions.go @@ -54,7 +54,7 @@ func (env *Submissions) Update(ctx context.Context, id int64, values datastore.O // the update can only occur if the status matches one of the provided values. func (env *Submissions) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.Status, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?",statuses).Updates(values.Map()).Error; err != nil { + if err := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil { if err == gorm.ErrRecordNotFound { return datastore.ErrNotExist } @@ -71,7 +71,7 @@ func (env *Submissions) IfStatusThenUpdateAndGet(ctx context.Context, id int64, result := env.db.Model(&submission). Clauses(clause.Returning{}). Where("id = ?", id). - Where("status_id IN ?",statuses). + Where("status_id IN ?", statuses). Updates(values.Map()) if result.Error != nil { if result.Error == gorm.ErrRecordNotFound { diff --git a/pkg/model/nats.go b/pkg/model/nats.go index e16416c..f9e13fc 100644 --- a/pkg/model/nats.go +++ b/pkg/model/nats.go @@ -5,7 +5,7 @@ package model // Requests are sent from maps-service to validator -type ValidateRequest struct{ +type ValidateRequest struct { // submission_id is passed back in the response message SubmissionID int64 ModelID uint64 @@ -14,7 +14,7 @@ type ValidateRequest struct{ } // Create a new map -type PublishNewRequest struct{ +type PublishNewRequest struct { SubmissionID int64 ModelID uint64 ModelVersion uint64 @@ -24,7 +24,7 @@ type PublishNewRequest struct{ //games HashSet } -type PublishFixRequest struct{ +type PublishFixRequest struct { SubmissionID int64 ModelID uint64 ModelVersion uint64 diff --git a/pkg/model/policy.go b/pkg/model/policy.go index c1ff56e..6df5bf6 100644 --- a/pkg/model/policy.go +++ b/pkg/model/policy.go @@ -4,15 +4,15 @@ import "time" type Policy int32 -const( - ScriptPolicyAllowed Policy=0 - ScriptPolicyBlocked Policy=1 - ScriptPolicyDelete Policy=2 - ScriptPolicyReplace Policy=3 +const ( + ScriptPolicyAllowed Policy = 0 + ScriptPolicyBlocked Policy = 1 + ScriptPolicyDelete Policy = 2 + ScriptPolicyReplace Policy = 3 ) type ScriptPolicy struct { - ID int64 `gorm:"primaryKey"` + ID int64 `gorm:"primaryKey"` // Hash of the source code that leads to this policy. // If this is a replacement mapping, the original source may not be pointed to by any policy. // The original source should still exist in the scripts table, which can be located by the same hash. @@ -20,8 +20,8 @@ type ScriptPolicy struct { // The ID of the replacement source (ScriptPolicyReplace) // or verbatim source (ScriptPolicyAllowed) // or 0 (other) - ToScriptID int64 - Policy Policy - CreatedAt time.Time - UpdatedAt time.Time + ToScriptID int64 + Policy Policy + CreatedAt time.Time + UpdatedAt time.Time } diff --git a/pkg/model/script.go b/pkg/model/script.go index f9a088b..1383cf4 100644 --- a/pkg/model/script.go +++ b/pkg/model/script.go @@ -3,10 +3,10 @@ package model import "time" type Script struct { - ID int64 `gorm:"primaryKey"` - Hash uint64 - Source string - SubmissionID int64 // which submission did this script first appear in - CreatedAt time.Time - UpdatedAt time.Time + ID int64 `gorm:"primaryKey"` + Hash uint64 + Source string + SubmissionID int64 // which submission did this script first appear in + CreatedAt time.Time + UpdatedAt time.Time } diff --git a/pkg/model/submission.go b/pkg/model/submission.go index ed08173..cb68897 100644 --- a/pkg/model/submission.go +++ b/pkg/model/submission.go @@ -4,31 +4,31 @@ import "time" type Status int32 -const( - StatusPublished Status=8 - StatusRejected Status=7 +const ( + StatusPublished Status = 8 + StatusRejected Status = 7 - StatusPublishing Status=6 - StatusValidated Status=5 - StatusValidating Status=4 - StatusAccepted Status=3 + StatusPublishing Status = 6 + StatusValidated Status = 5 + StatusValidating Status = 4 + StatusAccepted Status = 3 - StatusChangesRequested Status=2 - StatusSubmitted Status=1 - StatusUnderConstruction Status=0 + StatusChangesRequested Status = 2 + StatusSubmitted Status = 1 + StatusUnderConstruction Status = 0 ) type Submission struct { - ID int64 `gorm:"primaryKey"` - DisplayName string - Creator string - GameID int32 - CreatedAt time.Time - UpdatedAt time.Time - Submitter uint64 // UserID - AssetID uint64 - AssetVersion uint64 - Completed bool // Has this version of the map been completed at least once on maptest - TargetAssetID uint64 // where to upload map fix. if the TargetAssetID is 0, it's a new map. - StatusID Status + ID int64 `gorm:"primaryKey"` + DisplayName string + Creator string + GameID int32 + CreatedAt time.Time + UpdatedAt time.Time + Submitter uint64 // UserID + AssetID uint64 + AssetVersion uint64 + Completed bool // Has this version of the map been completed at least once on maptest + TargetAssetID uint64 // where to upload map fix. if the TargetAssetID is 0, it's a new map. + StatusID Status } diff --git a/pkg/service/script_policy.go b/pkg/service/script_policy.go index 0908aae..170d420 100644 --- a/pkg/service/script_policy.go +++ b/pkg/service/script_policy.go @@ -15,18 +15,18 @@ import ( // Create a new script policy. // // POST /script-policy -func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ID, error){ +func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ID, error) { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return nil, ErrPermissionDenied } - from_script, err := svc.DB.Scripts().Get(ctx,req.FromScriptID) - if err != nil{ + from_script, err := svc.DB.Scripts().Get(ctx, req.FromScriptID) + if err != nil { return nil, err } @@ -38,64 +38,67 @@ func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolic ToScriptID: req.ToScriptID, Policy: model.Policy(req.Policy), }) - if err != nil{ + if err != nil { return nil, err } return &api.ID{ - ID:script.ID, + ID: script.ID, }, nil } + // DeleteScriptPolicy implements deleteScriptPolicy operation. // // Delete the specified script policy by ID. // // DELETE /script-policy/id/{ScriptPolicyID} -func (svc *Service) DeleteScriptPolicy(ctx context.Context, params api.DeleteScriptPolicyParams) error{ +func (svc *Service) DeleteScriptPolicy(ctx context.Context, params api.DeleteScriptPolicyParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return ErrPermissionDenied } return svc.DB.ScriptPolicy().Delete(ctx, params.ScriptPolicyID) } + // GetScriptPolicy implements getScriptPolicy operation. // // Get the specified script policy by ID. // // GET /script-policy/id/{ScriptPolicyID} -func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPolicyParams) (*api.ScriptPolicy, error){ +func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPolicyParams) (*api.ScriptPolicy, error) { _, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } // Read permission for script policy only requires you to be logged in policy, err := svc.DB.ScriptPolicy().Get(ctx, params.ScriptPolicyID) - if err != nil{ + if err != nil { return nil, err } return &api.ScriptPolicy{ ID: policy.ID, - FromScriptHash: fmt.Sprintf("%x",policy.FromScriptHash), + FromScriptHash: fmt.Sprintf("%x", policy.FromScriptHash), ToScriptID: policy.ToScriptID, Policy: int32(policy.Policy), }, nil } + // GetScriptPolicyFromHash implements getScriptPolicyFromHash operation. // // Get the policy for the given hash of script source code. // // GET /script-policy/hash/{FromScriptHash} -func (svc *Service) GetScriptPolicyFromHash(ctx context.Context, params api.GetScriptPolicyFromHashParams) (*api.ScriptPolicy, error){ +func (svc *Service) GetScriptPolicyFromHash(ctx context.Context, params api.GetScriptPolicyFromHashParams) (*api.ScriptPolicy, error) { _, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } @@ -103,50 +106,51 @@ func (svc *Service) GetScriptPolicyFromHash(ctx context.Context, params api.GetS // parse hash from hex hash, err := strconv.ParseUint(params.FromScriptHash, 16, 64) - if err != nil{ + if err != nil { return nil, err } policy, err := svc.DB.ScriptPolicy().GetFromHash(ctx, hash) - if err != nil{ + if err != nil { return nil, err } return &api.ScriptPolicy{ ID: policy.ID, - FromScriptHash: fmt.Sprintf("%x",policy.FromScriptHash), + FromScriptHash: fmt.Sprintf("%x", policy.FromScriptHash), ToScriptID: policy.ToScriptID, Policy: int32(policy.Policy), }, nil } + // UpdateScriptPolicy implements updateScriptPolicy operation. // // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} -func (svc *Service) UpdateScriptPolicy(ctx context.Context, req *api.ScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error{ +func (svc *Service) UpdateScriptPolicy(ctx context.Context, req *api.ScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return ErrPermissionDenied } pmap := datastore.Optional() - if from_script_id,ok:=req.FromScriptID.Get();ok{ - from_script, err := svc.DB.Scripts().Get(ctx,from_script_id) - if err != nil{ + if from_script_id, ok := req.FromScriptID.Get(); ok { + from_script, err := svc.DB.Scripts().Get(ctx, from_script_id) + if err != nil { return err } - pmap.Add("from_script_hash",from_script.Hash) + pmap.Add("from_script_hash", from_script.Hash) } - if to_script_id,ok:=req.ToScriptID.Get();ok{ - pmap.Add("to_script_id",to_script_id) + if to_script_id, ok := req.ToScriptID.Get(); ok { + pmap.Add("to_script_id", to_script_id) } - if policy,ok:=req.Policy.Get();ok{ - pmap.Add("policy",policy) + if policy, ok := req.Policy.Get(); ok { + pmap.Add("policy", policy) } return svc.DB.ScriptPolicy().Update(ctx, req.ID, pmap) } diff --git a/pkg/service/scripts.go b/pkg/service/scripts.go index 7877219..185866d 100644 --- a/pkg/service/scripts.go +++ b/pkg/service/scripts.go @@ -15,94 +15,97 @@ import ( // Create a new script. // // POST /scripts -func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ID, error){ +func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ID, error) { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return nil, ErrPermissionDenied } script, err := svc.DB.Scripts().Create(ctx, model.Script{ ID: 0, - Hash: siphash.Hash(0,0,[]byte(req.Source)), + Hash: siphash.Hash(0, 0, []byte(req.Source)), Source: req.Source, SubmissionID: req.SubmissionID.Or(0), }) - if err != nil{ + if err != nil { return nil, err } return &api.ID{ - ID:script.ID, + ID: script.ID, }, nil } + // DeleteScript implements deleteScript operation. // // Delete the specified script by ID. // // DELETE /scripts/{ScriptID} -func (svc *Service) DeleteScript(ctx context.Context, params api.DeleteScriptParams) error{ +func (svc *Service) DeleteScript(ctx context.Context, params api.DeleteScriptParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return ErrPermissionDenied } return svc.DB.Scripts().Delete(ctx, params.ScriptID) } + // GetScript implements getScript operation. // // Get the specified script by ID. // // GET /scripts/{ScriptID} -func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error){ +func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error) { _, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } // Read permission for scripts only requires you to be logged in script, err := svc.DB.Scripts().Get(ctx, params.ScriptID) - if err != nil{ + if err != nil { return nil, err } return &api.Script{ ID: script.ID, - Hash: fmt.Sprintf("%x",script.Hash), + Hash: fmt.Sprintf("%x", script.Hash), Source: script.Source, SubmissionID: script.SubmissionID, }, nil } + // UpdateScript implements updateScript operation. // // Update the specified script by ID. // // PATCH /scripts/{ScriptID} -func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, params api.UpdateScriptParams) error{ +func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, params api.UpdateScriptParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } - if !userInfo.Roles.ScriptWrite{ + if !userInfo.Roles.ScriptWrite { return ErrPermissionDenied } pmap := datastore.Optional() - if source,ok:=req.Source.Get();ok{ - pmap.Add("source",source) - pmap.Add("hash",siphash.Hash(0,0,[]byte(source))) + if source, ok := req.Source.Get(); ok { + pmap.Add("source", source) + pmap.Add("hash", siphash.Hash(0, 0, []byte(source))) } - if SubmissionID,ok:=req.SubmissionID.Get();ok{ - pmap.Add("submission_id",SubmissionID) + if SubmissionID, ok := req.SubmissionID.Get(); ok { + pmap.Add("submission_id", SubmissionID) } return svc.DB.Scripts().Update(ctx, req.ID, pmap) } diff --git a/pkg/service/security.go b/pkg/service/security.go index 1cf09ca..57016d4 100644 --- a/pkg/service/security.go +++ b/pkg/service/security.go @@ -1,10 +1,10 @@ package service import ( - "errors" "context" - "git.itzana.me/strafesnet/maps-service/pkg/api" + "errors" "git.itzana.me/strafesnet/go-grpc/auth" + "git.itzana.me/strafesnet/maps-service/pkg/api" ) var ( @@ -16,7 +16,7 @@ var ( var ( // has SubmissionPublish - RoleMapAdmin int32 = 128 + RoleMapAdmin int32 = 128 // has SubmissionReview RoleMapCouncil int32 = 64 ) @@ -24,19 +24,19 @@ var ( type Roles struct { // human roles SubmissionPublish bool - SubmissionReview bool - ScriptWrite bool + SubmissionReview bool + ScriptWrite bool // automated roles - Maptest bool + Maptest bool Validator bool } type UserInfo struct { - Roles Roles + Roles Roles UserID uint64 } -func (usr UserInfo) IsSubmitter(submitter uint64) bool{ +func (usr UserInfo) IsSubmitter(submitter uint64) bool { return usr.UserID == submitter } @@ -44,7 +44,7 @@ type SecurityHandler struct { Client auth.AuthServiceClient } -func (svc SecurityHandler) HandleCookieAuth(ctx context.Context, operationName api.OperationName, t api.CookieAuth) (context.Context, error){ +func (svc SecurityHandler) HandleCookieAuth(ctx context.Context, operationName api.OperationName, t api.CookieAuth) (context.Context, error) { sessionId := t.GetAPIKey() if sessionId == "" { return nil, ErrMissingSessionID @@ -53,41 +53,41 @@ func (svc SecurityHandler) HandleCookieAuth(ctx context.Context, operationName a session, err := svc.Client.GetSessionUser(ctx, &auth.IdMessage{ SessionID: sessionId, }) - if err != nil{ + if err != nil { return nil, err } role, err := svc.Client.GetGroupRole(ctx, &auth.IdMessage{ SessionID: sessionId, }) - if err != nil{ + if err != nil { return nil, err } validate, err := svc.Client.ValidateSession(ctx, &auth.IdMessage{ SessionID: sessionId, }) - if err != nil{ + if err != nil { return nil, err } - if !validate.Valid{ + if !validate.Valid { return nil, ErrInvalidSession } roles := Roles{} // fix this when roblox udpates group roles - for _,r := range role.Roles{ - if RoleMapAdmin<=r.Rank{ + for _, r := range role.Roles { + if RoleMapAdmin <= r.Rank { roles.SubmissionPublish = true } - if RoleMapCouncil<=r.Rank{ + if RoleMapCouncil <= r.Rank { roles.SubmissionReview = true } } newCtx := context.WithValue(ctx, "UserInfo", UserInfo{ - Roles: roles, + Roles: roles, UserID: session.UserID, }) diff --git a/pkg/service/service.go b/pkg/service/service.go index c632969..72abde2 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -16,7 +16,7 @@ var ( ) type Service struct { - DB datastore.Datastore + DB datastore.Datastore Nats nats.JetStreamContext } @@ -25,16 +25,16 @@ type Service struct { // Used for common default response. func (svc *Service) NewError(ctx context.Context, err error) *api.ErrorStatusCode { status := 500 - if errors.Is(err,ErrPermissionDenied){ + if errors.Is(err, ErrPermissionDenied) { status = 403 } - if errors.Is(err,ErrUserInfo){ + if errors.Is(err, ErrUserInfo) { status = 401 } return &api.ErrorStatusCode{ StatusCode: status, - Response: api.Error{ - Code: int64(status), + Response: api.Error{ + Code: int64(status), Message: err.Error(), }, } diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index ac529d6..3a6deb4 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -9,11 +9,10 @@ import ( "git.itzana.me/strafesnet/maps-service/pkg/model" ) - // POST /submissions func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return nil, ErrUserInfo } @@ -29,11 +28,11 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio TargetAssetID: uint64(request.TargetAssetID.Value), StatusID: model.StatusUnderConstruction, }) - if err != nil{ + if err != nil { return nil, err } return &api.ID{ - ID:submission.ID, + ID: submission.ID, }, nil } @@ -44,22 +43,22 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio // GET /submissions/{SubmissionID} func (svc *Service) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) { submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID) - if err != nil{ + if err != nil { return nil, err } return &api.Submission{ - ID: submission.ID, - DisplayName: submission.DisplayName, - Creator: submission.Creator, - GameID: submission.GameID, - CreatedAt: submission.CreatedAt.Unix(), - UpdatedAt: submission.UpdatedAt.Unix(), - Submitter: int64(submission.Submitter), - AssetID: int64(submission.AssetID), - AssetVersion: int64(submission.AssetVersion), - Completed: submission.Completed, - TargetAssetID: api.NewOptInt64(int64(submission.TargetAssetID)), - StatusID: int32(submission.StatusID), + ID: submission.ID, + DisplayName: submission.DisplayName, + Creator: submission.Creator, + GameID: submission.GameID, + CreatedAt: submission.CreatedAt.Unix(), + UpdatedAt: submission.UpdatedAt.Unix(), + Submitter: int64(submission.Submitter), + AssetID: int64(submission.AssetID), + AssetVersion: int64(submission.AssetVersion), + Completed: submission.Completed, + TargetAssetID: api.NewOptInt64(int64(submission.TargetAssetID)), + StatusID: int32(submission.StatusID), }, nil } @@ -81,25 +80,25 @@ func (svc *Service) ListSubmissions(ctx context.Context, request api.ListSubmiss Number: request.Page.GetPage(), Size: request.Page.GetLimit(), }) - if err != nil{ + if err != nil { return nil, err } var resp []api.Submission for i := 0; i < len(items); i++ { resp = append(resp, api.Submission{ - ID: items[i].ID, - DisplayName: items[i].DisplayName, - Creator: items[i].Creator, - GameID: items[i].GameID, - CreatedAt: items[i].CreatedAt.Unix(), - UpdatedAt: items[i].UpdatedAt.Unix(), - Submitter: int64(items[i].Submitter), - AssetID: int64(items[i].AssetID), - AssetVersion: int64(items[i].AssetVersion), - Completed: items[i].Completed, - TargetAssetID: api.NewOptInt64(int64(items[i].TargetAssetID)), - StatusID: int32(items[i].StatusID), + ID: items[i].ID, + DisplayName: items[i].DisplayName, + Creator: items[i].Creator, + GameID: items[i].GameID, + CreatedAt: items[i].CreatedAt.Unix(), + UpdatedAt: items[i].UpdatedAt.Unix(), + Submitter: int64(items[i].Submitter), + AssetID: int64(items[i].AssetID), + AssetVersion: int64(items[i].AssetVersion), + Completed: items[i].Completed, + TargetAssetID: api.NewOptInt64(int64(items[i].TargetAssetID)), + StatusID: int32(items[i].StatusID), }) } @@ -113,12 +112,12 @@ func (svc *Service) ListSubmissions(ctx context.Context, request api.ListSubmiss // POST /submissions/{SubmissionID}/completed func (svc *Service) SetSubmissionCompleted(ctx context.Context, params api.SetSubmissionCompletedParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // check if caller has MaptestGame role (request must originate from a maptest roblox game) - if !userInfo.Roles.Maptest{ + if !userInfo.Roles.Maptest { return ErrPermissionDenied } @@ -135,18 +134,18 @@ func (svc *Service) SetSubmissionCompleted(ctx context.Context, params api.SetSu // POST /submissions/{SubmissionID}/model func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.UpdateSubmissionModelParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // read submission (this could be done with a transaction WHERE clause) submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID) - if err != nil{ + if err != nil { return err } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter){ + if !userInfo.IsSubmitter(submission.Submitter) { return ErrPermissionDenied } @@ -155,8 +154,8 @@ func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.Update pmap.AddNotNil("asset_id", params.ModelID) pmap.AddNotNil("asset_version", params.VersionID) //always reset completed when model changes - pmap.Add("completed",false) - return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusChangesRequested,model.StatusSubmitted,model.StatusUnderConstruction}, pmap) + pmap.Add("completed", false) + return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusChangesRequested, model.StatusSubmitted, model.StatusUnderConstruction}, pmap) } // ActionSubmissionPublish invokes actionSubmissionPublish operation. @@ -169,9 +168,10 @@ func (svc *Service) ActionSubmissionPublish(ctx context.Context, params api.Acti // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusPublished) + smap.Add("status_id", model.StatusPublished) return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusPublishing}, smap) } + // ActionSubmissionReject invokes actionSubmissionReject operation. // // Role Reviewer changes status from Submitted -> Rejected. @@ -179,20 +179,21 @@ func (svc *Service) ActionSubmissionPublish(ctx context.Context, params api.Acti // POST /submissions/{SubmissionID}/status/reject func (svc *Service) ActionSubmissionReject(ctx context.Context, params api.ActionSubmissionRejectParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // check if caller has required role - if !userInfo.Roles.SubmissionReview{ + if !userInfo.Roles.SubmissionReview { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusRejected) + smap.Add("status_id", model.StatusRejected) return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted}, smap) } + // ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation. // // Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested. @@ -200,20 +201,21 @@ func (svc *Service) ActionSubmissionReject(ctx context.Context, params api.Actio // POST /submissions/{SubmissionID}/status/request-changes func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params api.ActionSubmissionRequestChangesParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // check if caller has required role - if !userInfo.Roles.SubmissionReview{ + if !userInfo.Roles.SubmissionReview { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusChangesRequested) - return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidated,model.StatusAccepted,model.StatusSubmitted}, smap) + smap.Add("status_id", model.StatusChangesRequested) + return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidated, model.StatusAccepted, model.StatusSubmitted}, smap) } + // ActionSubmissionRevoke invokes actionSubmissionRevoke operation. // // Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction. @@ -221,26 +223,27 @@ func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params a // POST /submissions/{SubmissionID}/status/revoke func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.ActionSubmissionRevokeParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // read submission (this could be done with a transaction WHERE clause) submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID) - if err != nil{ + if err != nil { return err } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter){ + if !userInfo.IsSubmitter(submission.Submitter) { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusUnderConstruction) - return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted,model.StatusChangesRequested}, smap) + smap.Add("status_id", model.StatusUnderConstruction) + return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted, model.StatusChangesRequested}, smap) } + // ActionSubmissionSubmit invokes actionSubmissionSubmit operation. // // Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted. @@ -248,26 +251,27 @@ func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.Actio // POST /submissions/{SubmissionID}/status/submit func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.ActionSubmissionSubmitParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // read submission (this could be done with a transaction WHERE clause) submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID) - if err != nil{ + if err != nil { return err } // check if caller is the submitter - if !userInfo.IsSubmitter(submission.Submitter){ + if !userInfo.IsSubmitter(submission.Submitter) { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusSubmitted) - return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusUnderConstruction,model.StatusChangesRequested}, smap) + smap.Add("status_id", model.StatusSubmitted) + return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusUnderConstruction, model.StatusChangesRequested}, smap) } + // ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation. // // Role Admin changes status from Validated -> Publishing. @@ -275,25 +279,25 @@ func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.Actio // POST /submissions/{SubmissionID}/status/trigger-publish func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params api.ActionSubmissionTriggerPublishParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // check if caller has required role - if !userInfo.Roles.SubmissionPublish{ + if !userInfo.Roles.SubmissionPublish { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusPublishing) + smap.Add("status_id", model.StatusPublishing) submission, err := svc.DB.Submissions().IfStatusThenUpdateAndGet(ctx, params.SubmissionID, []model.Status{model.StatusValidated}, smap) - if err != nil{ + if err != nil { return err } // sentinel value because we are not using rust - if submission.TargetAssetID == 0{ + if submission.TargetAssetID == 0 { // this is a new map publish_new_request := model.PublishNewRequest{ SubmissionID: submission.ID, @@ -305,12 +309,12 @@ func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params a } j, err := json.Marshal(publish_new_request) - if err != nil{ + if err != nil { return err } svc.Nats.Publish("maptest.submissions.publish.new", []byte(j)) - }else{ + } else { // this is a map fix publish_fix_request := model.PublishFixRequest{ SubmissionID: submission.ID, @@ -320,7 +324,7 @@ func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params a } j, err := json.Marshal(publish_fix_request) - if err != nil{ + if err != nil { return err } @@ -329,6 +333,7 @@ func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params a return nil } + // ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation. // // Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating. @@ -336,20 +341,20 @@ func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params a // POST /submissions/{SubmissionID}/status/trigger-validate func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params api.ActionSubmissionTriggerValidateParams) error { userInfo, ok := ctx.Value("UserInfo").(UserInfo) - if !ok{ + if !ok { return ErrUserInfo } // check if caller has required role - if !userInfo.Roles.SubmissionReview{ + if !userInfo.Roles.SubmissionReview { return ErrPermissionDenied } // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusValidating) - submission, err := svc.DB.Submissions().IfStatusThenUpdateAndGet(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted,model.StatusAccepted}, smap) - if err != nil{ + smap.Add("status_id", model.StatusValidating) + submission, err := svc.DB.Submissions().IfStatusThenUpdateAndGet(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted, model.StatusAccepted}, smap) + if err != nil { return err } @@ -361,7 +366,7 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params } j, err := json.Marshal(validate_request) - if err != nil{ + if err != nil { return err } @@ -369,6 +374,7 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params return nil } + // ActionSubmissionValidate invokes actionSubmissionValidate operation. // // Role Validator changes status from Validating -> Validated. @@ -379,6 +385,6 @@ func (svc *Service) ActionSubmissionValidate(ctx context.Context, params api.Act // transaction smap := datastore.Optional() - smap.Add("status_id",model.StatusValidated) + smap.Add("status_id", model.StatusValidated) return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidating}, smap) }