Update try
This commit is contained in:
@@ -92,13 +92,17 @@ func (a *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *t
|
||||
}
|
||||
|
||||
// UpdateOne updates a workflow in the database
|
||||
func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
func (a *workflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
// avoid the update if the schedule is the same
|
||||
set = a.verifyResource(set)
|
||||
if set.(*Workflow).Graph != nil && set.(*Workflow).Graph.Partial {
|
||||
res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{})
|
||||
if code != 200 {
|
||||
return nil, code, err
|
||||
}
|
||||
res = a.verifyResource(res)
|
||||
if res.(*Workflow).Graph != nil && res.(*Workflow).Graph.Partial {
|
||||
return nil, 403, errors.New("you are not allowed to update a partial workflow")
|
||||
}
|
||||
res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{})
|
||||
res, code, err = utils.GenericUpdateOne(res.Serialize(res), id, a, &Workflow{})
|
||||
if code != 200 {
|
||||
return nil, code, err
|
||||
}
|
||||
@@ -154,7 +158,7 @@ func (a *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active
|
||||
return
|
||||
}
|
||||
if err == nil && len(resource) > 0 { // if the workspace already exists, update it
|
||||
a.workspaceAccessor.UpdateOne(&workspace.Workspace{
|
||||
w := &workspace.Workspace{
|
||||
Active: active,
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
@@ -163,7 +167,8 @@ func (a *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active
|
||||
Workflows: workflow.Workflows,
|
||||
Computes: workflow.Computes,
|
||||
},
|
||||
}, resource[0].GetID())
|
||||
}
|
||||
a.workspaceAccessor.UpdateOne(w.Serialize(w), resource[0].GetID())
|
||||
} else { // if the workspace does not exist, create it
|
||||
a.workspaceAccessor.StoreOne(&workspace.Workspace{
|
||||
Active: active,
|
||||
|
||||
Reference in New Issue
Block a user