test
This commit is contained in:
@@ -36,6 +36,10 @@ type Workspace struct {
|
||||
// TrustMap maps resource ID → trust bool based on the creator peer's relation.
|
||||
// Not persisted (bson:"-") — recomputed on every load by ComputeTrustAndClean.
|
||||
TrustMap map[string]bool `json:"trust_map,omitempty" bson:"-"`
|
||||
|
||||
// StaleMap maps resource ID → stale bool. Populated at GET time from the
|
||||
// verify campaign results stored in oc-workspace's stale cache. Not persisted.
|
||||
StaleMap map[string]bool `json:"stale_map,omitempty" bson:"-"`
|
||||
}
|
||||
|
||||
func (d *Workspace) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
|
||||
@@ -7,10 +7,60 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"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"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
func init() {
|
||||
resources.WorkspaceCandidatesProvider = func(dt tools.DataType, request *tools.APIRequest) []resources.ResourceInterface {
|
||||
res, _, _ := NewAccessor(request).Search(&dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"user_creator_id": {{Operator: dbs.EQUAL.String(), Value: request.Username}},
|
||||
"active": {{Operator: dbs.EQUAL.String(), Value: true}},
|
||||
},
|
||||
}, "", false, 0, 1)
|
||||
if len(res) == 0 {
|
||||
return []resources.ResourceInterface{}
|
||||
}
|
||||
ws, ok := res[0].(*Workspace)
|
||||
if !ok {
|
||||
return []resources.ResourceInterface{}
|
||||
}
|
||||
// ws.Fill was already called by Search — typed slices are populated.
|
||||
// Return an empty non-nil slice when the workspace exists but has no
|
||||
// resources of the requested type: caller must not fall back to catalog.
|
||||
out := []resources.ResourceInterface{}
|
||||
switch dt {
|
||||
case tools.COMPUTE_RESOURCE:
|
||||
for _, c := range ws.ComputeResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
case tools.DATA_RESOURCE:
|
||||
for _, c := range ws.DataResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
case tools.STORAGE_RESOURCE:
|
||||
for _, c := range ws.StorageResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
case tools.PROCESSING_RESOURCE:
|
||||
for _, c := range ws.ProcessingResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
case tools.WORKFLOW_RESOURCE:
|
||||
for _, c := range ws.WorkflowResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
case tools.SERVICE_RESOURCE:
|
||||
for _, c := range ws.ServiceResources {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
// Workspace is a struct that represents a workspace
|
||||
type workspaceMongoAccessor struct {
|
||||
utils.AbstractAccessor[*Workspace] // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
|
||||
Reference in New Issue
Block a user