Exemple #1
0
def try_remove_instructor(request, locator, user):
    # remove all roles in this course from this user: but fail if the user
    # is the last instructor in the course team
    instructors = CourseInstructorRole(locator)
    if instructors.has_user(user):
        if instructors.users_with_role().count() == 1:
            msg = {"error":_("You may not remove the last instructor from a course")}
            raise CannotOrphanCourse(msg)
        else:
            auth.remove_users(request.user, instructors, user)
Exemple #2
0
def try_remove_instructor(request, locator, user):
    # remove all roles in this course from this user: but fail if the user
    # is the last instructor in the course team
    instructors = CourseInstructorRole(locator)
    if instructors.has_user(user):
        if instructors.users_with_role().count() == 1:
            msg = {"error":_("You may not remove the last instructor from a course")}
            raise CannotOrphanCourse(msg)
        else:
            auth.remove_users(request.user, instructors, user)
Exemple #3
0
    def test_course_deletion_with_keep_instructors(self):
        """
        Tests that deleting course with keep-instructors option do not remove instructors from course.
        """
        instructor_user = User.objects.create(username='******',
                                              email='*****@*****.**')
        self.assertIsNotNone(instructor_user)

        # Add and verify instructor role for the course
        instructor_role = CourseInstructorRole(self.course.id)
        instructor_role.add_users(instructor_user)
        self.assertTrue(instructor_role.has_user(instructor_user))

        # Verify the course we are about to delete exists in the modulestore
        self.assertIsNotNone(modulestore().get_course(self.course.id))

        with mock.patch(self.YESNO_PATCH_LOCATION, return_value=True):
            call_command('delete_course', 'TestX/TS01/2015_Q1',
                         '--keep-instructors')

        self.assertIsNone(modulestore().get_course(self.course.id))
        self.assertTrue(instructor_role.has_user(instructor_user))