add admin_required decorator
This commit is contained in:
parent
7b76ad4cc0
commit
0050c403ab
1 changed files with 11 additions and 0 deletions
|
@ -19,3 +19,14 @@ def login_required_json(function=None):
|
|||
return render_to_json_response({'status': {'code': 401, 'text': 'login required'}})
|
||||
return wraps(function)(_wrapped_view)
|
||||
|
||||
def admin_required_json(function=None):
|
||||
"""
|
||||
Decorator for views that checks that the user is logged in
|
||||
return json error if not logged in.
|
||||
"""
|
||||
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated() and request.user.get_profile().get_level() == 'admin':
|
||||
return function(request, *args, **kwargs)
|
||||
return render_to_json_response({'status': {'code': 403, 'text': 'permission denied'}})
|
||||
return wraps(function)(_wrapped_view)
|
||||
|
|
Loading…
Reference in a new issue