pandora/pandora/user/decorators.py

17 lines
691 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
try:
from django.contrib.auth.decorators import wraps
except:
from django.utils.functional import wraps
2016-02-20 09:06:41 +00:00
from oxdjango.shortcuts import render_to_json_response, json_response
def capability_required_json(capability):
def capability_required(function=None):
def _wrapped_view(request, *args, **kwargs):
if request.user.is_authenticated() and \
2016-02-19 16:34:15 +00:00
request.user.profile.capability(capability):
return function(request, *args, **kwargs)
return render_to_json_response(json_response(status=403, text='permission denied'))
return wraps(function)(_wrapped_view)
return capability_required