Commit 86c851a6 by Awais Committed by Awais Qureshi

Skip Preview Stage if Course Edit Comes in After the Course-run Has Been Published.

ECOM-7811
parent 909138c5
...@@ -640,8 +640,8 @@ def send_email_for_published_course_run_editing(course_run): ...@@ -640,8 +640,8 @@ def send_email_for_published_course_run_editing(course_run):
context = { context = {
'course_name': course.title, 'course_name': course.title,
'course_team': course_team_user.get_full_name(), 'course_team': course_team_user.get_full_name() or course_team_user.username,
'recipient_name': publisher_user.get_full_name(), 'recipient_name': publisher_user.get_full_name() or publisher_user.username,
'contact_us_email': course.project_coordinator.email, 'contact_us_email': course.project_coordinator.email,
'course_run_page_url': 'https://{host}{path}'.format( 'course_run_page_url': 'https://{host}{path}'.format(
host=Site.objects.get_current().domain.strip('/'), path=object_path host=Site.objects.get_current().domain.strip('/'), path=object_path
......
...@@ -2456,6 +2456,51 @@ class CourseEditViewTests(TestCase): ...@@ -2456,6 +2456,51 @@ class CourseEditViewTests(TestCase):
response = self.client.get(self.edit_page_url + '?history_id={}'.format(100)) response = self.client.get(self.edit_page_url + '?history_id={}'.format(100))
self.assertIsNone(response.context['history_object']) self.assertIsNone(response.context['history_object'])
def test_course_with_published_course_run(self):
"""
Verify that editing course with published course run does not changed state
and an email is sent to Publisher.
"""
toggle_switch('enable_publisher_email_notifications', True)
self.client.logout()
self.client.login(username=self.course_team_role.user.username, password=USER_PASSWORD)
self._assign_permissions(self.organization_extension)
self.course.course_state.name = CourseStateChoices.Approved
self.course.course_state.save()
course_run = factories.CourseRunFactory(course=self.course, lms_course_id='course-v1:edxTest+Test342+2016Q1')
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.Publisher)
factories.CourseUserRoleFactory(course=self.course, role=PublisherUserRole.ProjectCoordinator)
post_data = self._post_data(self.organization_extension)
post_data['number'] = 'testX654'
response = self.client.post(self.edit_page_url, data=post_data)
self.assertRedirects(
response,
expected_url=reverse('publisher:publisher_course_detail', kwargs={'pk': self.course.id}),
status_code=302,
target_status_code=200
)
course_state = CourseState.objects.get(id=self.course.course_state.id)
self.assertEqual(course_state.name, CourseStateChoices.Approved)
# email send after editing.
self.assertEqual(len(mail.outbox), 1)
self.assertEqual([self.course.publisher.email], mail.outbox[0].to)
course_key = CourseKey.from_string(course_run.lms_course_id)
expected_subject = 'Changes to published course run: {title} {run_number}'.format(
title=self.course.title,
run_number=course_key.run
)
self.assertEqual(str(mail.outbox[0].subject), expected_subject)
@ddt.ddt @ddt.ddt
class CourseRunEditViewTests(TestCase): class CourseRunEditViewTests(TestCase):
......
...@@ -393,6 +393,15 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView): ...@@ -393,6 +393,15 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
self.object.organizations.remove(self.object.organizations.first()) self.object.organizations.remove(self.object.organizations.first())
self.object.organizations.add(organization_extension.organization) self.object.organizations.add(organization_extension.organization)
try:
latest_run = self.object.course_runs.latest()
except CourseRun.DoesNotExist:
latest_run = None
if latest_run and latest_run.course_run_state.name == CourseRunStateChoices.Published:
# If latest run of this course is published send an email to Publisher and don't change state.
send_email_for_published_course_run_editing(latest_run)
else:
user_role = self.object.course_user_roles.get(user=user) user_role = self.object.course_user_roles.get(user=user)
# Change course state to draft if marketing not yet reviewed or # Change course state to draft if marketing not yet reviewed or
# if marketing person updating the course. # if marketing person updating the course.
......
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