Browse Source

comments inherit from parent rights

sferot 10 years ago
parent
commit
0e05b68362
3 changed files with 39 additions and 11 deletions
  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 View File

@@ -319,16 +319,24 @@ class PODApiController(BaseController):
319 319
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
320 320
 
321 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 341
       for loRight in loNode._lRights:
334 342
         pm.DBSession.delete(loRight)
@@ -344,12 +352,24 @@ class PODApiController(BaseController):
344 352
           liOldValue = ldNewRights[liGroupId]
345 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 362
       for liGroupId, liRightLevel in ldNewRights.items():
348 363
         loNewRight = loApiController.createRight()
349 364
         loNewRight.group_id = liGroupId
350 365
         loNewRight.node_id = node_id
351 366
         loNewRight.rights = liRightLevel
352 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 374
       redirect(lurl('/document/%s#tab-accessmanagement'%(loNode.node_id)))
355 375
 

+ 6 - 2
pboard/pboard/lib/base.py View File

@@ -2,9 +2,9 @@
2 2
 
3 3
 """The base Controller API."""
4 4
 
5
-from tg import TGController, tmpl_context
5
+from tg import TGController, tmpl_context, flash
6 6
 from tg.render import render
7
-from tg import request
7
+from tg import request, redirect
8 8
 from tg.i18n import ugettext as _, ungettext
9 9
 import pboard.model as model
10 10
 
@@ -28,3 +28,7 @@ class BaseController(TGController):
28 28
         request.identity = request.environ.get('repoze.who.identity')
29 29
         tmpl_context.identity = request.identity
30 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 View File

@@ -96,7 +96,11 @@ class PODUserFilteredApiController(object):
96 96
   def getNode(self, liNodeId):
97 97
     liOwnerIdList = self._getUserIdListForFiltering()
98 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 104
     return None
101 105
 
102 106