Commits

John Paulett committed bb6586f

Added the has_app_perm decorator for checking to see if the current user has permissions to access an application.

Comments (0)

Files changed (2)

beehat/__init__.py

-__version__ = '0.1.1'
+__version__ = '0.1.2'

beehat/decorators.py

+try:
+    from functools import update_wrapper, wraps
+except ImportError:
+    from django.utils.functional import update_wrapper, wraps  # Python 2.3, 2.4 fallback.
+
+from django.http import HttpResponseForbidden
+
+def has_app_perm(app, view_func):
+    """Returns 403 response if the request.user does not have permissions to for
+    the app.
+    """
+    def _wrapped_view(request, *args, **kwargs):
+        if request.user.has_module_perms(app):
+            return view_func(request, *args, **kwargs)
+        return HttpResponseForbidden('You lack the permission to %s ' \
+                                     '%s' % (request.method, request.path))
+    return wraps(view_func)(_wrapped_view)
+