def has_staff_access(self): ''' Returns whether the user has staff access to the course associated with this CourseUsageInfo instance. For performance reasons (minimizing multiple SQL calls), the value is cached within this instance. ''' if self._has_staff_access is None: self._has_staff_access = _has_access_to_course(self.user, 'staff', self.course_key) return self._has_staff_access
def get_gated_content(course, user): """ Returns the unfulfilled gated content usage keys in the given course. Arguments: course (CourseDescriptor): The course user (User): The user Returns: list: The list of gated content usage keys for the given course """ if _has_access_to_course(user, 'staff', course.id): return [] else: # Get the unfulfilled gating milestones for this course, for this user return [ m['content_id'] for m in find_gating_milestones( course.id, None, 'requires', {'id': user.id}) ]
def get_gated_content(course, user): """ Returns the unfulfilled gated content usage keys in the given course. Arguments: course (CourseDescriptor): The course user (User): The user Returns: list: The list of gated content usage keys for the given course """ if _has_access_to_course(user, 'staff', course.id): return [] else: # Get the unfulfilled gating milestones for this course, for this user return [ m['content_id'] for m in find_gating_milestones( course.id, None, 'requires', {'id': user.id} ) ]
def test_has_access_to_course(self): self.assertFalse( access._has_access_to_course(None, 'staff', self.course.id)) self.assertFalse( access._has_access_to_course(self.anonymous_user, 'staff', self.course.id)) self.assertFalse( access._has_access_to_course(self.anonymous_user, 'instructor', self.course.id)) self.assertTrue( access._has_access_to_course(self.global_staff, 'staff', self.course.id)) self.assertTrue( access._has_access_to_course(self.global_staff, 'instructor', self.course.id)) # A user has staff access if they are in the staff group self.assertTrue( access._has_access_to_course(self.course_staff, 'staff', self.course.id)) self.assertFalse( access._has_access_to_course(self.course_staff, 'instructor', self.course.id)) # A user has staff and instructor access if they are in the instructor group self.assertTrue( access._has_access_to_course(self.course_instructor, 'staff', self.course.id)) self.assertTrue( access._has_access_to_course(self.course_instructor, 'instructor', self.course.id)) # A user does not have staff or instructor access if they are # not in either the staff or the the instructor group self.assertFalse( access._has_access_to_course(self.student, 'staff', self.course.id)) self.assertFalse( access._has_access_to_course(self.student, 'instructor', self.course.id)) self.assertFalse( access._has_access_to_course(self.student, 'not_staff_or_instructor', self.course.id))