resource as draft for update
This commit is contained in:
@@ -56,10 +56,7 @@ func (r *AbstractResource) StoreDraftDefault() {
|
||||
}
|
||||
|
||||
func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||||
if r.IsDraft != set.IsDrafted() && set.IsDrafted() {
|
||||
return true, set // only state can be updated
|
||||
}
|
||||
return r.IsDraft != set.IsDrafted() && set.IsDrafted(), set
|
||||
return r.IsDraft, set
|
||||
}
|
||||
|
||||
func (r *AbstractResource) CanDelete() bool {
|
||||
|
||||
@@ -59,12 +59,8 @@ 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")
|
||||
}
|
||||
if d, c, err := utils.GenericUpdateOne(set, id, dca, dca.generateData()); err != nil {
|
||||
return d, c, err
|
||||
} else {
|
||||
return utils.GenericUpdateOne(set, id, dca, dca.generateData())
|
||||
}
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool {
|
||||
return false // TEMP : by pass
|
||||
|
||||
@@ -93,7 +93,7 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor)
|
||||
}
|
||||
ok, r := r.CanUpdate(r)
|
||||
if !ok {
|
||||
return nil, 403, errors.New("you are not allowed to delete :" + a.GetType().String())
|
||||
return 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() {
|
||||
@@ -114,6 +114,9 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor)
|
||||
// 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) {
|
||||
if change["is_draft"] == nil {
|
||||
change["is_draft"] = false
|
||||
}
|
||||
loaded, c, err := ModelGenericUpdateOne(change, id, a)
|
||||
if err != nil {
|
||||
return nil, c, err
|
||||
|
||||
Reference in New Issue
Block a user