2013-06-02 10:40:41 +00:00
|
|
|
# -*- 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
|
2013-06-02 10:40:41 +00:00
|
|
|
|
|
|
|
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):
|
2013-06-02 10:40:41 +00:00
|
|
|
return function(request, *args, **kwargs)
|
2015-04-28 16:12:00 +00:00
|
|
|
return render_to_json_response(json_response(status=403, text='permission denied'))
|
2013-06-02 10:40:41 +00:00
|
|
|
return wraps(function)(_wrapped_view)
|
|
|
|
return capability_required
|