Commit 7bb0d5f5 by Usman Khalid

Merge pull request #5174 from edx/usman/tnl-208-instructor-permissions

Added instructor persmission checking to _has_access_error_desc() in courseware.access
parents 11525556 660cdf79
...@@ -230,7 +230,8 @@ def _has_access_error_desc(user, action, descriptor, course_key): ...@@ -230,7 +230,8 @@ def _has_access_error_desc(user, action, descriptor, course_key):
checkers = { checkers = {
'load': check_for_staff, 'load': check_for_staff,
'staff': check_for_staff 'staff': check_for_staff,
'instructor': lambda: _has_instructor_access_to_descriptor(user, descriptor, course_key)
} }
return _dispatch(checkers, action, user, descriptor) return _dispatch(checkers, action, user, descriptor)
......
...@@ -83,17 +83,34 @@ class AccessTestCase(TestCase): ...@@ -83,17 +83,34 @@ class AccessTestCase(TestCase):
self.assertRaises(ValueError, access._has_access_string, user, 'not_staff', 'global', self.course.course_key) self.assertRaises(ValueError, access._has_access_string, user, 'not_staff', 'global', self.course.course_key)
def test__has_access_error_desc(self):
descriptor = Mock()
self.assertFalse(access._has_access_error_desc(self.student, 'load', descriptor, self.course.course_key))
self.assertTrue(access._has_access_error_desc(self.course_staff, 'load', descriptor, self.course.course_key))
self.assertTrue(access._has_access_error_desc(self.course_instructor, 'load', descriptor, self.course.course_key))
self.assertFalse(access._has_access_error_desc(self.student, 'staff', descriptor, self.course.course_key))
self.assertTrue(access._has_access_error_desc(self.course_staff, 'staff', descriptor, self.course.course_key))
self.assertTrue(access._has_access_error_desc(self.course_instructor, 'staff', descriptor, self.course.course_key))
self.assertFalse(access._has_access_error_desc(self.student, 'instructor', descriptor, self.course.course_key))
self.assertFalse(access._has_access_error_desc(self.course_staff, 'instructor', descriptor, self.course.course_key))
self.assertTrue(access._has_access_error_desc(self.course_instructor, 'instructor', descriptor, self.course.course_key))
with self.assertRaises(ValueError):
access._has_access_error_desc(self.course_instructor, 'not_load_or_staff', descriptor, self.course.course_key)
def test__has_access_descriptor(self): def test__has_access_descriptor(self):
# TODO: override DISABLE_START_DATES and test the start date branch of the method # TODO: override DISABLE_START_DATES and test the start date branch of the method
user = Mock() user = Mock()
date = Mock() descriptor = Mock()
date.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1) # make sure the start time is in the past
# Always returns true because DISABLE_START_DATES is set in test.py # Always returns true because DISABLE_START_DATES is set in test.py
self.assertTrue(access._has_access_descriptor(user, 'load', date)) self.assertTrue(access._has_access_descriptor(user, 'load', descriptor))
self.assertTrue(access._has_access_descriptor(user, 'instructor', date)) self.assertTrue(access._has_access_descriptor(user, 'instructor', descriptor))
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
access._has_access_descriptor(user, 'not_load_or_staff', date) access._has_access_descriptor(user, 'not_load_or_staff', descriptor)
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test__has_access_descriptor_staff_lock(self): def test__has_access_descriptor_staff_lock(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment