Update try
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
type ResourceInterface interface {
|
||||
utils.DBObject
|
||||
Trim()
|
||||
FilterPeer(peerID string) *dbs.Filters
|
||||
GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation
|
||||
ConvertToPricedResource(t tools.DataType, a *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, b *int, request *tools.APIRequest) (pricing.PricedItemITF, error)
|
||||
|
||||
@@ -37,9 +37,6 @@ func (d *NativeTool) ClearEnv() utils.DBObject {
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *NativeTool) Trim() {
|
||||
/* EMPTY */
|
||||
}
|
||||
func (w *NativeTool) SetAllowedInstances(request *tools.APIRequest, ids ...string) {
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
@@ -150,17 +150,6 @@ func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.A
|
||||
abs.Instances = VerifyAuthAction(abs.Instances, request, instanceID...)
|
||||
}
|
||||
|
||||
func (d *AbstractInstanciatedResource[T]) Trim() {
|
||||
d.Type = d.GetType()
|
||||
if ok, _ := utils.IsMySelf(d.CreatorID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); !ok {
|
||||
for _, instance := range d.Instances {
|
||||
instance.ClearPeerGroups()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
||||
return len(VerifyAuthAction(abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(callName, request)
|
||||
}
|
||||
|
||||
@@ -55,12 +55,10 @@ func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIReques
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
func (dca *ResourceMongoAccessor[T]) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
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")
|
||||
}
|
||||
set.(T).Trim()
|
||||
|
||||
if d, c, err := utils.GenericUpdateOne(set, id, dca, dca.generateData()); err != nil {
|
||||
return d, c, err
|
||||
} else {
|
||||
@@ -72,7 +70,6 @@ func (dca *ResourceMongoAccessor[T]) StoreOne(data utils.DBObject) (utils.DBObje
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
return nil, 404, errors.New("can't create a non existing computing units resource not reported onto compute units catalog")
|
||||
}
|
||||
data.(T).Trim()
|
||||
return utils.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,6 @@ type FakeResource struct {
|
||||
resources.AbstractInstanciatedResource[*MockInstance]
|
||||
}
|
||||
|
||||
func (f *FakeResource) Trim() {}
|
||||
func (f *FakeResource) SetAllowedInstances(*tools.APIRequest, ...string) {}
|
||||
func (f *FakeResource) VerifyAuth(string, *tools.APIRequest) bool { return true }
|
||||
|
||||
|
||||
@@ -41,13 +41,6 @@ func TestWorkflowResource_ClearEnv(t *testing.T) {
|
||||
w := &resources.WorkflowResource{}
|
||||
assert.Equal(t, w, w.ClearEnv())
|
||||
}
|
||||
|
||||
func TestWorkflowResource_Trim(t *testing.T) {
|
||||
w := &resources.WorkflowResource{}
|
||||
w.Trim()
|
||||
// nothing to assert; just test that it doesn't panic
|
||||
}
|
||||
|
||||
func TestWorkflowResource_SetAllowedInstances(t *testing.T) {
|
||||
w := &resources.WorkflowResource{}
|
||||
w.SetAllowedInstances(&tools.APIRequest{})
|
||||
|
||||
@@ -30,9 +30,6 @@ func (d *WorkflowResource) ClearEnv() utils.DBObject {
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) Trim() {
|
||||
/* EMPTY */
|
||||
}
|
||||
func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest, ids ...string) {
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user