refactor to add access control to already_existing access control routines in access.py

This commit is contained in:
Kevin Chugh
2013-08-20 19:42:03 -04:00
parent 013009ea24
commit a2bbb65dcf
2 changed files with 15 additions and 11 deletions

View File

@@ -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),