light modification
This commit is contained in:
@@ -122,6 +122,10 @@ type AbstractAccessor struct {
|
||||
ResourceModelAccessor Accessor
|
||||
}
|
||||
|
||||
func (r *AbstractAccessor) ShouldVerifyAuth() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *AbstractAccessor) GetRequest() *tools.APIRequest {
|
||||
return r.Request
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"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")
|
||||
}
|
||||
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())
|
||||
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")
|
||||
}
|
||||
_, 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
|
||||
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")
|
||||
}
|
||||
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
|
||||
}
|
||||
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 f(data)
|
||||
@@ -125,12 +124,11 @@ func genericLoadAll[T DBObject](res *mgb.Cursor, code int, err error, onlyDraft
|
||||
return nil, 404, err
|
||||
}
|
||||
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
|
||||
}
|
||||
objs = append(objs, f(r))
|
||||
}
|
||||
fmt.Println("results 2", results, objs)
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ type Accessor interface {
|
||||
GetGroups() []string
|
||||
GetLogger() *zerolog.Logger
|
||||
GetCaller() *tools.HTTPCaller
|
||||
ShouldVerifyAuth() bool
|
||||
Search(filters *dbs.Filters, search string, isDraft bool) ([]ShallowDBObject, int, error)
|
||||
LoadAll(isDraft bool) ([]ShallowDBObject, int, error)
|
||||
LoadOne(id string) (DBObject, int, error)
|
||||
|
||||
Reference in New Issue
Block a user