MCPcopy Create free account
hub / github.com/pydio/cells / LoadRootNodesForWorkspaces

Function LoadRootNodesForWorkspaces

common/permissions/ws-roots.go:53–108  ·  view source on GitHub ↗

LoadRootNodesForWorkspaces finds all root nodes based on the ACLs

(ctx context.Context, wsUUIDs []string, wss map[string]*idm.Workspace, resolver VirtualPathResolver)

Source from the content-addressed store, hash-verified

51
52// LoadRootNodesForWorkspaces finds all root nodes based on the ACLs
53func LoadRootNodesForWorkspaces(ctx context.Context, wsUUIDs []string, wss map[string]*idm.Workspace, resolver VirtualPathResolver) error {
54
55 acls, err := GetACLsForWorkspace(ctx, wsUUIDs, &idm.ACLAction{Name: AclWsrootActionName})
56 if err != nil {
57 return err
58 }
59 wsAcls := make(map[string][]*idm.ACL, len(wsUUIDs))
60 for _, a := range acls {
61 wsAcls[a.WorkspaceID] = append(wsAcls[a.WorkspaceID], a)
62 }
63 streamer := treec.NodeProviderStreamerClient(ctx)
64 ct, ca := context.WithCancel(ctx)
65 defer ca()
66 c, e := streamer.ReadNodeStream(ct)
67 if e != nil {
68 return e
69 }
70
71 localCache := make(map[string]*tree.Node)
72 for uuid, ws := range wss {
73 aa, o := wsAcls[uuid]
74 if !o {
75 continue
76 }
77 for _, a := range aa {
78 if n, o := localCache[a.NodeID]; o {
79 if ws.RootNodes == nil {
80 ws.RootNodes = make(map[string]*tree.Node)
81 }
82 ws.RootNodes[a.NodeID] = n
83 }
84 c.Send(&tree.ReadNodeRequest{Node: &tree.Node{Uuid: a.NodeID}})
85 r, e := c.Recv()
86 if e != nil {
87 break
88 }
89 if r != nil && r.Success {
90 if ws.RootNodes == nil {
91 ws.RootNodes = make(map[string]*tree.Node)
92 }
93 ws.RootNodes[a.NodeID] = r.Node.WithoutReservedMetas()
94 localCache[a.NodeID] = r.Node.WithoutReservedMetas()
95 } else {
96 // May be a virtual node
97 if node, ok := resolver(ctx, &tree.Node{Uuid: a.NodeID}); ok {
98 if ws.RootNodes == nil {
99 ws.RootNodes = make(map[string]*tree.Node)
100 }
101 ws.RootNodes[a.NodeID] = node.WithoutReservedMetas()
102 localCache[a.NodeID] = node.WithoutReservedMetas()
103 }
104 }
105 }
106 }
107 return nil
108}
109
110// StoreRootNodesAsACLs transforms a list of RootNodes into a list of ACL and store them.

Callers 2

ServeDAVMethod · 0.92
SearchWorkspacesMethod · 0.92

Calls 9

GetACLsForWorkspaceFunction · 0.85
makeFunction · 0.85
resolverStruct · 0.85
WithoutReservedMetasMethod · 0.80
ReadNodeStreamMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65
caFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…