浏览代码

comments inherit from parent rights

sferot 11 年前
父节点
当前提交
0e05b68362
共有 3 个文件被更改,包括 39 次插入11 次删除
  1. 28 8
      pboard/pboard/controllers/api.py
  2. 6 2
      pboard/pboard/lib/base.py
  3. 5 1
      pboard/pboard/lib/dbapi.py

+ 28 - 8
pboard/pboard/controllers/api.py 查看文件

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
 

+ 6 - 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'])

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

96
   def getNode(self, liNodeId):
96
   def getNode(self, liNodeId):
97
     liOwnerIdList = self._getUserIdListForFiltering()
97
     liOwnerIdList = self._getUserIdListForFiltering()
98
     if liNodeId!=0:
98
     if liNodeId!=0:
99
-      return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren")).filter(pbmd.PBNode.node_id==liNodeId).filter(pbmd.PBNode.owner_id.in_(liOwnerIdList)).one()
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()
100
     return None
104
     return None
101
 
105
 
102
 
106