add username to our trip

This commit is contained in:
mr
2024-12-04 11:33:08 +01:00
parent 6681c455d8
commit fd01f535a1
30 changed files with 129 additions and 113 deletions

View File

@@ -18,18 +18,18 @@ type Workspace struct {
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
}
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 (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 (ao *Workspace) VerifyAuth(peerID string, groups []string) bool {
func (ao *Workspace) VerifyAuth(username string, peerID string, groups []string) bool {
fmt.Println("Workspace.VerifyAuth", ao.Shared)
if ao.Shared != "" {
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, peerID, groups, nil).LoadOne(ao.Shared)
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, username, peerID, groups, nil).LoadOne(ao.Shared)
if code != 200 || shared == nil {
return false
}
return shared.VerifyAuth(peerID, groups)
return shared.VerifyAuth(username, peerID, groups)
}
return true
}

View File

@@ -8,8 +8,8 @@ import (
type WorkspaceHistory struct{ Workspace }
func (d *WorkspaceHistory) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
return New(tools.WORKFLOW_HISTORY, peerID, groups, caller) // Create a new instance of the accessor
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 (r *WorkspaceHistory) GenerateID() {
r.UUID = uuid.New().String()

View File

@@ -18,12 +18,13 @@ type workspaceMongoAccessor struct {
}
// New creates a new instance of the workspaceMongoAccessor
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *workspaceMongoAccessor {
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *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,
},
@@ -86,21 +87,21 @@ 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.PeerID, a.Groups)
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
return d, 200, nil
}, a)
}
func (a *workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
return utils.GenericLoadAll[*Workspace](func(d utils.DBObject) utils.ShallowDBObject {
d.(*Workspace).Fill(a.PeerID, a.Groups)
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
return d
}, a)
}
func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
return utils.GenericSearch[*Workspace](filters, search, (&Workspace{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject {
d.(*Workspace).Fill(a.PeerID, a.Groups)
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
return d
}, a)
}
@@ -114,7 +115,7 @@ func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD,
return
}
shallow := &shallow_collaborative_area.ShallowCollaborativeArea{}
access := (shallow).GetAccessor(a.PeerID, a.Groups, nil)
access := (shallow).GetAccessor(a.GetUser(), a.PeerID, a.Groups, nil)
res, code, _ := access.LoadOne(realData.Shared)
if code != 200 {
return