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) {
|
func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||||||
if r.IsDraft != set.IsDrafted() && set.IsDrafted() {
|
return r.IsDraft, set
|
||||||
return true, set // only state can be updated
|
|
||||||
}
|
|
||||||
return r.IsDraft != set.IsDrafted() && set.IsDrafted(), set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractResource) CanDelete() bool {
|
func (r *AbstractResource) CanDelete() bool {
|
||||||
|
|||||||
@@ -59,11 +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")
|
||||||
}
|
}
|
||||||
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())
|
return utils.GenericUpdateOne(set, id, dca, dca.generateData())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool {
|
func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor)
|
|||||||
}
|
}
|
||||||
ok, r := r.CanUpdate(r)
|
ok, r := r.CanUpdate(r)
|
||||||
if !ok {
|
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)
|
r.UpToDate(a.GetUser(), a.GetPeerID(), false)
|
||||||
if a.GetPeerID() == r.GetCreatorID() {
|
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)
|
// 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, new DBObject) (DBObject, int, error) {
|
||||||
|
if change["is_draft"] == nil {
|
||||||
|
change["is_draft"] = false
|
||||||
|
}
|
||||||
loaded, c, err := ModelGenericUpdateOne(change, id, a)
|
loaded, c, err := ModelGenericUpdateOne(change, id, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, c, err
|
return nil, c, err
|
||||||
|
|||||||
Reference in New Issue
Block a user