lightest + clearest code
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"slices"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
@@ -39,6 +38,10 @@ type AbstractResource struct {
|
||||
Currency string `json:"currency,omitempty" bson:"currency,omitempty"` // Currency is the currency of the price
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) SetResourceModel(model *ResourceModel) {
|
||||
abs.ResourceModel = model
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) VerifyAuth(peerID string, groups []string) bool {
|
||||
if grps, ok := abs.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
||||
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
|
||||
@@ -53,18 +56,6 @@ func (abs *AbstractResource) VerifyAuth(peerID string, groups []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) GetResourceFilter(search string) *dbs.Filters {
|
||||
return &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
|
||||
"abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.owner": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.source_url": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* GetModelType returns the type of the model key
|
||||
*/
|
||||
@@ -147,7 +138,7 @@ func (abs *ResourceModel) VerifyAuth(peerID string, groups []string) bool {
|
||||
func (d *ResourceModel) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return &ResourceModelMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
Type: tools.RESOURCE_MODEL.String(),
|
||||
Type: tools.RESOURCE_MODEL,
|
||||
PeerID: peerID,
|
||||
Groups: groups,
|
||||
Caller: caller,
|
||||
|
||||
Reference in New Issue
Block a user