Browse Source

New predicate for read rights

sferot 11 years ago
parent
commit
2e5918103b
2 changed files with 27 additions and 1 deletions
  1. 3 1
      pboard/pboard/controllers/root.py
  2. 24 0
      pboard/pboard/lib/auth.py

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

6
 from tg import expose, flash, require, url, lurl, request, redirect, tmpl_context
6
 from tg import expose, flash, require, url, lurl, request, redirect, tmpl_context
7
 from tg.i18n import ugettext as _, lazy_ugettext as l_
7
 from tg.i18n import ugettext as _, lazy_ugettext as l_
8
 from tg import predicates
8
 from tg import predicates
9
+from pboard.lib.auth import can_read
9
 
10
 
10
 import tgext.admin.tgadminconfig as tgat
11
 import tgext.admin.tgadminconfig as tgat
11
 import tgext.admin.controller as tgac
12
 import tgext.admin.controller as tgac
113
 
114
 
114
 
115
 
115
     @expose('pboard.templates.document')
116
     @expose('pboard.templates.document')
116
-    @require(predicates.in_group('user', msg=l_('Please login to access this page')))
117
+    #@require(predicates.in_group('user', msg=l_('Please login to access this page')))
118
+    @require(can_read())
117
     def document(self, node=0, version=0, came_from=lurl('/'), highlight=''):
119
     def document(self, node=0, version=0, came_from=lurl('/'), highlight=''):
118
         """show the user dashboard"""
120
         """show the user dashboard"""
119
         loCurrentUser   = pld.PODStaticController.getCurrentUser()
121
         loCurrentUser   = pld.PODStaticController.getCurrentUser()

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

1
+# -*- coding: utf-8 -*-
2
+"""Predicates for authorizations"""
3
+from tg.predicates import Predicate
4
+from pboard.model import DBSession as session
5
+from pboard.model.auth import Permission, User
6
+
7
+class can_read(Predicate):
8
+    message = ""
9
+
10
+    def __init__(self, **kwargs):
11
+        pass
12
+
13
+    def evaluate(self, environ, credentials):
14
+        node_id = environ['webob.adhoc_attrs']['validation']['values']['node']
15
+        has_right = session.execute("""
16
+                select *
17
+                from pod_group_node pgn
18
+                join pod_user_group pug on pug.group_id = pgn.group_id
19
+                join pod_user pu on pug.user_id = pu.user_id
20
+                where rights > 0
21
+                and email_address = :mail
22
+                and node_id = :node""", {"mail":credentials["repoze.who.userid"], "node":node_id})
23
+        if has_right.rowcount == 0 :
24
+            self.unmet()