|
@@ -94,19 +94,35 @@ class PODUserFilteredApiController(object):
|
94
|
94
|
return self._iUserIdFilteringList
|
95
|
95
|
|
96
|
96
|
|
97
|
|
- def createNode(self, parent_id=0):
|
|
97
|
+ def createNode(self, parent_id=0, inherit_rights=True):
|
98
|
98
|
loNode = pbmd.PBNode()
|
99
|
99
|
loNode.owner_id = self._iCurrentUserId
|
100
|
100
|
if int(parent_id)!=0:
|
101
|
|
- loNode.parent_id = parent_id
|
102
|
|
- parent_rights = DBSession.query(pbma.Rights).filter(pbma.Rights.node_id==parent_id).all()
|
103
|
|
- loNode.rights = parent_rights
|
104
|
|
- loNode.rights = [pbma.Rights(group_id=r.group_id, rights=r.rights) for r in parent_rights]
|
|
101
|
+ loNode.parent_id = parent_id
|
|
102
|
+
|
|
103
|
+ if inherit_rights:
|
|
104
|
+ parent_node = DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.node_id==parent_id).one()
|
|
105
|
+ self.copy_rights(parent_node, loNode)
|
|
106
|
+
|
105
|
107
|
DBSession.add(loNode)
|
|
108
|
+
|
106
|
109
|
return loNode
|
107
|
|
-
|
108
|
|
- def createDummyNode(self, parent_id):
|
109
|
|
- loNewNode = self.createNode(parent_id)
|
|
110
|
+
|
|
111
|
+ def copy_rights(self, from_node: pbmd.PBNode, to_node: pbmd.PBNode, copy_also_is_shared=True):
|
|
112
|
+ """
|
|
113
|
+ copy rights from first node to second one
|
|
114
|
+ """
|
|
115
|
+ for parent_right in from_node._lRights:
|
|
116
|
+ new_right = self.createRight()
|
|
117
|
+ new_right.group_id = parent_right.group_id
|
|
118
|
+ new_right.rights = parent_right.rights
|
|
119
|
+ to_node._lRights.append(new_right)
|
|
120
|
+
|
|
121
|
+ if copy_also_is_shared:
|
|
122
|
+ to_node.is_shared = from_node.is_shared
|
|
123
|
+
|
|
124
|
+ def createDummyNode(self, parent_id, inherit_rights=True):
|
|
125
|
+ loNewNode = self.createNode(parent_id, inherit_rights)
|
110
|
126
|
loNewNode.data_label = ''
|
111
|
127
|
loNewNode.data_content = ''
|
112
|
128
|
return loNewNode
|
|
@@ -171,13 +187,13 @@ class PODUserFilteredApiController(object):
|
171
|
187
|
FROM
|
172
|
188
|
pod_group_node AS pgn
|
173
|
189
|
join pod_user_group AS pug ON pug.group_id = pgn.group_id
|
174
|
|
- join pod_nodes AS pn ON pgn.node_id=pn.node_id
|
|
190
|
+ join pod_nodes AS pn ON pgn.node_id=pn.node_id AND pn.is_shared='t'
|
175
|
191
|
WHERE
|
176
|
192
|
pn.node_type='data'
|
177
|
193
|
AND pn.node_status NOT IN ('deleted', 'closed')
|
178
|
194
|
AND pn.node_id=pgn.node_id
|
179
|
195
|
AND pgn.rights > 0
|
180
|
|
- AND pug.user_id = 3
|
|
196
|
+ AND pug.user_id = :owner_id
|
181
|
197
|
|
182
|
198
|
UNION
|
183
|
199
|
SELECT
|
|
@@ -201,9 +217,9 @@ class PODUserFilteredApiController(object):
|
201
|
217
|
FROM
|
202
|
218
|
pod_nodes AS pn
|
203
|
219
|
WHERE
|
204
|
|
- pn.node_type='data'
|
|
220
|
+ pn.node_type = 'data'
|
205
|
221
|
AND pn.node_status NOT IN ('deleted', 'closed')
|
206
|
|
- AND pn.owner_id=:owner_id
|
|
222
|
+ AND pn.owner_id = :owner_id
|
207
|
223
|
|
208
|
224
|
ORDER BY node_id ASC
|
209
|
225
|
"""
|
|
@@ -286,7 +302,7 @@ class PODUserFilteredApiController(object):
|
286
|
302
|
|
287
|
303
|
|
288
|
304
|
|
289
|
|
- def buildTreeListForMenu(self, poCurrentNode: pbmd.PBNode, plViewableStatusId: [], plAllowedNodes: [pbmd.PBNode]) -> [pbmd.NodeTreeItem]:
|
|
305
|
+ def buildTreeListForMenu(self, current_node: pbmd.PBNode, allowed_nodes: [pbmd.PBNode]) -> [pbmd.NodeTreeItem]:
|
290
|
306
|
# The algorithm is:
|
291
|
307
|
# 1. build an intermediate tree containing only current node and parent path
|
292
|
308
|
# + complete it with sibling at each level (except root)
|
|
@@ -298,34 +314,33 @@ class PODUserFilteredApiController(object):
|
298
|
314
|
previous_tree_item = None
|
299
|
315
|
tmp_children_nodes = []
|
300
|
316
|
|
301
|
|
- print("============================> ",poCurrentNode)
|
302
|
|
- if poCurrentNode is not None:
|
303
|
|
- breadcrumb_nodes = poCurrentNode.getBreadCrumbNodes()
|
304
|
|
- print("====================> NODES", breadcrumb_nodes)
|
305
|
|
- breadcrumb_nodes.append(poCurrentNode) # by default the current node is not included
|
|
317
|
+ if current_node is not None:
|
|
318
|
+ breadcrumb_nodes = current_node.getBreadCrumbNodes()
|
|
319
|
+ breadcrumb_nodes.append(current_node) # by default the current node is not included
|
306
|
320
|
|
307
|
321
|
for breadcrumb_node in reversed(breadcrumb_nodes):
|
308
|
322
|
if previous_tree_item is None:
|
309
|
323
|
# First iteration. We add all current_node children
|
310
|
324
|
for child_node in breadcrumb_node.getChildren():
|
311
|
|
- child_item = pbmd.NodeTreeItem(child_node, [])
|
312
|
|
- assert(isinstance(child_item, pbmd.NodeTreeItem))
|
313
|
|
- tmp_children_nodes.append(child_item)
|
|
325
|
+ if child_node in allowed_nodes:
|
|
326
|
+ child_item = pbmd.NodeTreeItem(child_node, [])
|
|
327
|
+ tmp_children_nodes.append(child_item)
|
|
328
|
+
|
314
|
329
|
previous_tree_item = pbmd.NodeTreeItem(breadcrumb_node, tmp_children_nodes)
|
|
330
|
+
|
315
|
331
|
else:
|
316
|
332
|
tmp_children_nodes = []
|
317
|
333
|
for child_node in breadcrumb_node.getChildren():
|
318
|
|
- if child_node == previous_tree_item.node:
|
319
|
|
- assert(isinstance(previous_tree_item, pbmd.NodeTreeItem))
|
320
|
|
- tmp_children_nodes.append(previous_tree_item)
|
321
|
|
- else:
|
322
|
|
- sibling_node = pbmd.NodeTreeItem(child_node, [])
|
323
|
|
- assert(isinstance(sibling_node, pbmd.NodeTreeItem))
|
324
|
|
- tmp_children_nodes.append(sibling_node)
|
|
334
|
+ if child_node in allowed_nodes:
|
|
335
|
+ if child_node == previous_tree_item.node:
|
|
336
|
+ tmp_children_nodes.append(previous_tree_item)
|
|
337
|
+ else:
|
|
338
|
+ sibling_node = pbmd.NodeTreeItem(child_node, [])
|
|
339
|
+ tmp_children_nodes.append(sibling_node)
|
325
|
340
|
|
326
|
341
|
previous_tree_item = pbmd.NodeTreeItem(breadcrumb_node, tmp_children_nodes)
|
327
|
342
|
|
328
|
|
- for node in plAllowedNodes:
|
|
343
|
+ for node in allowed_nodes:
|
329
|
344
|
# This part of the algorithm insert root items
|
330
|
345
|
if node.parent_id==0 or node.parent_id is None:
|
331
|
346
|
if previous_tree_item is not None and node == previous_tree_item.node:
|
|
@@ -337,9 +352,9 @@ class PODUserFilteredApiController(object):
|
337
|
352
|
# Try to add nodes shared with me but with a parent which is not shared
|
338
|
353
|
if node.owner_id!=self._iCurrentUserId:
|
339
|
354
|
# this is a node shared with me
|
340
|
|
- if node._oParent!=None and node._oParent not in plAllowedNodes:
|
|
355
|
+ if node._oParent!=None and node._oParent not in allowed_nodes:
|
341
|
356
|
# the node is shared but not the parent => put it in the root
|
342
|
|
- node_tree.append(pbmd.NodeTreeItem(node))
|
|
357
|
+ node_tree.append(pbmd.NodeTreeItem(node, []))
|
343
|
358
|
|
344
|
359
|
|
345
|
360
|
return node_tree
|