From 2bfcfb5736b3c2389115038d90587ed95f3612e1 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 4 Mar 2026 13:51:43 +0100 Subject: [PATCH] New --- models/booking/booking_mongo_accessor.go | 2 +- .../collaborative_area_mongo_accessor.go | 2 +- models/resources/resource_accessor.go | 2 +- models/utils/abstracts.go | 2 +- models/utils/common.go | 16 ++++++++-------- models/workflow/workflow_mongo_accessor.go | 4 ++-- .../workflow_execution_mongo_accessor.go | 2 +- models/workspace/workspace_mongo_accessor.go | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/models/booking/booking_mongo_accessor.go b/models/booking/booking_mongo_accessor.go index 6442de6..6c2134e 100644 --- a/models/booking/booking_mongo_accessor.go +++ b/models/booking/booking_mongo_accessor.go @@ -36,7 +36,7 @@ func (a *BookingMongoAccessor) UpdateOne(set map[string]interface{}, id string) set = map[string]interface{}{ "state": set["state"], } - return utils.GenericUpdateOne(set, id, a, &Booking{}) + return utils.GenericUpdateOne(set, id, a) } func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { diff --git a/models/collaborative_area/collaborative_area_mongo_accessor.go b/models/collaborative_area/collaborative_area_mongo_accessor.go index 56fe031..0de7576 100644 --- a/models/collaborative_area/collaborative_area_mongo_accessor.go +++ b/models/collaborative_area/collaborative_area_mongo_accessor.go @@ -54,7 +54,7 @@ func (a *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, i // UpdateOne updates a collaborative area in the database, given its ID and the new data, it automatically share to peers if the workspace is shared func (a *collaborativeAreaMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) { - res, code, err := utils.GenericUpdateOne(set, id, a, &CollaborativeArea{}) + res, code, err := utils.GenericUpdateOne(set, id, a) // a.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer a.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows a.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one) diff --git a/models/resources/resource_accessor.go b/models/resources/resource_accessor.go index 59a8400..18a335a 100755 --- a/models/resources/resource_accessor.go +++ b/models/resources/resource_accessor.go @@ -59,7 +59,7 @@ func (dca *ResourceMongoAccessor[T]) UpdateOne(set map[string]interface{}, id st if dca.GetType() == tools.COMPUTE_RESOURCE { return nil, 404, errors.New("can't update a non existing computing units resource not reported onto compute units catalog") } - return utils.GenericUpdateOne(set, id, dca, dca.generateData()) + return utils.GenericUpdateOne(set, id, dca) } func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool { diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 9f10f71..6ad9bce 100755 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -232,7 +232,7 @@ func (a *AbstractAccessor[T]) UpdateOne(set map[string]interface{}, id string) ( return nil, 404, errors.New("not implemented") } // should verify if a source is existing... - return GenericUpdateOne(set, id, a, a.New()) + return GenericUpdateOne(set, id, a) } func (a *AbstractAccessor[T]) StoreOne(data DBObject) (DBObject, int, error) { diff --git a/models/utils/common.go b/models/utils/common.go index 759ad6a..1a39e68 100755 --- a/models/utils/common.go +++ b/models/utils/common.go @@ -87,17 +87,17 @@ func GenericDeleteOne(id string, a Accessor) (DBObject, int, error) { return res, 200, nil } -func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor) (map[string]interface{}, int, error) { +func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, map[string]interface{}, int, error) { r, c, err := a.LoadOne(id) if err != nil { - return nil, c, err + return nil, nil, c, err } obj := &AbstractObject{} b, _ := json.Marshal(r) json.Unmarshal(b, obj) ok, r := r.CanUpdate(obj) if !ok { - return nil, 403, errors.New("you are not allowed to update :" + a.GetType().String()) + return nil, nil, 403, errors.New("you are not allowed to update :" + a.GetType().String()) } r.UpToDate(a.GetUser(), a.GetPeerID(), false) if a.GetPeerID() == r.GetCreatorID() { @@ -105,24 +105,24 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor) r.Sign() } if a.ShouldVerifyAuth() && !r.VerifyAuth("update", a.GetRequest()) { - return nil, 403, errors.New("you are not allowed to access :" + a.GetType().String()) + return nil, nil, 403, errors.New("you are not allowed to access :" + a.GetType().String()) } loaded := r.Serialize(r) // get the loaded object for k, v := range change { // apply the changes, with a flatten method loaded[k] = v } - return loaded, 200, nil + return r, loaded, 200, nil } // GenericLoadOne loads one object from the database (generic) // json expected in entry is a flatted object no need to respect the inheritance hierarchy -func GenericUpdateOne(change map[string]interface{}, id string, a Accessor, new DBObject) (DBObject, int, error) { - loaded, c, err := ModelGenericUpdateOne(change, id, a) +func GenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, int, error) { + obj, loaded, c, err := ModelGenericUpdateOne(change, id, a) if err != nil { return nil, c, err } - id, code, err := mongo.MONGOService.UpdateOne(new.Deserialize(loaded, new), id, a.GetType().String()) + id, code, err := mongo.MONGOService.UpdateOne(obj.Deserialize(loaded, obj), id, a.GetType().String()) if err != nil { a.GetLogger().Error().Msg("Could not update " + id + " to db. Error: " + err.Error()) return nil, code, err diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 8a34065..46c2993 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -94,7 +94,7 @@ func (a *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *t // UpdateOne updates a workflow in the database func (a *workflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) { // avoid the update if the schedule is the same - res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{}) + res, code, err := utils.GenericUpdateOne(set, id, a) if code != 200 { return nil, code, err } @@ -102,7 +102,7 @@ func (a *workflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) 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(res.Serialize(res), id, a, &Workflow{}) + res, code, err = utils.GenericUpdateOne(res.Serialize(res), id, a) if code != 200 { return nil, code, err } diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index b497efd..732f8e9 100755 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -48,7 +48,7 @@ func (wfa *WorkflowExecutionMongoAccessor) UpdateOne(set map[string]interface{}, } return utils.GenericUpdateOne(map[string]interface{}{ "state": set["state"], - }, id, wfa, &WorkflowExecution{}) + }, id, wfa) } func (a *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { diff --git a/models/workspace/workspace_mongo_accessor.go b/models/workspace/workspace_mongo_accessor.go index 5ef3fb0..bd48230 100644 --- a/models/workspace/workspace_mongo_accessor.go +++ b/models/workspace/workspace_mongo_accessor.go @@ -60,7 +60,7 @@ func (a *workspaceMongoAccessor) UpdateOne(set map[string]interface{}, id string } } } - res, code, err := utils.GenericUpdateOne(set, id, a, &Workspace{}) + res, code, err := utils.GenericUpdateOne(set, id, a) if code == 200 && res != nil { a.share(res.(*Workspace), tools.PUT, a.GetCaller()) }