0005-decorators-add-check_auth_level-for-automatic-increa.patch
| src/authentic2/decorators.py | ||
|---|---|---|
|
from django.core.exceptions import ValidationError
|
||
|
from django.utils import six
|
||
|
from django_rbac.exceptions import InsufficientAuthLevel
|
||
|
from . import utils, app_settings, middleware
|
||
|
from .utils import to_list, to_iter
|
||
| ... | ... | |
|
response.write(json_str)
|
||
|
return response
|
||
|
return f
|
||
|
def check_auth_level(func):
|
||
|
from django.contrib.auth.views import redirect_to_login
|
||
|
@wraps(func)
|
||
|
def wrapped(request, *args, **kwargs):
|
||
|
try:
|
||
|
request.user.auth_level = request.session.get('auth_level', 1)
|
||
|
return func(request, *args, **kwargs)
|
||
|
except InsufficientAuthLevel as e:
|
||
|
required_auth_level = e.required_level
|
||
|
next_field_value = request.get_full_path()
|
||
|
login_url = utils.get_manager_login_url() + '?auth_level=%s' % required_auth_level
|
||
|
return redirect_to_login(next_field_value, login_url)
|
||
|
return wrapped
|
||