From c926a13f4124603539f5dc666a601e1e89036043 Mon Sep 17 00:00:00 2001 From: "hasnain.naveed" Date: Fri, 6 Dec 2019 12:59:49 +0500 Subject: [PATCH] ENT-1961 | Making the manual enrollment reason field optional via configuration flag `ENABLE_MANUAL_ENROLLMENT_REASON_FIELD`. --- .../tests/views/test_instructor_dashboard.py | 25 +++++++++++++++++++ .../instructor/views/instructor_dashboard.py | 3 ++- .../js/instructor_dashboard/membership.js | 2 +- .../instructor_dashboard_2/membership.html | 14 ++++++----- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 6a14f60290..e3c159cfe7 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -158,6 +158,31 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT content('#field-course-organization b').contents()[0].strip() ) + @ddt.data(True, False) + def test_membership_reason_field_visibility(self, enbale_reason_field): + """ + Verify that reason field is enabled by site configuration flag 'ENABLE_MANUAL_ENROLLMENT_REASON_FIELD' + """ + + configuration_values = { + "ENABLE_MANUAL_ENROLLMENT_REASON_FIELD": enbale_reason_field + } + site = Site.objects.first() + SiteConfiguration.objects.create(site=site, values=configuration_values, enabled=True) + + url = reverse( + 'instructor_dashboard', + kwargs={ + 'course_id': six.text_type(self.course_info.id) + } + ) + response = self.client.get(url) + reason_field = '' # pylint: disable=line-too-long + if enbale_reason_field: + self.assertContains(response, reason_field) + else: + self.assertNotContains(response, reason_field) + def test_membership_site_configuration_role(self): """ Verify that the role choices set via site configuration are loaded in the membership tab diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 37b3df7d9c..cbe1a38d3e 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -550,7 +550,8 @@ def _section_membership(course, access): 'update_forum_role_membership', kwargs={'course_id': six.text_type(course_key)} ), - 'enrollment_role_choices': enrollment_role_choices + 'enrollment_role_choices': enrollment_role_choices, + 'is_reason_field_enabled': configuration_helpers.get_value('ENABLE_MANUAL_ENROLLMENT_REASON_FIELD', False) } return section_data diff --git a/lms/static/js/instructor_dashboard/membership.js b/lms/static/js/instructor_dashboard/membership.js index 1f3164dd4b..a9e5bf73a2 100644 --- a/lms/static/js/instructor_dashboard/membership.js +++ b/lms/static/js/instructor_dashboard/membership.js @@ -603,7 +603,7 @@ such that the value can be defined later than this assignment (file load order). this.$request_response_error = this.$container.find('.request-response-error'); this.$enrollment_button.click(function(event) { var sendData; - if (!batchEnroll.$reason_field.val()) { + if (batchEnroll.$reason_field.length && !batchEnroll.$reason_field.val()) { batchEnroll.fail_with_error(gettext('Reason field should not be left blank.')); return false; } diff --git a/lms/templates/instructor/instructor_dashboard_2/membership.html b/lms/templates/instructor/instructor_dashboard_2/membership.html index 2662ad958e..84ac8b7b1f 100644 --- a/lms/templates/instructor/instructor_dashboard_2/membership.html +++ b/lms/templates/instructor/instructor_dashboard_2/membership.html @@ -24,12 +24,14 @@ from openedx.core.djangolib.markup import HTML, Text - + % if section_data['is_reason_field_enabled']: + + %endif