|
24 | 24 | get_courses_accessible_to_user |
25 | 25 | ) |
26 | 26 | from common.djangoapps.course_action_state.models import CourseRerunState |
| 27 | +from common.djangoapps.student.models.user import CourseAccessRole |
27 | 28 | from common.djangoapps.student.roles import ( |
28 | 29 | CourseInstructorRole, |
| 30 | + CourseLimitedStaffRole, |
29 | 31 | CourseStaffRole, |
30 | 32 | GlobalStaff, |
31 | 33 | OrgInstructorRole, |
@@ -188,6 +190,48 @@ def test_staff_course_listing(self): |
188 | 190 | with self.assertNumQueries(2): |
189 | 191 | list(_accessible_courses_summary_iter(self.request)) |
190 | 192 |
|
| 193 | + def test_course_limited_staff_course_listing(self): |
| 194 | + # Setup a new course |
| 195 | + course_location = self.store.make_course_key('Org', 'CreatedCourse', 'Run') |
| 196 | + CourseFactory.create( |
| 197 | + org=course_location.org, |
| 198 | + number=course_location.course, |
| 199 | + run=course_location.run |
| 200 | + ) |
| 201 | + course = CourseOverviewFactory.create(id=course_location, org=course_location.org) |
| 202 | + |
| 203 | + # Add the user as a course_limited_staff on the course |
| 204 | + CourseLimitedStaffRole(course.id).add_users(self.user) |
| 205 | + self.assertTrue(CourseLimitedStaffRole(course.id).has_user(self.user)) |
| 206 | + |
| 207 | + # Fetch accessible courses list & verify their count |
| 208 | + courses_list_by_staff, __ = get_courses_accessible_to_user(self.request) |
| 209 | + |
| 210 | + # Limited Course Staff should not be able to list courses in Studio |
| 211 | + assert len(list(courses_list_by_staff)) == 0 |
| 212 | + |
| 213 | + def test_org_limited_staff_course_listing(self): |
| 214 | + |
| 215 | + # Setup a new course |
| 216 | + course_location = self.store.make_course_key('Org', 'CreatedCourse', 'Run') |
| 217 | + CourseFactory.create( |
| 218 | + org=course_location.org, |
| 219 | + number=course_location.course, |
| 220 | + run=course_location.run |
| 221 | + ) |
| 222 | + course = CourseOverviewFactory.create(id=course_location, org=course_location.org) |
| 223 | + |
| 224 | + # Add a user as course_limited_staff on the org |
| 225 | + # This is not possible using the course roles classes but is possible via Django admin so we |
| 226 | + # insert a row into the model directly to test that scenario. |
| 227 | + CourseAccessRole.objects.create(user=self.user, org=course_location.org, role=CourseLimitedStaffRole.ROLE) |
| 228 | + |
| 229 | + # Fetch accessible courses list & verify their count |
| 230 | + courses_list_by_staff, __ = get_courses_accessible_to_user(self.request) |
| 231 | + |
| 232 | + # Limited Course Staff should not be able to list courses in Studio |
| 233 | + assert len(list(courses_list_by_staff)) == 0 |
| 234 | + |
191 | 235 | def test_get_course_list_with_invalid_course_location(self): |
192 | 236 | """ |
193 | 237 | Test getting courses with invalid course location (course deleted from modulestore). |
|
0 commit comments