Skip to content

Commit

Permalink
store current request on thread local storage using crum
Browse files Browse the repository at this point in the history
ENT-2002
  • Loading branch information
muhammad-ammar committed Jul 12, 2019
1 parent 43c278c commit 6f08ace
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
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.
[1.0.2] - 2019-07-12
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* store current request on thread local storage using crum.

[1.0.1] - 2019-05-27
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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__ = '1.0.1'
__version__ = '1.0.2'

default_app_config = 'edx_rbac.apps.EdxRbacConfig' # pylint: disable=invalid-name
4 changes: 4 additions & 0 deletions 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

import crum


def permission_required(*permissions, **decorator_kwargs):
"""
Expand All @@ -22,6 +24,8 @@ def wrapped_view(self, request, *args, **kwargs):
else:
obj = fn

crum.set_current_request(request)

missing_permissions = [perm for perm in permissions
if not request.user.has_perm(perm, obj)]
if any(missing_permissions):
Expand Down
3 changes: 3 additions & 0 deletions edx_rbac/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from __future__ import absolute_import, unicode_literals

import crum
from django.core.exceptions import ImproperlyConfigured
from six import string_types

Expand Down Expand Up @@ -42,6 +43,8 @@ def check_permissions(self, request):
"""
Check through permissions required and throws a permission_denied if missing any.
"""
crum.set_current_request(request)

user = request.user
missing_permissions = [perm for perm in self.get_permission_required()
if not user.has_perm(perm)]
Expand Down

0 comments on commit 6f08ace

Please sign in to comment.