light modification
This commit is contained in:
parent
bc12fb53be
commit
bf5a16f41b
@ -11,12 +11,14 @@ import (
|
|||||||
|
|
||||||
type peerMongoAccessor struct {
|
type peerMongoAccessor struct {
|
||||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
|
overrideAuth bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the peerMongoAccessor
|
// New creates a new instance of the peerMongoAccessor
|
||||||
func NewShallowAccessor() *peerMongoAccessor {
|
func NewShallowAccessor() *peerMongoAccessor {
|
||||||
return &peerMongoAccessor{
|
return &peerMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
overrideAuth: true,
|
||||||
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(tools.PEER.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(tools.PEER.String()), // Create a logger with the data type
|
||||||
Type: tools.PEER,
|
Type: tools.PEER,
|
||||||
},
|
},
|
||||||
@ -25,7 +27,8 @@ func NewShallowAccessor() *peerMongoAccessor {
|
|||||||
|
|
||||||
func NewAccessor(request *tools.APIRequest) *peerMongoAccessor {
|
func NewAccessor(request *tools.APIRequest) *peerMongoAccessor {
|
||||||
return &peerMongoAccessor{
|
return &peerMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
overrideAuth: false,
|
||||||
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(tools.PEER.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(tools.PEER.String()), // Create a logger with the data type
|
||||||
Request: request,
|
Request: request,
|
||||||
Type: tools.PEER,
|
Type: tools.PEER,
|
||||||
@ -33,6 +36,10 @@ func NewAccessor(request *tools.APIRequest) *peerMongoAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wfa *peerMongoAccessor) ShouldVerifyAuth() bool {
|
||||||
|
return !wfa.overrideAuth
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Nothing special here, just the basic CRUD operations
|
* Nothing special here, just the basic CRUD operations
|
||||||
*/
|
*/
|
||||||
|
@ -122,6 +122,10 @@ type AbstractAccessor struct {
|
|||||||
ResourceModelAccessor Accessor
|
ResourceModelAccessor Accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *AbstractAccessor) ShouldVerifyAuth() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (r *AbstractAccessor) GetRequest() *tools.APIRequest {
|
func (r *AbstractAccessor) GetRequest() *tools.APIRequest {
|
||||||
return r.Request
|
return r.Request
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
@ -31,7 +30,7 @@ func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if !data.VerifyAuth(a.GetRequest()) {
|
if a.ShouldVerifyAuth() && !data.VerifyAuth(a.GetRequest()) {
|
||||||
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
if cursor, _, _ := a.Search(&f, "", data.IsDrafted()); len(cursor) > 0 {
|
if cursor, _, _ := a.Search(&f, "", data.IsDrafted()); len(cursor) > 0 {
|
||||||
@ -59,7 +58,7 @@ func GenericDeleteOne(id string, a Accessor) (DBObject, int, error) {
|
|||||||
a.GetLogger().Error().Msg("Could not retrieve " + id + " to db. Error: " + err.Error())
|
a.GetLogger().Error().Msg("Could not retrieve " + id + " to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
if !res.VerifyAuth(a.GetRequest()) {
|
if a.ShouldVerifyAuth() && !res.VerifyAuth(a.GetRequest()) {
|
||||||
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
_, code, err = mongo.MONGOService.DeleteOne(id, a.GetType().String())
|
_, code, err = mongo.MONGOService.DeleteOne(id, a.GetType().String())
|
||||||
@ -83,7 +82,7 @@ func GenericUpdateOne(set DBObject, id string, a Accessor, new DBObject) (DBObje
|
|||||||
}
|
}
|
||||||
set = newSet
|
set = newSet
|
||||||
r.UpToDate(a.GetUser(), false)
|
r.UpToDate(a.GetUser(), false)
|
||||||
if !r.VerifyAuth(a.GetRequest()) {
|
if a.ShouldVerifyAuth() && !r.VerifyAuth(a.GetRequest()) {
|
||||||
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
change := set.Serialize(set) // get the changes
|
change := set.Serialize(set) // get the changes
|
||||||
@ -108,7 +107,7 @@ func GenericLoadOne[T DBObject](id string, f func(DBObject) (DBObject, int, erro
|
|||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
res_mongo.Decode(&data)
|
res_mongo.Decode(&data)
|
||||||
if !data.VerifyAuth(a.GetRequest()) {
|
if a.ShouldVerifyAuth() && !data.VerifyAuth(a.GetRequest()) {
|
||||||
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
return nil, 403, errors.New("you are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
return f(data)
|
return f(data)
|
||||||
@ -125,12 +124,11 @@ func genericLoadAll[T DBObject](res *mgb.Cursor, code int, err error, onlyDraft
|
|||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if !r.VerifyAuth(a.GetRequest()) || f(r) == nil || (onlyDraft && !r.IsDrafted()) || (!onlyDraft && r.IsDrafted()) {
|
if (a.ShouldVerifyAuth() && !r.VerifyAuth(a.GetRequest())) || f(r) == nil || (onlyDraft && !r.IsDrafted()) || (!onlyDraft && r.IsDrafted()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
objs = append(objs, f(r))
|
objs = append(objs, f(r))
|
||||||
}
|
}
|
||||||
fmt.Println("results 2", results, objs)
|
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ type Accessor interface {
|
|||||||
GetGroups() []string
|
GetGroups() []string
|
||||||
GetLogger() *zerolog.Logger
|
GetLogger() *zerolog.Logger
|
||||||
GetCaller() *tools.HTTPCaller
|
GetCaller() *tools.HTTPCaller
|
||||||
|
ShouldVerifyAuth() bool
|
||||||
Search(filters *dbs.Filters, search string, isDraft bool) ([]ShallowDBObject, int, error)
|
Search(filters *dbs.Filters, search string, isDraft bool) ([]ShallowDBObject, int, error)
|
||||||
LoadAll(isDraft bool) ([]ShallowDBObject, int, error)
|
LoadAll(isDraft bool) ([]ShallowDBObject, int, error)
|
||||||
LoadOne(id string) (DBObject, int, error)
|
LoadOne(id string) (DBObject, int, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user