浏览代码

Merge branch 'master' of https://bitbucket.org/lebouquetin/protov1

Damien Accorsi 11 年前
父节点
当前提交
04757975da

+ 29 - 9
pboard/pboard/controllers/api.py 查看文件

62
         loUserSpecificGroup = pld.PODStaticController.createGroup()
62
         loUserSpecificGroup = pld.PODStaticController.createGroup()
63
 
63
 
64
         loUserSpecificGroup.group_id = 0-loNewAccount.user_id # group id of a given user is the opposite of the user id
64
         loUserSpecificGroup.group_id = 0-loNewAccount.user_id # group id of a given user is the opposite of the user id
65
-        loUserSpecificGroup.group_name = ''
65
+        loUserSpecificGroup.group_name = 'user_%d' % loNewAccount.user_id
66
         loUserSpecificGroup.personnal_group = True
66
         loUserSpecificGroup.personnal_group = True
67
         loUserSpecificGroup.users.append(loNewAccount)
67
         loUserSpecificGroup.users.append(loNewAccount)
68
 
68
 
319
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
319
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
320
 
320
 
321
       loNode = loApiController.getNode(node_id)
321
       loNode = loApiController.getNode(node_id)
322
-      # loNode._lRights = list()
323
 
322
 
324
-      # SHARE IS OFF, so deactivate the document share (and do not change "shared-with" group configuration
325
-      if is_shared=='off':
326
-        loNode.is_shared = False
327
-        pm.DBSession.flush()
328
-        redirect(lurl('/document/%s#tab-accessmanagement'%(loNode.node_id)))
323
+      is_shared_b = False if is_shared=='off' else True
324
+      print(is_shared_b)
325
+      print(loNode.is_shared)
326
+      print(loNode.owner_id)
327
+      print(loCurrentUser.user_id)
328
+
329
+      # Only the node owner can modify is_shared
330
+      if is_shared_b != loNode.is_shared and loNode.owner_id != loCurrentUser.user_id:
331
+        self.back_with_error(_("You can't share a document that doesn't belong to you."))
332
+      else:
333
+        loNode.is_shared = is_shared_b
334
+        if not is_shared_b:
335
+          # SHARE IS OFF, so deactivate the document share (and do not change "shared-with" group configuration
336
+          pm.DBSession.flush()
337
+          redirect(lurl('/document/%s#tab-accessmanagement'%(loNode.node_id)))
329
 
338
 
330
-      # SHARE IS ON, so remove all current shares and set the new ones
331
-      loNode.is_shared = True
339
+      # remove all current shares and set the new ones
332
 
340
 
333
       for loRight in loNode._lRights:
341
       for loRight in loNode._lRights:
334
         pm.DBSession.delete(loRight)
342
         pm.DBSession.delete(loRight)
344
           liOldValue = ldNewRights[liGroupId]
352
           liOldValue = ldNewRights[liGroupId]
345
         ldNewRights[liGroupId] = liOldValue + pma.Rights.WRITE_ACCESS
353
         ldNewRights[liGroupId] = liOldValue + pma.Rights.WRITE_ACCESS
346
 
354
 
355
+      user_list = loApiController._getUserIdListForFiltering()
356
+      comments = pm.DBSession.query(pmd.PBNode).filter(pmd.PBNode.parent_id==node_id).\
357
+              filter((pmd.PBNode.owner_id.in_(user_list)) | (pma.user_group_table.c.user_id.in_(user_list))).\
358
+              filter(pmd.PBNode.node_type=='comment').all()
359
+      for comment in comments:
360
+          pm.DBSession.add(comment)
361
+
347
       for liGroupId, liRightLevel in ldNewRights.items():
362
       for liGroupId, liRightLevel in ldNewRights.items():
348
         loNewRight = loApiController.createRight()
363
         loNewRight = loApiController.createRight()
349
         loNewRight.group_id = liGroupId
364
         loNewRight.group_id = liGroupId
350
         loNewRight.node_id = node_id
365
         loNewRight.node_id = node_id
351
         loNewRight.rights = liRightLevel
366
         loNewRight.rights = liRightLevel
352
         loNode._lRights.append(loNewRight)
367
         loNode._lRights.append(loNewRight)
368
+        for comment in comments:
369
+            comment_right = loApiController.createRight()
370
+            comment_right.group_id = liGroupId
371
+            comment_right.node_id = comment.node_id
372
+            comment_right.rights = liRightLevel
353
 
373
 
354
       redirect(lurl('/document/%s#tab-accessmanagement'%(loNode.node_id)))
374
       redirect(lurl('/document/%s#tab-accessmanagement'%(loNode.node_id)))
355
 
375
 

+ 2 - 0
pboard/pboard/lib/auth.py 查看文件

3
 from tg.predicates import Predicate
3
 from tg.predicates import Predicate
4
 from pboard.model import DBSession as session
4
 from pboard.model import DBSession as session
5
 from pboard.model.auth import Permission, User
5
 from pboard.model.auth import Permission, User
6
+import logging as l
6
 
7
 
7
 DIRTY_canReadOrCanWriteSqlQuery = """
8
 DIRTY_canReadOrCanWriteSqlQuery = """
8
 SELECT
9
 SELECT
42
                     {"email":credentials["repoze.who.userid"], "node_id":node_id, "excluded_right_low_level": 0}
43
                     {"email":credentials["repoze.who.userid"], "node_id":node_id, "excluded_right_low_level": 0}
43
                 )
44
                 )
44
                 if has_right.rowcount == 0 :
45
                 if has_right.rowcount == 0 :
46
+                    l.info("User {} don't have read right on node {}".format(credentials["repoze.who.userid"], node_id))
45
                     self.unmet()
47
                     self.unmet()
