settings.py 1.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
"""
These callables are used by django-wiki to check various permissions
a user has on an article.
"""

from course_wiki.utils import user_is_article_course_staff


def CAN_DELETE(article, user):  # pylint: disable=invalid-name
    """Is user allowed to soft-delete article?"""
    return _is_staff_for_article(article, user)


def CAN_MODERATE(article, user):  # pylint: disable=invalid-name
    """Is user allowed to restore or purge article?"""
    return _is_staff_for_article(article, user)


def CAN_CHANGE_PERMISSIONS(article, user):  # pylint: disable=invalid-name
    """Is user allowed to change permissions on article?"""
    return _is_staff_for_article(article, user)


def CAN_ASSIGN(article, user):  # pylint: disable=invalid-name
    """Is user allowed to change owner or group of article?"""
    return _is_staff_for_article(article, user)


def CAN_ASSIGN_OWNER(article, user):  # pylint: disable=invalid-name
    """Is user allowed to change group of article to one of its own groups?"""
    return _is_staff_for_article(article, user)


def _is_staff_for_article(article, user):
    """Is the user staff for article's course wiki?"""
    return user.is_staff or user.is_superuser or user_is_article_course_staff(user, article)