diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 94b6e44..042c394 100644 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -212,12 +212,7 @@ func genericLoadAll[T DBObject](res *mgb.Cursor, code int, err error, f func(DBO if err = res.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } - - var test []map[string]interface{} - _ = res.All(mongo.MngoCtx, &test) - fmt.Println("results 1", res, results, test, err) for _, r := range results { - fmt.Println("results", r) if !r.VerifyAuth(a.GetPeerID(), a.GetGroups()) { continue } diff --git a/models/workflow/workflow.go b/models/workflow/workflow.go index 6aa4b3b..8d8727a 100644 --- a/models/workflow/workflow.go +++ b/models/workflow/workflow.go @@ -3,6 +3,7 @@ package workflow import ( "errors" + "cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area" "cloud.o-forge.io/core/oc-lib/models/peer" "cloud.o-forge.io/core/oc-lib/models/resources" "cloud.o-forge.io/core/oc-lib/models/utils" @@ -97,6 +98,20 @@ type Workflow struct { AbstractWorkflow // AbstractWorkflow contains the basic fields of a workflow } +func (ao *Workflow) VerifyAuth(peerID string, groups []string) bool { + isAuthorized := false + if len(ao.Shared) > 0 { + for _, shared := range ao.Shared { + shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, peerID, groups, nil).LoadOne(shared) + if code != 200 || shared == nil { + isAuthorized = false + } + isAuthorized = shared.VerifyAuth(peerID, groups) + } + } + return isAuthorized +} + /* * CheckBooking is a function that checks the booking of the workflow on peers (even ourselves) */ diff --git a/models/workspace/workspace.go b/models/workspace/workspace.go index 7b03386..ef38853 100644 --- a/models/workspace/workspace.go +++ b/models/workspace/workspace.go @@ -1,6 +1,7 @@ package workspace import ( + "cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area" "cloud.o-forge.io/core/oc-lib/models/resources" "cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/tools" @@ -18,3 +19,14 @@ type Workspace struct { func (d *Workspace) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor { return New(tools.WORKSPACE, peerID, groups, caller) // Create a new instance of the accessor } + +func (ao *Workspace) VerifyAuth(peerID string, groups []string) bool { + if ao.Shared != "" { + shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, peerID, groups, nil).LoadOne(ao.Shared) + if code != 200 || shared == nil { + return false + } + return shared.VerifyAuth(peerID, groups) + } + return false +}