From 5c2980fb360ccf1d224fac8dbfb2ae0ecd4ae609 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 21 Jan 2025 09:02:26 +0100 Subject: [PATCH] light modification --- models/resources/resource.go | 2 ++ models/resources/resource_accessor.go | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/models/resources/resource.go b/models/resources/resource.go index 8f8f15b..61556ea 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -24,6 +24,7 @@ import ( type AbstractResource struct { utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) + Type string `json:"type,omitempty" bson:"type,omitempty"` // Type is the type of the resource Logo string `json:"logo,omitempty" bson:"logo,omitempty" validate:"required"` // Logo is the logo of the resource Description string `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the resource ShortDescription string `json:"short_description,omitempty" bson:"short_description,omitempty" validate:"required"` // ShortDescription is the short description of the resource @@ -85,6 +86,7 @@ func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.AP } func (d *AbstractIntanciatedResource[T]) Trim() { + d.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 9868f5a..cc35619 100644 --- a/models/resources/resource_accessor.go +++ b/models/resources/resource_accessor.go @@ -2,7 +2,6 @@ package resources import ( "slices" - "strings" "cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/logs" @@ -83,9 +82,6 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search), func(d utils.DBObject) utils.ShallowDBObject { d.(T).SetAllowedInstances(wfa.Request) - if strings.Contains(d.(T).GetType(), search) && search != "" { - return nil - } if err == nil && len(resources) > 0 { d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel)) } @@ -100,6 +96,7 @@ 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}},