Commit 54bedfae by Awais Committed by Awais Qureshi

Course run key getting blanked issue fixed.

ECOM-7411
parent 7873d2d4
...@@ -271,6 +271,12 @@ class CustomCourseRunForm(CourseRunForm): ...@@ -271,6 +271,12 @@ class CustomCourseRunForm(CourseRunForm):
return None return None
def __init__(self, *args, **kwargs):
is_project_coordinator = kwargs.pop('is_project_coordinator', None)
super(CustomCourseRunForm, self).__init__(*args, **kwargs)
if not is_project_coordinator:
self.fields['lms_course_id'].widget = forms.HiddenInput()
class SeatForm(BaseCourseForm): class SeatForm(BaseCourseForm):
""" Course Seat Form. """ """ Course Seat Form. """
......
...@@ -1937,6 +1937,8 @@ class CourseRunEditViewTests(TestCase): ...@@ -1937,6 +1937,8 @@ class CourseRunEditViewTests(TestCase):
self.group = self.organization_extension.group self.group = self.organization_extension.group
self.user.groups.add(self.group) self.user.groups.add(self.group)
self.group_project_coordinator = Group.objects.get(name=PROJECT_COORDINATOR_GROUP_NAME)
self.course = factories.CourseFactory() self.course = factories.CourseFactory()
self.course_run = factories.CourseRunFactory(course=self.course) self.course_run = factories.CourseRunFactory(course=self.course)
self.seat = factories.SeatFactory(course_run=self.course_run, type=Seat.VERIFIED, price=2) self.seat = factories.SeatFactory(course_run=self.course_run, type=Seat.VERIFIED, price=2)
...@@ -2284,7 +2286,7 @@ class CourseRunEditViewTests(TestCase): ...@@ -2284,7 +2286,7 @@ class CourseRunEditViewTests(TestCase):
) )
response = self.client.get(self.edit_page_url) response = self.client.get(self.edit_page_url)
self.assertNotContains(response, 'name="lms_course_id"') self.assertContains(response, '<input id="id_lms_course_id" name="lms_course_id" type="hidden"')
self.assertContains(response, 'Course Run Key') self.assertContains(response, 'Course Run Key')
self.assertContains(response, 'STUDIO URL') self.assertContains(response, 'STUDIO URL')
...@@ -2294,6 +2296,40 @@ class CourseRunEditViewTests(TestCase): ...@@ -2294,6 +2296,40 @@ class CourseRunEditViewTests(TestCase):
self.new_course_run.save() self.new_course_run.save()
response = self.client.get(self.edit_page_url) response = self.client.get(self.edit_page_url)
self.assertContains(
response, '<input id="id_lms_course_id" name="lms_course_id" type="hidden"'
)
self.assertContains(response, '<a class="studio-link"')
def test_studio_instance_with_project_coordinator(self):
"""
Verify that PC can see the course-key input field. And on post course-key remains in db.
"""
pc_user = UserFactory()
pc_user.groups.add(self.group_project_coordinator)
pc_user.groups.add(self.organization_extension.group)
assign_perm(
OrganizationExtension.EDIT_COURSE_RUN, self.organization_extension.group, self.organization_extension
)
self.client.logout()
self.client.login(username=pc_user.username, password=USER_PASSWORD)
self.new_course_run.lms_course_id = 'course-v1:edxTest+Test342+2016Q1'
self.new_course_run.save()
response = self.client.get(self.edit_page_url)
self.assertContains(response, self.new_course_run.lms_course_id)
self.assertContains(
response, '<input class="field-input input-text" id="id_lms_course_id" name="lms_course_id"'
)
self.assertNotContains(response, '<a class="studio-link"')
data = {'full_description': 'This is testing description.', 'image': ''}
updated_dict = self._post_data(data, self.new_course, None, None)
self.client.post(self.edit_page_url, updated_dict)
response = self.client.get(self.edit_page_url)
self.assertContains(response, self.new_course_run.lms_course_id) self.assertContains(response, self.new_course_run.lms_course_id)
def test_price_hidden_without_seat(self): def test_price_hidden_without_seat(self):
......
...@@ -529,6 +529,7 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix ...@@ -529,6 +529,7 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
'publisher_add_instructor_feature': waffle.switch_is_active('publisher_add_instructor_feature'), 'publisher_add_instructor_feature': waffle.switch_is_active('publisher_add_instructor_feature'),
'is_internal_user': mixins.check_roles_access(self.request.user), 'is_internal_user': mixins.check_roles_access(self.request.user),
'edit_mode': True, 'edit_mode': True,
'is_project_coordinator': is_project_coordinator_user(self.request.user),
} }
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
...@@ -541,7 +542,9 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix ...@@ -541,7 +542,9 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
organization=context.get('organization'), organization=context.get('organization'),
edit_mode=True edit_mode=True
) )
context['run_form'] = self.run_form(instance=course_run) context['run_form'] = self.run_form(
instance=course_run, is_project_coordinator=context.get('is_project_coordinator')
)
context['seat_form'] = self.seat_form(instance=course_run.seats.first()) context['seat_form'] = self.seat_form(instance=course_run.seats.first())
context['breadcrumbs'] = make_bread_crumbs( context['breadcrumbs'] = make_bread_crumbs(
...@@ -570,7 +573,9 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix ...@@ -570,7 +573,9 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
organization=context.get('organization'), organization=context.get('organization'),
edit_mode=True edit_mode=True
) )
run_form = self.run_form(request.POST, instance=course_run) run_form = self.run_form(
request.POST, instance=course_run, is_project_coordinator=context.get('is_project_coordinator')
)
seat_form = self.seat_form(request.POST, instance=course_run.seats.first()) seat_form = self.seat_form(request.POST, instance=course_run.seats.first())
if course_form.is_valid() and run_form.is_valid() and seat_form.is_valid(): if course_form.is_valid() and run_form.is_valid() and seat_form.is_valid():
try: try:
......
...@@ -196,9 +196,9 @@ ...@@ -196,9 +196,9 @@
</div> </div>
<div class="col col-6"> <div class="col col-6">
<label class="field-label ">{{ run_form.lms_course_id.label_tag }} <span class="required">*</span></label> <label class="field-label ">{{ run_form.lms_course_id.label_tag }} <span class="required">*</span></label>
{% if is_internal_user %} {{ run_form.lms_course_id }}
{{ run_form.lms_course_id }}
{% else %} {% if not is_project_coordinator %}
<div class="studio-url"> <div class="studio-url">
<span class="studio-url-heading">{% trans "STUDIO URL" %} - </span> <span class="studio-url-heading">{% trans "STUDIO URL" %} - </span>
{% if course_run.studio_url %} {% if course_run.studio_url %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment