refactor to add access control to already_existing access control routines in access.py
This commit is contained in:
@@ -114,6 +114,7 @@ def _has_access_course_desc(user, course, action):
|
||||
Valid actions:
|
||||
|
||||
'load' -- load the courseware, see inside the course
|
||||
'load_forum' -- can load and contribute to the forums (one access level for now)
|
||||
'enroll' -- enroll. Checks for enrollment window,
|
||||
ACCESS_REQUIRE_STAFF_FOR_COURSE,
|
||||
'see_exists' -- can see that the course exists.
|
||||
@@ -128,6 +129,13 @@ def _has_access_course_desc(user, course, action):
|
||||
# delegate to generic descriptor check to check start dates
|
||||
return _has_access_descriptor(user, course, 'load')
|
||||
|
||||
def can_load_forum():
|
||||
"""
|
||||
Can this user access the forums in this course?
|
||||
"""
|
||||
return (CourseEnrollment.is_enrolled(request.user, course_id) or \
|
||||
_has_staff_access_to_descriptor(user, course)
|
||||
|
||||
def can_enroll():
|
||||
"""
|
||||
First check if restriction of enrollment by login method is enabled, both
|
||||
@@ -193,6 +201,7 @@ def _has_access_course_desc(user, course, action):
|
||||
|
||||
checkers = {
|
||||
'load': can_load,
|
||||
'load_forum': can_load_forum,
|
||||
'enroll': can_enroll,
|
||||
'see_exists': see_exists,
|
||||
'staff': lambda: _has_staff_access_to_descriptor(user, course),
|
||||
|
||||
Reference in New Issue
Block a user