access.py 1.36 KB
Newer Older
1
from student.roles import CourseStaffRole, GlobalStaff, CourseInstructorRole
2
from student import auth
3

4

5
def has_course_access(user, course_key, role=CourseStaffRole):
cahrens committed
6
    """
7
    Return True if user allowed to access this course_id
8 9 10 11
    Note that the CMS permissions model is with respect to courses
    There is a super-admin permissions if user.is_staff is set
    Also, since we're unifying the user database between LMS and CAS,
    I'm presuming that the course instructor (formally known as admin)
12 13
    will not be in both INSTRUCTOR and STAFF groups, so we have to cascade our
    queries here as INSTRUCTOR has all the rights that STAFF do
cahrens committed
14
    """
15 16
    if GlobalStaff().has_user(user):
        return True
17
    return auth.has_access(user, role(course_key))
18 19


20
def get_user_role(user, course_id):
21
    """
22 23 24 25 26
    What type of access: staff or instructor does this user have in Studio?

    No code should use this for access control, only to quickly serialize the type of access
    where this code knows that Instructor trumps Staff and assumes the user has one or the other.

27 28
    This will not return student role because its purpose for using in Studio.

29
    :param course_id: the course_id of the course we're interested in
30
    """
31 32
    # afaik, this is only used in lti
    if auth.has_access(user, CourseInstructorRole(course_id)):
33 34 35
        return 'instructor'
    else:
        return 'staff'