|
@@ -52,12 +52,28 @@ class PODStaticController(object):
|
52
|
52
|
return loGroups
|
53
|
53
|
|
54
|
54
|
@classmethod
|
55
|
|
- def getUserSpecificGroups(cls):
|
56
|
|
- return DBSession.query(pbma.Group).filter(pbma.Group.personnal_group==True).all()
|
|
55
|
+ def getRealGroupRightsOnNode(cls, piNodeId: int) -> pbmd.DIRTY_GroupRightsOnNode:
|
|
56
|
+
|
|
57
|
+ groupRightsOnNodeCustomSelect = DBSession\
|
|
58
|
+ .query(pbmd.DIRTY_GroupRightsOnNode)\
|
|
59
|
+ .from_statement(pbmd.DIRTY_RealGroupRightOnNodeSqlQuery)\
|
|
60
|
+ .params(node_id=piNodeId)\
|
|
61
|
+ .all()
|
|
62
|
+
|
|
63
|
+ return groupRightsOnNodeCustomSelect
|
57
|
64
|
|
58
|
65
|
@classmethod
|
59
|
|
- def getRealGroups(cls):
|
60
|
|
- return DBSession.query(pbma.Group).filter(pbma.Group.personnal_group==False).all()
|
|
66
|
+ def getUserDedicatedGroupRightsOnNode(cls, piNodeId: int) -> pbmd.DIRTY_GroupRightsOnNode:
|
|
67
|
+
|
|
68
|
+ groupRightsOnNodeCustomSelect = DBSession\
|
|
69
|
+ .query(pbmd.DIRTY_GroupRightsOnNode)\
|
|
70
|
+ .from_statement(pbmd.DIRTY_UserDedicatedGroupRightOnNodeSqlQuery)\
|
|
71
|
+ .params(node_id=piNodeId)\
|
|
72
|
+ .all()
|
|
73
|
+
|
|
74
|
+ return groupRightsOnNodeCustomSelect
|
|
75
|
+
|
|
76
|
+
|
61
|
77
|
|
62
|
78
|
class PODUserFilteredApiController(object):
|
63
|
79
|
|
|
@@ -79,7 +95,8 @@ class PODUserFilteredApiController(object):
|
79
|
95
|
def createNode(self, parent_id=0):
|
80
|
96
|
loNode = pbmd.PBNode()
|
81
|
97
|
loNode.owner_id = self._iCurrentUserId
|
82
|
|
- loNode.parent_id = parent_id
|
|
98
|
+ if int(parent_id)!=0:
|
|
99
|
+ loNode.parent_id = parent_id
|
83
|
100
|
parent_rights = DBSession.query(pbma.Rights).filter(pbma.Rights.node_id==parent_id).all()
|
84
|
101
|
loNode.rights = parent_rights
|
85
|
102
|
loNode.rights = [pbma.Rights(group_id=r.group_id, rights=r.rights) for r in parent_rights]
|
|
@@ -93,18 +110,34 @@ class PODUserFilteredApiController(object):
|
93
|
110
|
return loNewNode
|
94
|
111
|
|
95
|
112
|
|
96
|
|
- def getNode(self, liNodeId):
|
97
|
|
- liOwnerIdList = self._getUserIdListForFiltering()
|
98
|
|
- if liNodeId!=0:
|
99
|
|
- return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren")).\
|
100
|
|
- join(pbma.Group.users).\
|
101
|
|
- filter(pbmd.PBNode.node_id==liNodeId).\
|
102
|
|
- filter((pbmd.PBNode.owner_id.in_(liOwnerIdList)) | (pbma.user_group_table.c.user_id.in_(liOwnerIdList))).\
|
103
|
|
- first()
|
104
|
|
- return None
|
|
113
|
+ def getNode(self, liNodeId: int) -> pbmd.PBNode:
|
105
|
114
|
|
|
115
|
+ lsSqlSelectQuery = """pod_nodes.node_id IN
|
|
116
|
+ (SELECT
|
|
117
|
+ pgn.node_id
|
|
118
|
+ FROM
|
|
119
|
+ pod_group_node AS pgn
|
|
120
|
+ join pod_user_group AS pug ON pug.group_id = pgn.group_id
|
|
121
|
+ join pod_user AS pu ON pug.user_id = pu.user_id
|
|
122
|
+ WHERE
|
|
123
|
+ rights > 0
|
|
124
|
+ AND pu.user_id = %s)
|
|
125
|
+ """
|
|
126
|
+ lsNodeIdFiltering = lsSqlSelectQuery % (str(self._iCurrentUserId))
|
|
127
|
+
|
|
128
|
+ if liNodeId!=None and liNodeId!=0:
|
|
129
|
+ return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren"))\
|
|
130
|
+ .filter(pbmd.PBNode.node_id==liNodeId)\
|
|
131
|
+ .filter(
|
|
132
|
+ sqla.or_(
|
|
133
|
+ pbmd.PBNode.owner_id==self._iCurrentUserId,
|
|
134
|
+ lsNodeIdFiltering
|
|
135
|
+ )
|
|
136
|
+ )\
|
|
137
|
+ .one()
|
|
138
|
+ return None
|
106
|
139
|
|
107
|
|
- def getLastModifiedNodes(self, piMaxNodeNb):
|
|
140
|
+ def getLastModifiedNodes(self, piMaxNodeNb: int):
|
108
|
141
|
"""
|
109
|
142
|
Returns a list of nodes order by modification time and limited to piMaxNodeNb nodes
|
110
|
143
|
"""
|
|
@@ -112,7 +145,7 @@ class PODUserFilteredApiController(object):
|
112
|
145
|
return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren")).filter(pbmd.PBNode.owner_id.in_(liOwnerIdList)).order_by(pbmd.PBNode.updated_at.desc()).limit(piMaxNodeNb).all()
|
113
|
146
|
|
114
|
147
|
|
115
|
|
- def searchNodesByText(self, plKeywordList, piMaxNodeNb=100):
|
|
148
|
+ def searchNodesByText(self, plKeywordList: [str], piMaxNodeNb=100):
|
116
|
149
|
"""
|
117
|
150
|
Returns a list of nodes order by type, nodes which contain at least one of the keywords
|
118
|
151
|
"""
|
|
@@ -142,7 +175,19 @@ class PODUserFilteredApiController(object):
|
142
|
175
|
def buildTreeListForMenu(self, plViewableStatusId):
|
143
|
176
|
liOwnerIdList = self._getUserIdListForFiltering()
|
144
|
177
|
|
145
|
|
- loNodeList = pbm.DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.owner_id.in_(liOwnerIdList)).filter(pbmd.PBNode.node_type==pbmd.PBNodeType.Data).filter(pbmd.PBNode.node_status.in_(plViewableStatusId)).order_by(pbmd.PBNode.parent_tree_path).order_by(pbmd.PBNode.node_order).order_by(pbmd.PBNode.node_id).all()
|
|
178
|
+ # loNodeList = pbm.DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.owner_id.in_(liOwnerIdList)).filter(pbmd.PBNode.node_type==pbmd.PBNodeType.Data).filter(pbmd.PBNode.node_status.in_(plViewableStatusId)).order_by(pbmd.PBNode.parent_tree_path).order_by(pbmd.PBNode.node_order).order_by(pbmd.PBNode.node_id).all()
|
|
179
|
+ loNodeListNotFiltered = pbm.DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.node_type==pbmd.PBNodeType.Data).filter(pbmd.PBNode.node_status.in_(plViewableStatusId)).order_by(pbmd.PBNode.parent_tree_path).order_by(pbmd.PBNode.node_order).order_by(pbmd.PBNode.node_id).all()
|
|
180
|
+
|
|
181
|
+ loNodeList = []
|
|
182
|
+ for loNode in loNodeListNotFiltered:
|
|
183
|
+ if loNode.owner_id in self._getUserIdListForFiltering():
|
|
184
|
+ loNodeList.append(loNode)
|
|
185
|
+ else:
|
|
186
|
+ for loRight in loNode._lRights:
|
|
187
|
+ for loUser in loRight._oGroup.users:
|
|
188
|
+ if loUser.user_id in self._getUserIdListForFiltering():
|
|
189
|
+ loNodeList.append(loNode)
|
|
190
|
+
|
146
|
191
|
loTreeList = []
|
147
|
192
|
loTmpDict = {}
|
148
|
193
|
for loNode in loNodeList:
|
|
@@ -157,8 +202,18 @@ class PODUserFilteredApiController(object):
|
157
|
202
|
# We suppose that the parent node has already been added
|
158
|
203
|
# this *should* be the case, but the code does not check it
|
159
|
204
|
if loNode.parent_id not in loTmpDict.keys():
|
160
|
|
- loTmpDict[loNode.parent_id] = self.getNode(loNode.parent_id)
|
161
|
|
- loTmpDict[loNode.parent_id].appendStaticChild(loNode)
|
|
205
|
+ print('THE NODE =========',loNode.parent_id)
|
|
206
|
+ try:
|
|
207
|
+ loTmpDict[loNode.parent_id] = self.getNode(loNode.parent_id)
|
|
208
|
+ except Exception as e:
|
|
209
|
+ # loTreeList.append(
|
|
210
|
+ # FIXME - D.A. - 2014-05-22 This may be wrong code:
|
|
211
|
+ # we are in the case when the node parent is not shared with the current user
|
|
212
|
+ # So the node should be added at the root
|
|
213
|
+ pass
|
|
214
|
+ if loNode.parent_id in loTmpDict.keys():
|
|
215
|
+ # HACK- D.A. - 2014-05-22 - See FIXME upper
|
|
216
|
+ loTmpDict[loNode.parent_id].appendStaticChild(loNode)
|
162
|
217
|
|
163
|
218
|
return loTreeList
|
164
|
219
|
|