Browse Source

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

Damien Accorsi 10 years ago
parent
commit
a8616e28e4
3 changed files with 29 additions and 1 deletions
  1. 9 0
      pboard/pboard/controllers/api.py
  2. 0 1
      pboard/pboard/controllers/root.py
  3. 20 0
      pboard/pboard/lib/auth.py

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

@@ -24,6 +24,7 @@ from pboard.lib.base import BaseController
24 24
 from pboard.lib   import dbapi as pld
25 25
 from pboard.model import data as pmd
26 26
 from pboard import model as pm
27
+from pboard.lib.auth import can_read, can_write
27 28
 
28 29
 __all__ = ['PODPublicApiController', 'PODApiController']
29 30
 
@@ -141,6 +142,7 @@ class PODApiController(BaseController):
141 142
       redirect(lurl('/document/%i'%(loNewNode.parent_id)))
142 143
 
143 144
     @expose()
145
+    @require(can_read())
144 146
     def get_file_content(self, node_id=None, **kw):
145 147
       if node_id==None:
146 148
         return
@@ -177,6 +179,7 @@ class PODApiController(BaseController):
177 179
         return loResultBuffer.getvalue()
178 180
 
179 181
     @expose()
182
+    @require(can_write())
180 183
     def set_parent_node(self, node_id, new_parent_id, **kw):
181 184
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
182 185
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -189,6 +192,7 @@ class PODApiController(BaseController):
189 192
       redirect(lurl('/document/%s'%(node_id)))
190 193
 
191 194
     @expose()
195
+    @require(can_write())
192 196
     def move_node_upper(self, node_id=0):
193 197
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
194 198
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -199,6 +203,7 @@ class PODApiController(BaseController):
199 203
       redirect(lurl('/document/%s'%(node_id)))
200 204
 
201 205
     @expose()
206
+    @require(can_write())
202 207
     def move_node_lower(self, node_id=0):
203 208
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
204 209
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -234,6 +239,7 @@ class PODApiController(BaseController):
234 239
       redirect(lurl('/document/%i'%(loNewNode.node_id)))
235 240
 
236 241
     @expose()
242
+    @require(can_write())
237 243
     def edit_status(self, node_id, node_status):
238 244
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
239 245
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -243,6 +249,7 @@ class PODApiController(BaseController):
243 249
       redirect(lurl('/document/%s'%(node_id)))
244 250
 
245 251
     @expose()
252
+    @require(can_write())
246 253
     def edit_label_and_content(self, node_id, data_label, data_content):
247 254
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
248 255
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -253,6 +260,7 @@ class PODApiController(BaseController):
253 260
       redirect(lurl('/document/%s'%(node_id)))
254 261
 
255 262
     @expose()
263
+    @require(can_write())
256 264
     def force_delete_node(self, node_id=None):
257 265
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
258 266
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
@@ -284,6 +292,7 @@ class PODApiController(BaseController):
284 292
       redirect(lurl('/document/%s'%(back_to_node_id)))
285 293
 
286 294
     @expose()
295
+    @require(can_write())
287 296
     def toggle_share_status(self, node_id):
288 297
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
289 298
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)

+ 0 - 1
pboard/pboard/controllers/root.py View File

@@ -134,7 +134,6 @@ class RootController(BaseController):
134 134
               row = dict(pm.DBSession.execute("select * from pod_nodes_history where node_id=:node_id and version_id=:version_id", {"node_id":liNodeId, "version_id":liVersionId}).first().items())
135 135
               del(row['version_id'])
136 136
               loCurrentNode = pbmd.PBNode(**row)
137
-              log.info(loCurrentNode)
138 137
           else:
139 138
             loCurrentNode    = loApiController.getNode(liNodeId)
140 139
         except Exception as e:

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

@@ -24,3 +24,23 @@ class can_read(Predicate):
24 24
                         and node_id = :node""", {"mail":credentials["repoze.who.userid"], "node":node_id})
25 25
                 if has_right.rowcount == 0 :
26 26
                     self.unmet()
27
+
28
+class can_write(Predicate):
29
+    message = ""
30
+
31
+    def __init__(self, **kwargs):
32
+        pass
33
+
34
+    def evaluate(self, environ, credentials):
35
+        node_id = environ['webob.adhoc_attrs']['validation']['values']['node_id']
36
+        has_right = session.execute("""
37
+                select *
38
+                from pod_group_node pgn
39
+                join pod_user_group pug on pug.group_id = pgn.group_id
40
+                join pod_user pu on pug.user_id = pu.user_id
41
+                where rights > 1
42
+                and email_address = :mail
43
+                and node_id = :node""", {"mail":credentials["repoze.who.userid"], "node":node_id})
44
+        if has_right.rowcount == 0 :
45
+            self.unmet()
46
+