From f9113fdfeaaf91248a0c17bec67517801c69bdf7 Mon Sep 17 00:00:00 2001 From: irfanuddinahmad Date: Fri, 22 Mar 2019 17:37:23 +0500 Subject: [PATCH] Added enable argument for permission_required decorator --- CHANGELOG.rst | 5 +++++ edx_rbac/__init__.py | 2 +- edx_rbac/decorators.py | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 657de64..d434583 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,11 @@ Change Log .. There should always be an "Unreleased" section for changes pending release. +[0.1.8] - 2019-03-22 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* Adding an additional argument for the permission_required decorator + [0.1.7] - 2019-03-20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/edx_rbac/__init__.py b/edx_rbac/__init__.py index cd3828e..3e09625 100644 --- a/edx_rbac/__init__.py +++ b/edx_rbac/__init__.py @@ -4,6 +4,6 @@ from __future__ import absolute_import, unicode_literals -__version__ = '0.1.7' +__version__ = '0.1.8' default_app_config = 'edx_rbac.apps.EdxRbacConfig' # pylint: disable=invalid-name diff --git a/edx_rbac/decorators.py b/edx_rbac/decorators.py index 3b2a636..c070e6f 100644 --- a/edx_rbac/decorators.py +++ b/edx_rbac/decorators.py @@ -3,6 +3,8 @@ """ from __future__ import absolute_import, unicode_literals +from functools import wraps + def permission_required(*permissions, **decorator_kwargs): """ @@ -14,6 +16,7 @@ def permission_required(*permissions, **decorator_kwargs): """ def decorator(view): """Verify permissions decorator.""" + @wraps(view) def wrapped_view(self, request, *args, **kwargs): """Wrap for the view function.""" fn = decorator_kwargs.get('fn', None) @@ -33,5 +36,7 @@ def wrapped_view(self, request, *args, **kwargs): ) return view(self, request, *args, **kwargs) - return wrapped_view + + enabled = decorator_kwargs.get('enabled', False) + return wrapped_view if enabled else view return decorator