]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/lib/permissions.py
require at least one non-zero share on an expenditure
[bluechips.git] / bluechips / lib / permissions.py
index 393cc6c3048ef528f0390c651de5f0ea5d28d8b4..63c9c5c0241a495990bdd9ca4abe6aeba4391b36 100644 (file)
@@ -3,11 +3,9 @@ authkit authorization permission objects for BlueChips
 """
 
 from authkit.authenticate import AddDictToEnviron
-from authkit.authorize import NotAuthorizedError
+from authkit.authorize import NotAuthenticatedError, NotAuthorizedError
 from authkit.permissions import RequestPermission
 
-from sqlalchemy.exceptions import InvalidRequestError
-
 from bluechips import model
 from bluechips.model import meta
 
@@ -15,11 +13,10 @@ class BlueChipUser(RequestPermission):
     def check(self, app, environ, start_response):
         if 'REMOTE_USER' not in environ:
             raise NotAuthenticatedError('Not Authenticated')
-        try:
-            environ['user'] = meta.Session.query(model.User).\
-                filter_by(username=unicode(environ['REMOTE_USER'])).\
-                one()
-        except InvalidRequestError:
+        environ['user'] = meta.Session.query(model.User).\
+            filter_by(username=unicode(environ['REMOTE_USER'])).\
+            first()
+        if environ['user'] == None:
             raise NotAuthorizedError('You are not allowed access.')
         return app(environ, start_response)
 
@@ -28,8 +25,12 @@ class DummyAuthenticate(AddDictToEnviron):
     Set the authkit.authenticate environment variable so
     authkit.authorize shuts up
     """
-    def __init__(self, app):
-        super(DummyAuthenticate, self).__init__(app, {
-                'authkit.authenticate': True})
+    def __init__(self, app, app_conf):
+        newenv = {}
+        newenv['authkit.authenticate'] = True
+        newenv['authkit.config'] = {'setup.enable': True}
+        if 'fake_username' in app_conf:
+            newenv['REMOTE_USER'] = app_conf['fake_username']
+        super(DummyAuthenticate, self).__init__(app, newenv)
 
 __all__ = ['BlueChipUser', 'DummyAuthenticate']