massive draft for payment process (UNCOMPLETE)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package workspace
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
@@ -16,17 +18,20 @@ type Workspace struct {
|
||||
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
||||
}
|
||||
|
||||
func (d *Workspace) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New(tools.WORKSPACE, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||
func (d *Workspace) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return NewAccessor(request) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
func (ao *Workspace) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||
func (ao *Workspace) VerifyAuth(request *tools.APIRequest) bool {
|
||||
fmt.Println("Workspace.VerifyAuth", ao.Shared)
|
||||
if ao.Shared != "" {
|
||||
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, username, peerID, groups, nil).LoadOne(ao.Shared)
|
||||
shared, code, _ := shallow_collaborative_area.NewAccessor(request).LoadOne(ao.Shared)
|
||||
fmt.Println("Workspace.VerifyAuth", shared, code)
|
||||
if code != 200 || shared == nil {
|
||||
return false
|
||||
}
|
||||
return shared.VerifyAuth(username, peerID, groups)
|
||||
return shared.VerifyAuth(request)
|
||||
}
|
||||
return ao.AbstractObject.VerifyAuth(username, peerID, groups)
|
||||
fmt.Println("Workspace.VerifyAuth", ao.AbstractObject.VerifyAuth(request))
|
||||
return ao.AbstractObject.VerifyAuth(request)
|
||||
}
|
||||
|
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
type WorkspaceHistory struct{ Workspace }
|
||||
|
||||
func (d *WorkspaceHistory) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New(tools.WORKFLOW_HISTORY, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||
func (d *WorkspaceHistory) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return NewAccessorHistory(request) // Create a new instance of the accessor
|
||||
}
|
||||
func (r *WorkspaceHistory) GenerateID() {
|
||||
r.UUID = uuid.New().String()
|
||||
|
@@ -18,15 +18,21 @@ type workspaceMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor
|
||||
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *workspaceMongoAccessor {
|
||||
func NewAccessorHistory(request *tools.APIRequest) *workspaceMongoAccessor {
|
||||
return new(tools.WORKSPACE_HISTORY, request)
|
||||
}
|
||||
|
||||
func NewAccessor(request *tools.APIRequest) *workspaceMongoAccessor {
|
||||
return new(tools.WORKSPACE, request)
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor
|
||||
func new(t tools.DataType, request *tools.APIRequest) *workspaceMongoAccessor {
|
||||
return &workspaceMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
User: username,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t,
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: t,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -36,7 +42,7 @@ func New(t tools.DataType, username string, peerID string, groups []string, call
|
||||
func (a *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
res, code, err := utils.GenericDeleteOne(id, a)
|
||||
if code == 200 && res != nil {
|
||||
a.share(res.(*Workspace), tools.DELETE, a.Caller) // Share the deletion to the peers
|
||||
a.share(res.(*Workspace), tools.DELETE, a.GetCaller()) // Share the deletion to the peers
|
||||
}
|
||||
return res, code, err
|
||||
}
|
||||
@@ -46,7 +52,7 @@ func (a *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils
|
||||
d := set.(*Workspace) // Get the workspace from the set
|
||||
d.Clear()
|
||||
if d.Active { // If the workspace is active, deactivate all the other workspaces
|
||||
res, _, err := a.LoadAll()
|
||||
res, _, err := a.LoadAll(true)
|
||||
if err == nil {
|
||||
for _, r := range res {
|
||||
if r.GetID() != id {
|
||||
@@ -58,7 +64,7 @@ func (a *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils
|
||||
}
|
||||
res, code, err := utils.GenericUpdateOne(set, id, a, &Workspace{})
|
||||
if code == 200 && res != nil {
|
||||
a.share(res.(*Workspace), tools.PUT, a.Caller)
|
||||
a.share(res.(*Workspace), tools.PUT, a.GetCaller())
|
||||
}
|
||||
return res, code, err
|
||||
}
|
||||
@@ -70,8 +76,8 @@ func (a *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
||||
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}},
|
||||
},
|
||||
}
|
||||
res, _, err := a.Search(filters, "") // Search for the workspace
|
||||
if err == nil && len(res) > 0 { // If the workspace already exists, return an error
|
||||
res, _, err := a.Search(filters, "", true) // Search for the workspace
|
||||
if err == nil && len(res) > 0 { // If the workspace already exists, return an error
|
||||
return nil, 409, errors.New("A workspace with the same name already exists")
|
||||
}
|
||||
// reset the resources
|
||||
@@ -87,23 +93,23 @@ func (a *workspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, i
|
||||
|
||||
func (a *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[*Workspace](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||
d.(*Workspace).Fill(a.GetRequest())
|
||||
return d, 200, nil
|
||||
}, a)
|
||||
}
|
||||
|
||||
func (a *workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
func (a *workspaceMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[*Workspace](func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||
d.(*Workspace).Fill(a.GetRequest())
|
||||
return d
|
||||
}, a)
|
||||
}, isDraft, a)
|
||||
}
|
||||
|
||||
func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericSearch[*Workspace](filters, search, (&Workspace{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject {
|
||||
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||
d.(*Workspace).Fill(a.GetRequest())
|
||||
return d
|
||||
}, a)
|
||||
}, isDraft, a)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -115,7 +121,7 @@ func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD,
|
||||
return
|
||||
}
|
||||
shallow := &shallow_collaborative_area.ShallowCollaborativeArea{}
|
||||
access := (shallow).GetAccessor(a.GetUser(), a.PeerID, a.Groups, nil)
|
||||
access := (shallow).GetAccessor(a.GetRequest())
|
||||
res, code, _ := access.LoadOne(realData.Shared)
|
||||
if code != 200 {
|
||||
return
|
||||
|
Reference in New Issue
Block a user