Browse Source

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

Damien Accorsi 10 years ago
parent
commit
04757975da

+ 29 - 9
pboard/pboard/controllers/api.py View File

@@ -62,7 +62,7 @@ class PODPublicApiController(BaseController):
62 62
         loUserSpecificGroup = pld.PODStaticController.createGroup()
63 63
 
64 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 66
         loUserSpecificGroup.personnal_group = True
67 67
         loUserSpecificGroup.users.append(loNewAccount)
68 68
 
@@ -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
 

+ 2 - 0
pboard/pboard/lib/auth.py View File

@@ -3,6 +3,7 @@
3 3
 from tg.predicates import Predicate
4 4
 from pboard.model import DBSession as session
5 5
 from pboard.model.auth import Permission, User
6
+import logging as l
6 7
 
7 8
 DIRTY_canReadOrCanWriteSqlQuery = """
8 9
 SELECT
@@ -42,6 +43,7 @@ class can_read(Predicate):
42 43
                     {"email":credentials["repoze.who.userid"], "node_id":node_id, "excluded_right_low_level": 0}
43 44
                 )
44 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 47
                     self.unmet()
46 48
 
47 49
 class can_write(Predicate):

+ 9 - 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,10 @@ 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'])
35
+
36
+def current_user():
37
+    return request.environ.get('repoze.who.identity')['user']

+ 28 - 5
pboard/pboard/lib/dbapi.py View File

@@ -96,7 +96,8 @@ class PODUserFilteredApiController(object):
96 96
   def createNode(self, parent_id=0):
97 97
     loNode          = pbmd.PBNode()
98 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 101
     parent_rights = DBSession.query(pbma.Rights).filter(pbma.Rights.node_id==parent_id).all()
101 102
     loNode.rights = parent_rights
102 103
     loNode.rights = [pbma.Rights(group_id=r.group_id, rights=r.rights) for r in parent_rights]
@@ -125,7 +126,7 @@ class PODUserFilteredApiController(object):
125 126
     """
126 127
     lsNodeIdFiltering = lsSqlSelectQuery % (str(self._iCurrentUserId))
127 128
 
128
-    if liNodeId!=0:
129
+    if liNodeId!=None and liNodeId!=0:
129 130
       return DBSession.query(pbmd.PBNode).options(joinedload_all("_lAllChildren"))\
130 131
         .filter(pbmd.PBNode.node_id==liNodeId)\
131 132
         .filter(
@@ -245,7 +246,19 @@ class PODUserFilteredApiController(object):
245 246
 
246 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 262
     loTreeList = []
250 263
     loTmpDict = {}
251 264
     for loNode in loNodeList:
@@ -260,8 +273,18 @@ class PODUserFilteredApiController(object):
260 273
         # We suppose that the parent node has already been added
261 274
         # this *should* be the case, but the code does not check it
262 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 289
     return loTreeList
267 290
 

+ 3 - 0
pboard/pboard/templates/master.mak View File

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