Update try
This commit is contained in:
@@ -91,10 +91,6 @@ func (d *CollaborativeArea) GetAccessor(request *tools.APIRequest) utils.Accesso
|
||||
return NewAccessor(request) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
func (d *CollaborativeArea) Trim() *CollaborativeArea {
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *CollaborativeArea) StoreDraftDefault() {
|
||||
d.AllowedPeersGroup = map[string][]string{
|
||||
d.CreatorID: {"*"},
|
||||
|
||||
@@ -53,8 +53,8 @@ func (a *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, i
|
||||
}
|
||||
|
||||
// UpdateOne updates a collaborative area in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
|
||||
func (a *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
res, code, err := utils.GenericUpdateOne(set.(*CollaborativeArea).Trim(), id, a, &CollaborativeArea{})
|
||||
func (a *collaborativeAreaMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
res, code, err := utils.GenericUpdateOne(set, id, a, &CollaborativeArea{})
|
||||
// a.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
|
||||
a.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
|
||||
a.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
|
||||
@@ -76,7 +76,7 @@ func (a *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DB
|
||||
data.(*CollaborativeArea).CollaborativeAreaRule = &CollaborativeAreaRule{}
|
||||
}
|
||||
data.(*CollaborativeArea).CollaborativeAreaRule.Creator = pp.GetID()
|
||||
d, code, err := utils.GenericStoreOne(data.(*CollaborativeArea).Trim(), a)
|
||||
d, code, err := utils.GenericStoreOne(data, a)
|
||||
if code == 200 {
|
||||
a.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows
|
||||
a.sharedWorkspace(d.(*CollaborativeArea), d.GetID()) // create all collaborative areas
|
||||
@@ -141,7 +141,9 @@ func (a *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeAr
|
||||
eld := eldest.(*CollaborativeArea)
|
||||
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
|
||||
for _, v := range eld.Workspaces {
|
||||
a.workspaceAccessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
|
||||
a.workspaceAccessor.UpdateOne(map[string]interface{}{
|
||||
"shared": "",
|
||||
}, v)
|
||||
if a.GetCaller() != nil || a.GetCaller().URLS == nil || a.GetCaller().URLS[tools.WORKSPACE] == nil {
|
||||
continue
|
||||
}
|
||||
@@ -157,7 +159,10 @@ func (a *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeAr
|
||||
}
|
||||
if shared.Workspaces != nil {
|
||||
for _, v := range shared.Workspaces { // update all the collaborative areas
|
||||
workspace, code, _ := a.workspaceAccessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace
|
||||
workspace, code, _ := a.workspaceAccessor.UpdateOne(
|
||||
map[string]interface{}{
|
||||
"shared": shared.UUID,
|
||||
}, v) // add the shared ref to workspace
|
||||
if a.GetCaller() != nil || a.GetCaller().URLS == nil || a.GetCaller().URLS[tools.WORKSPACE] == nil {
|
||||
continue
|
||||
}
|
||||
@@ -197,7 +202,7 @@ func (a *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeAre
|
||||
} // kick the shared reference in your old shared workflow
|
||||
n := &w.Workflow{}
|
||||
n.Shared = new
|
||||
a.workflowAccessor.UpdateOne(n, v)
|
||||
a.workflowAccessor.UpdateOne(n.Serialize(n), v)
|
||||
if a.GetCaller() != nil || a.GetCaller().URLS == nil || a.GetCaller().URLS[tools.WORKFLOW] == nil {
|
||||
continue
|
||||
}
|
||||
@@ -219,7 +224,7 @@ func (a *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeAre
|
||||
s := data.(*w.Workflow)
|
||||
if !slices.Contains(s.Shared, id) {
|
||||
s.Shared = append(s.Shared, id)
|
||||
workflow, code, _ := a.workflowAccessor.UpdateOne(s, v)
|
||||
workflow, code, _ := a.workflowAccessor.UpdateOne(s.Serialize(s), v)
|
||||
if a.GetCaller() != nil || a.GetCaller().URLS == nil || a.GetCaller().URLS[tools.WORKFLOW] == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user