2024-11-26 23:30:58 +00:00
|
|
|
package service
|
2024-11-26 23:28:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-11-29 23:52:44 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2024-11-26 23:28:48 +00:00
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
2024-11-28 00:38:22 +00:00
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
2024-11-29 23:52:44 +00:00
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
2024-11-26 23:28:48 +00:00
|
|
|
)
|
|
|
|
|
2024-11-28 02:19:19 +00:00
|
|
|
|
2024-11-26 23:28:48 +00:00
|
|
|
// POST /submissions
|
2024-12-06 02:48:26 +00:00
|
|
|
func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return nil, ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-27 23:38:17 +00:00
|
|
|
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
|
|
|
|
ID: 0,
|
2024-12-06 02:48:26 +00:00
|
|
|
DisplayName: request.DisplayName,
|
|
|
|
Creator: request.Creator,
|
|
|
|
GameID: request.GameID,
|
2024-12-11 03:18:04 +00:00
|
|
|
Submitter: userInfo.UserID,
|
|
|
|
AssetID: uint64(request.AssetID),
|
|
|
|
AssetVersion: uint64(request.AssetVersion),
|
2024-11-27 23:38:17 +00:00
|
|
|
Completed: false,
|
2024-12-11 03:18:04 +00:00
|
|
|
TargetAssetID: uint64(request.TargetAssetID.Value),
|
2024-11-28 01:59:29 +00:00
|
|
|
StatusID: model.StatusUnderConstruction,
|
2024-11-27 23:38:17 +00:00
|
|
|
})
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &api.ID{
|
2024-12-06 00:41:06 +00:00
|
|
|
ID:submission.ID,
|
2024-11-27 23:38:17 +00:00
|
|
|
}, nil
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubmission implements getSubmission operation.
|
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
|
|
|
// GET /submissions/{SubmissionID}
|
2024-11-26 23:30:58 +00:00
|
|
|
func (svc *Service) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) {
|
2024-11-26 23:55:56 +00:00
|
|
|
submission, err := svc.DB.Submissions().Get(ctx, params.SubmissionID)
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &api.Submission{
|
2024-12-06 00:41:06 +00:00
|
|
|
ID: submission.ID,
|
|
|
|
DisplayName: submission.DisplayName,
|
|
|
|
Creator: submission.Creator,
|
|
|
|
GameID: submission.GameID,
|
2024-12-10 06:27:52 +00:00
|
|
|
CreatedAt: submission.CreatedAt.Unix(),
|
|
|
|
UpdatedAt: submission.UpdatedAt.Unix(),
|
2024-12-11 03:18:04 +00:00
|
|
|
Submitter: int64(submission.Submitter),
|
|
|
|
AssetID: int64(submission.AssetID),
|
|
|
|
AssetVersion: int64(submission.AssetVersion),
|
2024-12-06 00:41:06 +00:00
|
|
|
Completed: submission.Completed,
|
2024-12-11 03:18:04 +00:00
|
|
|
TargetAssetID: api.NewOptInt64(int64(submission.TargetAssetID)),
|
2024-12-06 00:41:06 +00:00
|
|
|
StatusID: int32(submission.StatusID),
|
2024-11-26 23:55:56 +00:00
|
|
|
}, nil
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSubmissions implements listSubmissions operation.
|
|
|
|
//
|
|
|
|
// Get list of submissions.
|
|
|
|
//
|
|
|
|
// GET /submissions
|
2024-11-28 00:38:22 +00:00
|
|
|
func (svc *Service) ListSubmissions(ctx context.Context, request api.ListSubmissionsParams) ([]api.Submission, error) {
|
|
|
|
filter := datastore.Optional()
|
|
|
|
//fmt.Println(request)
|
|
|
|
if request.Filter.IsSet() {
|
|
|
|
filter.AddNotNil("display_name", request.Filter.Value.DisplayName)
|
|
|
|
filter.AddNotNil("creator", request.Filter.Value.Creator)
|
|
|
|
filter.AddNotNil("game_id", request.Filter.Value.GameID)
|
|
|
|
}
|
|
|
|
|
|
|
|
items, err := svc.DB.Submissions().List(ctx, filter, model.Page{
|
|
|
|
Number: request.Page.GetPage(),
|
|
|
|
Size: request.Page.GetLimit(),
|
|
|
|
})
|
|
|
|
if err != nil{
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp []api.Submission
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
resp = append(resp, api.Submission{
|
2024-12-06 00:41:06 +00:00
|
|
|
ID: items[i].ID,
|
|
|
|
DisplayName: items[i].DisplayName,
|
|
|
|
Creator: items[i].Creator,
|
|
|
|
GameID: items[i].GameID,
|
2024-12-10 06:27:52 +00:00
|
|
|
CreatedAt: items[i].CreatedAt.Unix(),
|
|
|
|
UpdatedAt: items[i].UpdatedAt.Unix(),
|
2024-12-11 03:18:04 +00:00
|
|
|
Submitter: int64(items[i].Submitter),
|
|
|
|
AssetID: int64(items[i].AssetID),
|
|
|
|
AssetVersion: int64(items[i].AssetVersion),
|
2024-12-06 00:41:06 +00:00
|
|
|
Completed: items[i].Completed,
|
2024-12-11 03:18:04 +00:00
|
|
|
TargetAssetID: api.NewOptInt64(int64(items[i].TargetAssetID)),
|
2024-12-06 00:41:06 +00:00
|
|
|
StatusID: int32(items[i].StatusID),
|
2024-11-28 00:38:22 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PatchSubmissionCompleted implements patchSubmissionCompleted operation.
|
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/completed
|
|
|
|
func (svc *Service) SetSubmissionCompleted(ctx context.Context, params api.SetSubmissionCompletedParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:27:40 +00:00
|
|
|
// check if caller has MaptestGame role (request must originate from a maptest roblox game)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !userInfo.Roles.Maptest{
|
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 00:44:50 +00:00
|
|
|
pmap := datastore.Optional()
|
2024-11-28 01:22:59 +00:00
|
|
|
pmap.Add("completed", true)
|
2024-11-28 00:44:50 +00:00
|
|
|
err := svc.DB.Submissions().Update(ctx, params.SubmissionID, pmap)
|
|
|
|
return err
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PatchSubmissionModel implements patchSubmissionModel operation.
|
|
|
|
//
|
|
|
|
// Update model following role restrictions.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/model
|
|
|
|
func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.UpdateSubmissionModelParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
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{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if caller is the submitter
|
|
|
|
if !userInfo.IsSubmitter(submission.Submitter){
|
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:27:40 +00:00
|
|
|
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
2024-11-28 00:44:50 +00:00
|
|
|
pmap := datastore.Optional()
|
|
|
|
pmap.AddNotNil("asset_id", params.ModelID)
|
|
|
|
pmap.AddNotNil("asset_version", params.VersionID)
|
2024-11-28 01:27:44 +00:00
|
|
|
//always reset completed when model changes
|
|
|
|
pmap.Add("completed",false)
|
2024-11-29 21:58:47 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusChangesRequested,model.StatusSubmitted,model.StatusUnderConstruction}, pmap)
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionPublish invokes actionSubmissionPublish operation.
|
2024-11-26 23:28:48 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Validator changes status from Publishing -> Published.
|
2024-11-26 23:28:48 +00:00
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/publish
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionPublish(ctx context.Context, params api.ActionSubmissionPublishParams) error {
|
2024-12-11 06:32:56 +00:00
|
|
|
println("[ActionSubmissionPublish] Implicit Validator permission granted!")
|
2024-11-29 21:58:47 +00:00
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusPublished)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusPublishing}, smap)
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionReject invokes actionSubmissionReject operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer changes status from Submitted -> Rejected.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/reject
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionReject(ctx context.Context, params api.ActionSubmissionRejectParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:19:19 +00:00
|
|
|
// check if caller has required role
|
2024-12-06 03:10:01 +00:00
|
|
|
if !userInfo.Roles.SubmissionReview{
|
2024-11-29 21:58:47 +00:00
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusRejected)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted}, smap)
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/request-changes
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params api.ActionSubmissionRequestChangesParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:19:19 +00:00
|
|
|
// check if caller has required role
|
2024-12-06 03:10:01 +00:00
|
|
|
if !userInfo.Roles.SubmissionReview{
|
2024-11-29 21:58:47 +00:00
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusChangesRequested)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidated,model.StatusAccepted,model.StatusSubmitted}, smap)
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionRevoke invokes actionSubmissionRevoke operation.
|
|
|
|
//
|
|
|
|
// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/revoke
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.ActionSubmissionRevokeParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
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{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if caller is the submitter
|
|
|
|
if !userInfo.IsSubmitter(submission.Submitter){
|
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusUnderConstruction)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted,model.StatusChangesRequested}, smap)
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionSubmit invokes actionSubmissionSubmit operation.
|
|
|
|
//
|
|
|
|
// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/submit
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.ActionSubmissionSubmitParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
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{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if caller is the submitter
|
|
|
|
if !userInfo.IsSubmitter(submission.Submitter){
|
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusSubmitted)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusUnderConstruction,model.StatusChangesRequested}, smap)
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation.
|
|
|
|
//
|
|
|
|
// Role Admin changes status from Validated -> Publishing.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-publish
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionTriggerPublish(ctx context.Context, params api.ActionSubmissionTriggerPublishParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:19:19 +00:00
|
|
|
// check if caller has required role
|
2024-12-06 03:10:01 +00:00
|
|
|
if !userInfo.Roles.SubmissionPublish{
|
2024-11-29 21:58:47 +00:00
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusPublishing)
|
2024-11-29 23:52:44 +00:00
|
|
|
submission, err := svc.DB.Submissions().IfStatusThenUpdateAndGet(ctx, params.SubmissionID, []model.Status{model.StatusValidated}, smap)
|
|
|
|
if err != nil{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// sentinel value because we are not using rust
|
|
|
|
if submission.TargetAssetID == 0{
|
|
|
|
// this is a new map
|
|
|
|
publish_new_request := model.PublishNewRequest{
|
|
|
|
SubmissionID: submission.ID,
|
|
|
|
ModelID: submission.AssetID,
|
|
|
|
ModelVersion: submission.AssetVersion,
|
|
|
|
Creator: submission.Creator,
|
|
|
|
DisplayName: submission.DisplayName,
|
2024-12-12 00:31:01 +00:00
|
|
|
GameID: uint32(submission.GameID),
|
2024-11-29 23:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
j, err := json.Marshal(publish_new_request)
|
|
|
|
if err != nil{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-12 05:07:51 +00:00
|
|
|
svc.Nats.Publish("maptest.submissions.publish.new", []byte(j))
|
2024-11-29 23:52:44 +00:00
|
|
|
}else{
|
|
|
|
// this is a map fix
|
|
|
|
publish_fix_request := model.PublishFixRequest{
|
|
|
|
SubmissionID: submission.ID,
|
|
|
|
ModelID: submission.AssetID,
|
|
|
|
ModelVersion: submission.AssetVersion,
|
|
|
|
TargetAssetID: submission.TargetAssetID,
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := json.Marshal(publish_fix_request)
|
|
|
|
if err != nil{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-12 05:07:51 +00:00
|
|
|
svc.Nats.Publish("maptest.submissions.publish.fix", []byte(j))
|
2024-11-29 23:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-validate
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params api.ActionSubmissionTriggerValidateParams) error {
|
2024-12-10 05:19:38 +00:00
|
|
|
userInfo, ok := ctx.Value("UserInfo").(UserInfo)
|
2024-11-29 21:58:47 +00:00
|
|
|
if !ok{
|
|
|
|
return ErrUserInfo
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:19:19 +00:00
|
|
|
// check if caller has required role
|
2024-12-06 03:10:01 +00:00
|
|
|
if !userInfo.Roles.SubmissionReview{
|
2024-11-29 21:58:47 +00:00
|
|
|
return ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusValidating)
|
2024-11-29 23:52:44 +00:00
|
|
|
submission, err := svc.DB.Submissions().IfStatusThenUpdateAndGet(ctx, params.SubmissionID, []model.Status{model.StatusSubmitted,model.StatusAccepted}, smap)
|
|
|
|
if err != nil{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_request := model.ValidateRequest{
|
|
|
|
SubmissionID: submission.ID,
|
|
|
|
ModelID: submission.AssetID,
|
|
|
|
ModelVersion: submission.AssetVersion,
|
|
|
|
ValidatedModelID: 0, //TODO: reuse velidation models
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := json.Marshal(validate_request)
|
|
|
|
if err != nil{
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-12 05:07:51 +00:00
|
|
|
svc.Nats.Publish("maptest.submissions.validate", []byte(j))
|
2024-11-29 23:52:44 +00:00
|
|
|
|
|
|
|
return nil
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
|
|
|
//
|
|
|
|
// Role Validator changes status from Validating -> Validated.
|
|
|
|
//
|
2024-12-10 06:09:52 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validate
|
2024-11-28 01:46:54 +00:00
|
|
|
func (svc *Service) ActionSubmissionValidate(ctx context.Context, params api.ActionSubmissionValidateParams) error {
|
2024-12-11 06:32:56 +00:00
|
|
|
println("[ActionSubmissionValidate] Implicit Validator permission granted!")
|
2024-11-29 21:58:47 +00:00
|
|
|
|
2024-11-28 02:57:42 +00:00
|
|
|
// transaction
|
2024-11-28 02:19:19 +00:00
|
|
|
smap := datastore.Optional()
|
|
|
|
smap.Add("status_id",model.StatusValidated)
|
2024-11-28 02:57:42 +00:00
|
|
|
return svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusValidating}, smap)
|
2024-11-26 23:28:48 +00:00
|
|
|
}
|