decorators.py 730 Bytes
Newer Older
1 2 3 4 5 6
"""
Decorators used by the support app.
"""
from functools import wraps

from django.contrib.auth.decorators import login_required
7
from django.http import HttpResponseForbidden
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

from courseware.access import has_access


def require_support_permission(func):
    """
    View decorator that requires the user to have permission to use the support UI.
    """
    @wraps(func)
    def inner(request, *args, **kwargs):  # pylint: disable=missing-docstring
        if has_access(request.user, "support", "global"):
            return func(request, *args, **kwargs)
        else:
            return HttpResponseForbidden()

    # In order to check the user's permission, he/she needs to be logged in.
    return login_required(inner)