diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index 5f7b1b0..cecdc7c 100644 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -11,6 +11,7 @@ type ResourceInterface interface { utils.DBObject Trim() ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF + GetType() string SetAllowedInstances(request *tools.APIRequest) SetResourceModel(model *resource_model.ResourceModel) } diff --git a/models/resources/resource.go b/models/resources/resource.go index bb9c7f3..8f8f15b 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -34,7 +34,7 @@ type AbstractResource struct { } func (r *AbstractResource) GetType() string { - return r.Type + return tools.INVALID.String() } func (r *AbstractResource) StoreDraftDefault() { @@ -85,7 +85,6 @@ func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.AP } func (d *AbstractIntanciatedResource[T]) Trim() { - d.AbstractResource.AbstractObject.Type = d.GetType() if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok { for _, instance := range d.Instances { instance.ClearPeerGroups() diff --git a/models/resources/resource_accessor.go b/models/resources/resource_accessor.go index 43e8c2b..421ce34 100644 --- a/models/resources/resource_accessor.go +++ b/models/resources/resource_accessor.go @@ -69,10 +69,13 @@ func (dca *resourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, er func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) { resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType().String(), isDraft) return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject { + d.(T).SetAllowedInstances(wfa.Request) + if d.(T).GetType() != wfa.GetType().String() { + return nil + } if err == nil && len(resources) > 0 { d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } - d.(T).SetAllowedInstances(wfa.Request) return d }, isDraft, wfa) } @@ -81,10 +84,13 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType().String(), false) return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search), func(d utils.DBObject) utils.ShallowDBObject { + d.(T).SetAllowedInstances(wfa.Request) + if d.(T).GetType() != wfa.GetType().String() { + return nil + } if err == nil && len(resources) > 0 { d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } - d.(T).SetAllowedInstances(wfa.Request) return d }, isDraft, wfa) } @@ -96,7 +102,6 @@ func (abs *resourceMongoAccessor[T]) getResourceFilter(search string) *dbs.Filte return &dbs.Filters{ Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided "abstractintanciatedresource.abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}}, - "abstractintanciatedresource.abstractresource.abstractobject.type": {{Operator: dbs.LIKE.String(), Value: search}}, "abstractintanciatedresource.abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}}, "abstractintanciatedresource.abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}}, "abstractintanciatedresource.abstractresource.owners.name": {{Operator: dbs.LIKE.String(), Value: search}}, diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 10088f8..772a6a2 100644 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -31,7 +31,6 @@ type AbstractObject struct { Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"` IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"` CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"` - Type string `json:"type,omitempty" bson:"type,omitempty"` CreationDate time.Time `json:"creation_date" bson:"creation_date"` UpdateDate time.Time `json:"update_date" bson:"update_date"` UpdaterID string `json:"updater_id" bson:"updater_id"`