permissions.py 996 Bytes
Newer Older
Nimisha Asthagiri committed
1 2 3 4 5 6
"""
Encapsulates permissions checks for Course Blocks API
"""

from courseware.access import has_access
from student.models import CourseEnrollment
7
from student.roles import CourseStaffRole
Nimisha Asthagiri committed
8 9


10 11 12 13 14 15 16 17 18
def can_access_all_blocks(requesting_user, course_key):
    """
    Returns whether the requesting_user can access all the blocks
    in the course.
    """
    return has_access(requesting_user, CourseStaffRole.ROLE, course_key)


def can_access_others_blocks(requesting_user, course_key):
Nimisha Asthagiri committed
19 20 21 22
    """
    Returns whether the requesting_user can access the blocks for
    other users in the given course.
    """
23
    return has_access(requesting_user, CourseStaffRole.ROLE, course_key)
Nimisha Asthagiri committed
24 25


26
def can_access_self_blocks(requesting_user, course_key):
Nimisha Asthagiri committed
27
    """
28
    Returns whether the requesting_user can access own blocks.
Nimisha Asthagiri committed
29 30
    """
    return (
31 32
        (requesting_user.id and CourseEnrollment.is_enrolled(requesting_user, course_key)) or
        has_access(requesting_user, CourseStaffRole.ROLE, course_key)
Nimisha Asthagiri committed
33
    )