Skip to content

Commit

Permalink
Merge pull request #13 from edx/iahmad/ENT-1698-Add-Enable/Disable-su…
Browse files Browse the repository at this point in the history
…pport-to-permission_required-decorator

ENT-1698 Added an additional argument for the permission_required decorator
  • Loading branch information
irfanuddinahmad authored Mar 22, 2019
2 parents e3bf304 + f9113fd commit db7d11d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion edx_rbac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion edx_rbac/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
from __future__ import absolute_import, unicode_literals

from functools import wraps


def permission_required(*permissions, **decorator_kwargs):
"""
Expand All @@ -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)
Expand All @@ -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

0 comments on commit db7d11d

Please sign in to comment.