submissions: postgres does not support unsigned integers, so let's pretend they are signed
This commit is contained in:
parent
b3ffbe4b50
commit
f04ab4f653
@ -8,22 +8,22 @@ package model
|
|||||||
type ValidateRequest struct {
|
type ValidateRequest struct {
|
||||||
// submission_id is passed back in the response message
|
// submission_id is passed back in the response message
|
||||||
SubmissionID int64
|
SubmissionID int64
|
||||||
ModelID uint64
|
ModelID int64
|
||||||
ModelVersion uint64
|
ModelVersion int64
|
||||||
ValidatedModelID uint64 // optional value
|
ValidatedModelID int64 // optional value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new map
|
// Create a new map
|
||||||
type PublishNewRequest struct {
|
type PublishNewRequest struct {
|
||||||
SubmissionID int64
|
SubmissionID int64
|
||||||
ModelID uint64
|
ModelID int64
|
||||||
ModelVersion uint64
|
ModelVersion int64
|
||||||
ModelName string
|
ModelName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublishFixRequest struct {
|
type PublishFixRequest struct {
|
||||||
SubmissionID int64
|
SubmissionID int64
|
||||||
ModelID uint64
|
ModelID int64
|
||||||
ModelVersion uint64
|
ModelVersion int64
|
||||||
TargetAssetID uint64
|
TargetAssetID int64
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type ScriptPolicy struct {
|
|||||||
// Hash of the source code that leads to this policy.
|
// 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.
|
// 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.
|
// The original source should still exist in the scripts table, which can be located by the same hash.
|
||||||
FromScriptHash uint64
|
FromScriptHash int64 // postgres does not support unsigned integers, so we have to pretend
|
||||||
// The ID of the replacement source (ScriptPolicyReplace)
|
// The ID of the replacement source (ScriptPolicyReplace)
|
||||||
// or verbatim source (ScriptPolicyAllowed)
|
// or verbatim source (ScriptPolicyAllowed)
|
||||||
// or 0 (other)
|
// or 0 (other)
|
||||||
|
@ -26,7 +26,7 @@ func HashParse(hash string) (uint64, error){
|
|||||||
type Script struct {
|
type Script struct {
|
||||||
ID int64 `gorm:"primaryKey"`
|
ID int64 `gorm:"primaryKey"`
|
||||||
Name string
|
Name string
|
||||||
Hash uint64
|
Hash int64 // postgres does not support unsigned integers, so we have to pretend
|
||||||
Source string
|
Source string
|
||||||
SubmissionID int64 // which submission did this script first appear in
|
SubmissionID int64 // which submission did this script first appear in
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
|
@ -29,10 +29,10 @@ type Submission struct {
|
|||||||
GameID int32
|
GameID int32
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
Submitter uint64 // UserID
|
Submitter int64 // UserID
|
||||||
AssetID uint64
|
AssetID int64
|
||||||
AssetVersion uint64
|
AssetVersion int64
|
||||||
Completed bool // Has this version of the map been completed at least once on maptest
|
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.
|
TargetAssetID int64 // where to upload map fix. if the TargetAssetID is 0, it's a new map.
|
||||||
StatusID Status
|
StatusID Status
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
filter.AddNotNil("from_script_hash", hash)
|
filter.AddNotNil("from_script_hash", int64(hash)) // No type safety!
|
||||||
}
|
}
|
||||||
if params.ToScriptID.IsSet(){
|
if params.ToScriptID.IsSet(){
|
||||||
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
|
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
|
||||||
@ -80,7 +80,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
|
|||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
resp = append(resp, api.ScriptPolicy{
|
resp = append(resp, api.ScriptPolicy{
|
||||||
ID: items[i].ID,
|
ID: items[i].ID,
|
||||||
FromScriptHash: model.HashFormat(items[i].FromScriptHash),
|
FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)),
|
||||||
ToScriptID: items[i].ToScriptID,
|
ToScriptID: items[i].ToScriptID,
|
||||||
Policy: int32(items[i].Policy),
|
Policy: int32(items[i].Policy),
|
||||||
})
|
})
|
||||||
@ -127,7 +127,7 @@ func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPol
|
|||||||
|
|
||||||
return &api.ScriptPolicy{
|
return &api.ScriptPolicy{
|
||||||
ID: policy.ID,
|
ID: policy.ID,
|
||||||
FromScriptHash: model.HashFormat(policy.FromScriptHash),
|
FromScriptHash: model.HashFormat(uint64(policy.FromScriptHash)),
|
||||||
ToScriptID: policy.ToScriptID,
|
ToScriptID: policy.ToScriptID,
|
||||||
Policy: int32(policy.Policy),
|
Policy: int32(policy.Policy),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -26,7 +26,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a
|
|||||||
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Hash: model.HashSource(req.Source),
|
Hash: int64(model.HashSource(req.Source)),
|
||||||
Source: req.Source,
|
Source: req.Source,
|
||||||
SubmissionID: req.SubmissionID.Or(0),
|
SubmissionID: req.SubmissionID.Or(0),
|
||||||
})
|
})
|
||||||
@ -52,7 +52,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
filter.AddNotNil("hash", hash)
|
filter.AddNotNil("hash", int64(hash)) // No type safety!
|
||||||
}
|
}
|
||||||
if params.Name.IsSet(){
|
if params.Name.IsSet(){
|
||||||
filter.AddNotNil("name", params.Name.Value)
|
filter.AddNotNil("name", params.Name.Value)
|
||||||
@ -76,7 +76,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
|
|||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
resp = append(resp, api.Script{
|
resp = append(resp, api.Script{
|
||||||
ID: items[i].ID,
|
ID: items[i].ID,
|
||||||
Hash: model.HashFormat(items[i].Hash),
|
Hash: model.HashFormat(uint64(items[i].Hash)),
|
||||||
Source: items[i].Source,
|
Source: items[i].Source,
|
||||||
SubmissionID: items[i].SubmissionID,
|
SubmissionID: items[i].SubmissionID,
|
||||||
})
|
})
|
||||||
@ -124,7 +124,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (
|
|||||||
return &api.Script{
|
return &api.Script{
|
||||||
ID: script.ID,
|
ID: script.ID,
|
||||||
Name: script.Name,
|
Name: script.Name,
|
||||||
Hash: model.HashFormat(script.Hash),
|
Hash: model.HashFormat(uint64(script.Hash)),
|
||||||
Source: script.Source,
|
Source: script.Source,
|
||||||
SubmissionID: script.SubmissionID,
|
SubmissionID: script.SubmissionID,
|
||||||
}, nil
|
}, nil
|
||||||
@ -151,7 +151,7 @@ func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, par
|
|||||||
}
|
}
|
||||||
if source, ok := req.Source.Get(); ok {
|
if source, ok := req.Source.Get(); ok {
|
||||||
pmap.Add("source", source)
|
pmap.Add("source", source)
|
||||||
pmap.Add("hash", model.HashSource(source))
|
pmap.Add("hash", int64(model.HashSource(source))) // No type safety!
|
||||||
}
|
}
|
||||||
if SubmissionID, ok := req.SubmissionID.Get(); ok {
|
if SubmissionID, ok := req.SubmissionID.Get(); ok {
|
||||||
pmap.Add("submission_id", SubmissionID)
|
pmap.Add("submission_id", SubmissionID)
|
||||||
|
@ -21,11 +21,11 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
|
|||||||
DisplayName: request.DisplayName,
|
DisplayName: request.DisplayName,
|
||||||
Creator: request.Creator,
|
Creator: request.Creator,
|
||||||
GameID: request.GameID,
|
GameID: request.GameID,
|
||||||
Submitter: userInfo.UserID,
|
Submitter: int64(userInfo.UserID),
|
||||||
AssetID: uint64(request.AssetID),
|
AssetID: request.AssetID,
|
||||||
AssetVersion: uint64(request.AssetVersion),
|
AssetVersion: request.AssetVersion,
|
||||||
Completed: false,
|
Completed: false,
|
||||||
TargetAssetID: uint64(request.TargetAssetID.Value),
|
TargetAssetID: request.TargetAssetID.Value,
|
||||||
StatusID: model.StatusUnderConstruction,
|
StatusID: model.StatusUnderConstruction,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -149,7 +149,7 @@ func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.Update
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if caller is the submitter
|
// check if caller is the submitter
|
||||||
if !userInfo.IsSubmitter(submission.Submitter) {
|
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
|
||||||
return ErrPermissionDenied
|
return ErrPermissionDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.Actio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if caller is the submitter
|
// check if caller is the submitter
|
||||||
if !userInfo.IsSubmitter(submission.Submitter) {
|
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
|
||||||
return ErrPermissionDenied
|
return ErrPermissionDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.Actio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if caller is the submitter
|
// check if caller is the submitter
|
||||||
if !userInfo.IsSubmitter(submission.Submitter) {
|
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
|
||||||
return ErrPermissionDenied
|
return ErrPermissionDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
filter.AddNotNil("from_script_hash", hash)
|
filter.AddNotNil("from_script_hash", int64(hash)) // No type safety!
|
||||||
}
|
}
|
||||||
if params.ToScriptID.IsSet(){
|
if params.ToScriptID.IsSet(){
|
||||||
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
|
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
|
||||||
@ -70,7 +70,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
|
|||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
resp = append(resp, api.ScriptPolicy{
|
resp = append(resp, api.ScriptPolicy{
|
||||||
ID: items[i].ID,
|
ID: items[i].ID,
|
||||||
FromScriptHash: model.HashFormat(items[i].FromScriptHash),
|
FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)),
|
||||||
ToScriptID: items[i].ToScriptID,
|
ToScriptID: items[i].ToScriptID,
|
||||||
Policy: int32(items[i].Policy),
|
Policy: int32(items[i].Policy),
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a
|
|||||||
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Hash: model.HashSource(req.Source),
|
Hash: int64(model.HashSource(req.Source)),
|
||||||
Source: req.Source,
|
Source: req.Source,
|
||||||
SubmissionID: req.SubmissionID.Or(0),
|
SubmissionID: req.SubmissionID.Or(0),
|
||||||
})
|
})
|
||||||
@ -43,7 +43,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
filter.AddNotNil("hash", hash)
|
filter.AddNotNil("hash", int64(hash)) // No type safety!
|
||||||
}
|
}
|
||||||
if params.Name.IsSet(){
|
if params.Name.IsSet(){
|
||||||
filter.AddNotNil("name", params.Name.Value)
|
filter.AddNotNil("name", params.Name.Value)
|
||||||
@ -67,7 +67,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
|
|||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
resp = append(resp, api.Script{
|
resp = append(resp, api.Script{
|
||||||
ID: items[i].ID,
|
ID: items[i].ID,
|
||||||
Hash: model.HashFormat(items[i].Hash),
|
Hash: model.HashFormat(uint64(items[i].Hash)),
|
||||||
Source: items[i].Source,
|
Source: items[i].Source,
|
||||||
SubmissionID: items[i].SubmissionID,
|
SubmissionID: items[i].SubmissionID,
|
||||||
})
|
})
|
||||||
@ -90,7 +90,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (
|
|||||||
return &api.Script{
|
return &api.Script{
|
||||||
ID: script.ID,
|
ID: script.ID,
|
||||||
Name: script.Name,
|
Name: script.Name,
|
||||||
Hash: model.HashFormat(script.Hash),
|
Hash: model.HashFormat(uint64(script.Hash)),
|
||||||
Source: script.Source,
|
Source: script.Source,
|
||||||
SubmissionID: script.SubmissionID,
|
SubmissionID: script.SubmissionID,
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user