New
This commit is contained in:
@@ -36,7 +36,7 @@ func (a *BookingMongoAccessor) UpdateOne(set map[string]interface{}, id string)
|
|||||||
set = map[string]interface{}{
|
set = map[string]interface{}{
|
||||||
"state": set["state"],
|
"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) {
|
func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
|
|||||||
@@ -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
|
// 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) {
|
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.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
|
||||||
a.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
|
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)
|
a.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (dca *ResourceMongoAccessor[T]) UpdateOne(set map[string]interface{}, id st
|
|||||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
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 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 {
|
func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool {
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ func (a *AbstractAccessor[T]) UpdateOne(set map[string]interface{}, id string) (
|
|||||||
return nil, 404, errors.New("not implemented")
|
return nil, 404, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
// should verify if a source is existing...
|
// 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) {
|
func (a *AbstractAccessor[T]) StoreOne(data DBObject) (DBObject, int, error) {
|
||||||
|
|||||||
@@ -87,17 +87,17 @@ func GenericDeleteOne(id string, a Accessor) (DBObject, int, error) {
|
|||||||
return res, 200, nil
|
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)
|
r, c, err := a.LoadOne(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, c, err
|
return nil, nil, c, err
|
||||||
}
|
}
|
||||||
obj := &AbstractObject{}
|
obj := &AbstractObject{}
|
||||||
b, _ := json.Marshal(r)
|
b, _ := json.Marshal(r)
|
||||||
json.Unmarshal(b, obj)
|
json.Unmarshal(b, obj)
|
||||||
ok, r := r.CanUpdate(obj)
|
ok, r := r.CanUpdate(obj)
|
||||||
if !ok {
|
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)
|
r.UpToDate(a.GetUser(), a.GetPeerID(), false)
|
||||||
if a.GetPeerID() == r.GetCreatorID() {
|
if a.GetPeerID() == r.GetCreatorID() {
|
||||||
@@ -105,24 +105,24 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor)
|
|||||||
r.Sign()
|
r.Sign()
|
||||||
}
|
}
|
||||||
if a.ShouldVerifyAuth() && !r.VerifyAuth("update", a.GetRequest()) {
|
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
|
loaded := r.Serialize(r) // get the loaded object
|
||||||
|
|
||||||
for k, v := range change { // apply the changes, with a flatten method
|
for k, v := range change { // apply the changes, with a flatten method
|
||||||
loaded[k] = v
|
loaded[k] = v
|
||||||
}
|
}
|
||||||
return loaded, 200, nil
|
return r, loaded, 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericLoadOne loads one object from the database (generic)
|
// GenericLoadOne loads one object from the database (generic)
|
||||||
// json expected in entry is a flatted object no need to respect the inheritance hierarchy
|
// 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) {
|
func GenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, int, error) {
|
||||||
loaded, c, err := ModelGenericUpdateOne(change, id, a)
|
obj, loaded, c, err := ModelGenericUpdateOne(change, id, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, c, err
|
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 {
|
if err != nil {
|
||||||
a.GetLogger().Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
a.GetLogger().Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func (a *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *t
|
|||||||
// UpdateOne updates a workflow in the database
|
// UpdateOne updates a workflow in the database
|
||||||
func (a *workflowMongoAccessor) UpdateOne(set map[string]interface{}, 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
|
// 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 {
|
if code != 200 {
|
||||||
return nil, code, err
|
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 {
|
if res.(*Workflow).Graph != nil && res.(*Workflow).Graph.Partial {
|
||||||
return nil, 403, errors.New("you are not allowed to update a partial workflow")
|
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 {
|
if code != 200 {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (wfa *WorkflowExecutionMongoAccessor) UpdateOne(set map[string]interface{},
|
|||||||
}
|
}
|
||||||
return utils.GenericUpdateOne(map[string]interface{}{
|
return utils.GenericUpdateOne(map[string]interface{}{
|
||||||
"state": set["state"],
|
"state": set["state"],
|
||||||
}, id, wfa, &WorkflowExecution{})
|
}, id, wfa)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
|
|||||||
@@ -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 {
|
if code == 200 && res != nil {
|
||||||
a.share(res.(*Workspace), tools.PUT, a.GetCaller())
|
a.share(res.(*Workspace), tools.PUT, a.GetCaller())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user