From 1d85659b1332408b1e7d48b178b5a8edca3b5026 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Mon, 10 Nov 2014 16:03:25 -0500 Subject: [PATCH] Prevent instructors from accidentally downgrading enrollment modes through instructor dash TNL-804 --- lms/djangoapps/instructor/enrollment.py | 8 +++-- lms/djangoapps/instructor/tests/test_api.py | 32 +++++++++++++++++++ .../courseware/instructor_dashboard.html | 23 +++---------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index f0198e92a5..1e9735ee11 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -26,9 +26,12 @@ class EmailEnrollmentState(object): exists_user = User.objects.filter(email=email).exists() if exists_user: user = User.objects.get(email=email) - exists_ce = CourseEnrollment.is_enrolled(user, course_id) + mode, is_active = CourseEnrollment.enrollment_mode_for_user(user, course_id) + # is_active is `None` if the user is not enrolled in the course + exists_ce = is_active is not None and is_active full_name = user.profile.name else: + mode = None exists_ce = False full_name = None ceas = CourseEnrollmentAllowed.objects.filter(course_id=course_id, email=email).all() @@ -40,6 +43,7 @@ class EmailEnrollmentState(object): self.allowed = exists_allowed self.auto_enroll = bool(state_auto_enroll) self.full_name = full_name + self.mode = mode def __repr__(self): return "{}(user={}, enrollment={}, allowed={}, auto_enroll={})".format( @@ -84,7 +88,7 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal previous_state = EmailEnrollmentState(course_id, student_email) if previous_state.user: - CourseEnrollment.enroll_by_email(student_email, course_id) + CourseEnrollment.enroll_by_email(student_email, course_id, previous_state.mode) if email_students: email_params['message'] = 'enrolled_enroll' email_params['email_address'] = student_email diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index feda24b885..50d2bf2545 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -1050,6 +1050,38 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase): ) ) + def test_enroll_already_enrolled_student(self): + """ + Ensure that already enrolled "verified" students cannot be downgraded + to "honor" + """ + course_enrollment = CourseEnrollment.objects.get( + user=self.enrolled_student, course_id=self.course.id + ) + # make this enrollment "verified" + course_enrollment.mode = u'verified' + course_enrollment.save() + self.assertEqual(course_enrollment.mode, u'verified') + + # now re-enroll the student through the instructor dash + url = reverse( + 'students_update_enrollment', + kwargs={'course_id': self.course.id.to_deprecated_string()}, + ) + params = { + 'identifiers': self.enrolled_student.email, + 'action': 'enroll', + 'email_students': True, + } + response = self.client.post(url, params) + self.assertEqual(response.status_code, 200) + + # affirm that the student is still in "verified" mode + course_enrollment = CourseEnrollment.objects.get( + user=self.enrolled_student, course_id=self.course.id + ) + self.assertEqual(course_enrollment.mode, u"verified") + @ddt.ddt @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) diff --git a/lms/templates/courseware/instructor_dashboard.html b/lms/templates/courseware/instructor_dashboard.html index 606b5fbc01..4439fc6ba7 100644 --- a/lms/templates/courseware/instructor_dashboard.html +++ b/lms/templates/courseware/instructor_dashboard.html @@ -192,10 +192,8 @@ function goto( mode)

${_("Note: some of these buttons are known to time out for larger " - "courses. We have temporarily disabled those features for courses " - "with more than {max_enrollment} students. We are urgently working on " - "fixing this issue. Thank you for your patience as we continue " - "working to improve the platform!").format( + "courses. We have disabled those features for courses " + "with more than {max_enrollment} students.").format( max_enrollment=settings.FEATURES['MAX_ENROLLMENT_INSTR_BUTTONS'] )}

@@ -428,10 +426,8 @@ function goto( mode)

${_("Note: some of these buttons are known to time out for larger " - "courses. We have temporarily disabled those features for courses " - "with more than {max_enrollment} students. We are urgently working on " - "fixing this issue. Thank you for your patience as we continue " - "working to improve the platform!").format( + "courses. We have disabled those features for courses " + "with more than {max_enrollment} students.").format( max_enrollment=settings.FEATURES['MAX_ENROLLMENT_INSTR_BUTTONS'] )}

@@ -461,17 +457,6 @@ function goto( mode)
%endif -

${_("Batch Enrollment")}

-

${_("Enroll or un-enroll one or many students: enter emails, separated by new lines or commas;")}

- -

- ${_("Notify students by email")} -

- ${_("Auto-enroll students when they activate")} - -

- - %endif ##-----------------------------------------------------------------------------