46
 
48
 
47
 class can_write(Predicate):
49
 class can_write(Predicate):

+ 9 - 2
pboard/pboard/lib/base.py 查看文件

2
 
2
 
3
 """The base Controller API."""
3
 """The base Controller API."""
4
 
4
 
5
-from tg import TGController, tmpl_context
5
+from tg import TGController, tmpl_context, flash
6
 from tg.render import render
6
 from tg.render import render
7
-from tg import request
7
+from tg import request, redirect
8
 from tg.i18n import ugettext as _, ungettext
8
 from tg.i18n import ugettext as _, ungettext
9
 import pboard.model as model
9
 import pboard.model as model
10
 
10
 
28
         request.identity = request.environ.get('repoze.who.identity')
28
         request.identity = request.environ.get('repoze.who.identity')
29
         tmpl_context.identity = request.identity
29
         tmpl_context.identity = request.identity
30
         return TGController.__call__(self, environ, context)
30
         return TGController.__call__(self, environ, context)
31
+
32
+    def back_with_error(self, message):
33
+        flash(message)
34
+        redirect(request.headers['Referer'])
35
+
36
+def current_user():
37
+    return request.environ.get('repoze.who.identity')['user']

+ 28 - 5
pboard/pboard/lib/dbapi.py 查看文件

96
   def createNode(self, parent_id=0):
96
   def createNode(self, parent_id=0):
97
     loNode          = pbmd.PBNode()
97
     loNode          = pbmd.PBNode()
98
     loNode.owner_id = self._iCurrentUserId
98
     loNode.owner_id = self._iCurrentUserId
99
-    loNode.parent_id = parent_id
99
+    if int(parent_id)!=0:
100
+      loNode.parent_id = parent_id
100
     parent_rights = DBSession.query(pbma.Rights).filter(pbma.Rights.node_id==parent_id).all()
101
     parent_rights = DBSession.query(pbma.Rights).filter(pbma.Rights.node_id==parent_id).all()
101
     loNode.rights = parent_rights
102
     loNode.rights = parent_rights
102
     loNode.rights = [pbma.Rights(group_id=r.group_id, rights=r.rights) for r in parent_rights]
103
     loNode.rights = [pbma.Rights(group_id=r.group_id, rights=r.rights) for r in parent_rights]
125
     """
126
     """
126
     lsNodeIdFiltering = lsSqlSelectQuery % (str(self._iCurrentUserId))
127
     lsNodeIdFiltering = lsSqlSelectQuery % (str(self._iCurrentUserId))
127
 
128
 
128
-    if liNodeId!=0:
129
+    if liNodeId!=None and liNodeId!=0:
129
       return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren"))\
130
       return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren"))\
130
         .filter(pbmd.PBNode.node_id==liNodeId)\
131
         .filter(pbmd.PBNode.node_id==liNodeId)\
131
         .filter(
132
         .filter(
245
 
246
 
246
     liOwnerIdList = self._getUserIdListForFiltering()
247
     liOwnerIdList = self._getUserIdListForFiltering()
247
     
248
     
248
-    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()
249
+    # 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()
250
+    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()
251
+
252
+    loNodeList = []
253
+    for loNode in loNodeListNotFiltered:
254
+      if loNode.owner_id in self._getUserIdListForFiltering():
255
+        loNodeList.append(loNode)
256
+      else:
257
+        for loRight in loNode._lRights:
258
+          for loUser in loRight._oGroup.users:
259
+            if loUser.user_id in self._getUserIdListForFiltering():
260
+              loNodeList.append(loNode)
261
+
249
     loTreeList = []
262
     loTreeList = []
250
     loTmpDict = {}
263
     loTmpDict = {}
251
     for loNode in loNodeList:
264
     for loNode in loNodeList:
260
         # We suppose that the parent node has already been added
273
         # We suppose that the parent node has already been added
261
         # this *should* be the case, but the code does not check it
274
         # this *should* be the case, but the code does not check it
262
         if loNode.parent_id not in loTmpDict.keys():
275
         if loNode.parent_id not in loTmpDict.keys():
263
-          loTmpDict[loNode.parent_id] = self.getNode(loNode.parent_id)
264
-        loTmpDict[loNode.parent_id].appendStaticChild(loNode)
276
+          print('THE NODE =========',loNode.parent_id)
277
+          try:
278
+            loTmpDict[loNode.parent_id] = self.getNode(loNode.parent_id)
279
+          except Exception as e:
280
+            # loTreeList.append(
281
+            # FIXME - D.A. - 2014-05-22 This may be wrong code:
282
+            # we are in the case when the node parent is not shared with the current user
283
+            # So the node should be added at the root
284
+            pass
285
+        if loNode.parent_id in loTmpDict.keys():
286
+          # HACK- D.A. - 2014-05-22 - See FIXME upper
287
+          loTmpDict[loNode.parent_id].appendStaticChild(loNode)
265
   
288
   
266
     return loTreeList
289
     return loTreeList
267
 
290
 

+ 3 - 0
pboard/pboard/templates/master.mak 查看文件

172
                 <li><a href="${tg.url('/debug/identity')}"><i class="fa fa-user-md"></i>  request.identity</a></li>
172
                 <li><a href="${tg.url('/debug/identity')}"><i class="fa fa-user-md"></i>  request.identity</a></li>
173
               </ul>
173
               </ul>
174
             </li>
174
             </li>
175
+          % endif
176
+
177
+          % if request.identity:
175
             <li>
178
             <li>
176
               <form class="navbar-search  form-search" action="${tg.url('/search')}">
179
               <form class="navbar-search  form-search" action="${tg.url('/search')}">
177
                 <div class="input-append">
180
                 <div class="input-append">