Commit 0f69eb4e by Awais Committed by Awais Qureshi

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

Send an email also to the publisher role.

ECOM-7777
parent fca9ed9b
......@@ -613,3 +613,51 @@ def send_email_for_seo_review(course):
email_msg.send()
except Exception: # pylint: disable=broad-except
logger.exception('Failed to send email notifications for legal review requested of course %s', course.id)
def send_email_for_published_course_run_editing(course_run):
""" Send email when published course-run is edited.
Arguments:
course-run (Object): Course Run object
"""
try:
course = course_run.course
publisher_user = course.publisher
course_team_user = course_run.course.course_team_admin
course_key = CourseKey.from_string(course_run.lms_course_id)
txt_template = 'publisher/email/course_run/published_course_run_editing.txt'
html_template = 'publisher/email/course_run/published_course_run_editing.html'
subject = _('Changes to published course run: {title} {run_number}').format( # pylint: disable=no-member
title=course.title,
run_number=course_key.run
)
to_addresses = [publisher_user.email]
from_address = settings.PUBLISHER_FROM_EMAIL
object_path = reverse('publisher:publisher_course_run_detail', kwargs={'pk': course_run.id})
context = {
'course_name': course.title,
'course_team': course_team_user.get_full_name(),
'recipient_name': publisher_user.get_full_name(),
'contact_us_email': course.project_coordinator.email,
'course_run_page_url': 'https://{host}{path}'.format(
host=Site.objects.get_current().domain.strip('/'), path=object_path
),
'course_run_number': course_key.run,
}
template = get_template(txt_template)
plain_content = template.render(context)
template = get_template(html_template)
html_content = template.render(context)
email_msg = EmailMultiAlternatives(
subject, plain_content, from_address, to_addresses
)
email_msg.attach_alternative(html_content, 'text/html')
email_msg.send()
except Exception: # pylint: disable=broad-except
logger.exception('Failed to send email notifications for publisher course-run [%s] editing.', course_run.id)
......@@ -655,3 +655,50 @@ class SEOReviewEmailTests(TestCase):
page_url = 'https://{host}{path}'.format(host=Site.objects.get_current().domain.strip('/'), path=page_path)
self.assertIn(page_url, body)
self.assertIn('determine OFAC status', body)
class CourseRunPublishedEditEmailTests(CourseRunPublishedEmailTests):
"""
Tests for published course-run editing email functionality.
"""
def test_published_course_run_editing_email(self):
"""
Verify that on edit the published course-run email send to publisher.
"""
factories.CourseUserRoleFactory(
course=self.course, role=PublisherUserRole.ProjectCoordinator, user=self.user
)
self.course_run.lms_course_id = 'course-v1:testX+test45+2017T2'
self.course_run.save()
emails.send_email_for_published_course_run_editing(self.course_run)
course_key = CourseKey.from_string(self.course_run.lms_course_id)
subject = 'Changes to published course run: {title} {run_number}'.format(
title=self.course_run.course.title,
run_number=course_key.run
)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual([self.course.publisher.email], mail.outbox[0].to)
self.assertEqual(str(mail.outbox[0].subject), subject)
body = mail.outbox[0].body.strip()
self.assertIn('has made changes to the following published course run.', body)
page_path = reverse('publisher:publisher_course_run_detail', kwargs={'pk': self.run_state.course_run.id})
self.assertIn(page_path, body)
def test_email_with_error(self):
""" Verify that email failure logs error message."""
with LogCapture(emails.logger.name) as l:
emails.send_email_for_published_course_run_editing(self.course_run)
l.check(
(
emails.logger.name,
'ERROR',
'Failed to send email notifications for publisher course-run [{}] editing.'.format(
self.course_run.id
)
)
)
......@@ -2931,6 +2931,52 @@ class CourseRunEditViewTests(TestCase):
# Verify that `lms_course_id` not wiped.
self.assertEqual(self.new_course_run.lms_course_id, lms_course_id)
def test_published_course_run_editing_not_change_state_and_ownership(self):
""" Verify that when a user made changes in published course run, course-run state remains
same and owner ship as well."""
factories.CourseUserRoleFactory.create(course=self.course, role=PublisherUserRole.CourseTeam, user=self.user)
factories.CourseUserRoleFactory(
course=self.new_course_run.course, role=PublisherUserRole.Publisher, user=UserFactory()
)
self.new_course_run.course_run_state.name = CourseRunStateChoices.Published
self.new_course_run.course_run_state.preview_accepted = True
self.new_course_run.course_run_state.owner_role = PublisherUserRole.Publisher
self.new_course_run.course_run_state.save()
lms_course_id = 'course-v1:edX+DemoX+Demo_Course'
self.new_course_run.lms_course_id = lms_course_id
self.new_course_run.save()
self.updated_dict['min_effort'] = 2
self.updated_dict['max_effort'] = 51
response = self.client.post(self.edit_page_url, self.updated_dict)
self.assertRedirects(
response,
expected_url=reverse('publisher:publisher_course_run_detail', kwargs={'pk': self.new_course_run.id}),
status_code=302,
target_status_code=200
)
self.assertEqual(self.new_course_run.course_run_state.name, CourseRunStateChoices.Published)
self.assertEqual(self.new_course_run.course_run_state.owner_role, PublisherUserRole.Publisher)
course_key = CourseKey.from_string(self.new_course_run.lms_course_id)
# email send after editing.
self.assertEqual(len(mail.outbox), 1)
self.assertEqual([self.new_course_run.course.publisher.email], mail.outbox[0].to)
expected_subject = 'Changes to published course run: {title} {run_number}'.format(
title=self.new_course_run.course.title,
run_number=course_key.run
)
self.assertEqual(str(mail.outbox[0].subject), expected_subject)
class CourseRevisionViewTests(TestCase):
""" Tests for CourseReview"""
......
......@@ -25,6 +25,7 @@ from course_discovery.apps.ietf_language_tags.models import LanguageTag
from course_discovery.apps.publisher import emails, mixins
from course_discovery.apps.publisher.choices import CourseRunStateChoices, CourseStateChoices, PublisherUserRole
from course_discovery.apps.publisher.dataloader.create_courses import process_course
from course_discovery.apps.publisher.emails import send_email_for_published_course_run_editing
from course_discovery.apps.publisher.forms import (AdminImportCourseForm, CourseSearchForm, CustomCourseForm,
CustomCourseRunForm, CustomSeatForm)
from course_discovery.apps.publisher.models import (Course, CourseRun, CourseRunState, CourseState, CourseUserRole,
......@@ -733,9 +734,12 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
if request.POST.get('type'):
seat_form.save(changed_by=user, course_run=course_run)
# in case of any updating move the course-run state to draft.
if course_run.course_run_state.name != CourseStateChoices.Draft:
course_run.course_run_state.change_state(state=CourseStateChoices.Draft, user=user)
# in case of any updating move the course-run state to draft except draft and published state.
immutable_states = [CourseRunStateChoices.Draft, CourseRunStateChoices.Published]
course_run_state = course_run.course_run_state
if course_run_state.name not in immutable_states:
course_run_state.change_state(state=CourseStateChoices.Draft, user=user)
if course_run.lms_course_id and lms_course_id != course_run.lms_course_id:
emails.send_email_for_studio_instance_created(course_run)
......@@ -745,8 +749,14 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
# after editing course owner role will be changed to current user
user_role = course_run.course.course_user_roles.get(user=user).role
if user_role != course_run.course_run_state.owner_role:
course_run.course_run_state.change_owner_role(user_role)
if (
user_role != course_run_state.owner_role and
course_run_state.name != CourseRunStateChoices.Published
):
course_run_state.change_owner_role(user_role)
if CourseRunStateChoices.Published == course_run_state.name:
send_email_for_published_course_run_editing(course_run)
return HttpResponseRedirect(reverse(self.success_url, kwargs={'pk': course_run.id}))
except Exception as e: # pylint: disable=broad-except
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-05 14:41+0500\n"
"POT-Creation-Date: 2017-06-05 17:17+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: apps/api/filters.py
#, python-brace-format
......@@ -566,6 +566,11 @@ msgstr ""
msgid "Legal Team"
msgstr ""
#: apps/publisher/emails.py
#, python-brace-format
msgid "Changes to published course run: {title} {run_number}"
msgstr ""
#: apps/publisher/forms.py
msgid "Remove Image"
msgstr ""
......@@ -2754,6 +2759,8 @@ msgstr ""
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/course_run/send_for_review.html
#: templates/publisher/email/course_run/send_for_review.txt
#: templates/publisher/email/decline_preview.html
......@@ -2799,6 +2806,8 @@ msgstr ""
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/decline_preview.html
#: templates/publisher/email/decline_preview.txt
#: templates/publisher/email/studio_instance_created.html
......@@ -2815,6 +2824,7 @@ msgstr ""
#: templates/publisher/email/course_run/preview_accepted.html
#: templates/publisher/email/course_run/preview_available.html
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/send_for_review.html
#: templates/publisher/email/studio_instance_created.html
#, python-format
......@@ -2830,6 +2840,7 @@ msgstr ""
#: templates/publisher/email/course_run/preview_accepted.txt
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/course_run/send_for_review.txt
#: templates/publisher/email/studio_instance_created.txt
#, python-format
......@@ -2992,6 +3003,23 @@ msgstr ""
msgid "View this About page on edx.org. %(preview_url)s"
msgstr ""
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#, python-format
msgid ""
"%(course_team)s has made changes to the following published course run."
msgstr ""
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
msgid "View the course run in Publisher"
msgstr ""
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
msgid "to make changes and republish the course run."
msgstr ""
#: templates/publisher/email/course_run/send_for_review.html
#, python-format
msgid ""
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-05 14:41+0500\n"
"POT-Creation-Date: 2017-06-05 17:17+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: static/js/catalogs-change-form.js
msgid "Preview"
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-05 14:41+0500\n"
"POT-Creation-Date: 2017-06-05 17:17+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: apps/api/filters.py
......@@ -693,6 +693,13 @@ msgstr "Çöürsé téäm Ⱡ'σяєм ιρѕυм ∂σłσя #"
msgid "Legal Team"
msgstr "Légäl Téäm Ⱡ'σяєм ιρѕυм ∂σłσ#"
#: apps/publisher/emails.py
#, python-brace-format
msgid "Changes to published course run: {title} {run_number}"
msgstr ""
"Çhängés tö püßlïshéd çöürsé rün: {title} {run_number} Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт"
" αмєт, ¢σηѕє¢тєтυя#"
#: apps/publisher/forms.py
msgid "Remove Image"
msgstr "Rémövé Ìmägé Ⱡ'σяєм ιρѕυм ∂σłσя ѕ#"
......@@ -3258,6 +3265,8 @@ msgstr ""
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/course_run/send_for_review.html
#: templates/publisher/email/course_run/send_for_review.txt
#: templates/publisher/email/decline_preview.html
......@@ -3314,6 +3323,8 @@ msgstr ""
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/decline_preview.html
#: templates/publisher/email/decline_preview.txt
#: templates/publisher/email/studio_instance_created.html
......@@ -3330,6 +3341,7 @@ msgstr "Thänks, Ⱡ'σяєм ιρѕυм #"
#: templates/publisher/email/course_run/preview_accepted.html
#: templates/publisher/email/course_run/preview_available.html
#: templates/publisher/email/course_run/published.html
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/send_for_review.html
#: templates/publisher/email/studio_instance_created.html
#, python-format
......@@ -3347,6 +3359,7 @@ msgstr ""
#: templates/publisher/email/course_run/preview_accepted.txt
#: templates/publisher/email/course_run/preview_available.txt
#: templates/publisher/email/course_run/published.txt
#: templates/publisher/email/course_run/published_course_run_editing.txt
#: templates/publisher/email/course_run/send_for_review.txt
#: templates/publisher/email/studio_instance_created.txt
#, python-format
......@@ -3599,6 +3612,28 @@ msgstr ""
"Vïéw thïs Àßöüt pägé ön édx.örg. %(preview_url)s Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт "
"αмєт, ¢σηѕє¢тєтυ#"
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
#, python-format
msgid ""
"%(course_team)s has made changes to the following published course run."
msgstr ""
"%(course_team)s häs mädé çhängés tö thé föllöwïng püßlïshéd çöürsé rün. "
"Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
msgid "View the course run in Publisher"
msgstr ""
"Vïéw thé çöürsé rün ïn Püßlïshér Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тє#"
#: templates/publisher/email/course_run/published_course_run_editing.html
#: templates/publisher/email/course_run/published_course_run_editing.txt
msgid "to make changes and republish the course run."
msgstr ""
"tö mäké çhängés änd répüßlïsh thé çöürsé rün. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя #"
#: templates/publisher/email/course_run/send_for_review.html
#, python-format
msgid ""
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-05 14:41+0500\n"
"POT-Creation-Date: 2017-06-05 17:17+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/js/catalogs-change-form.js
......
{% extends "publisher/email/email_base.html" %}
{% load i18n %}
{% block body %}
<!-- Message Body -->
<p>
{% blocktrans trimmed %}
Dear {{ recipient_name }},
{% endblocktrans %}
</p>
<p>
{% blocktrans trimmed %}
{{ course_team }} has made changes to the following published course run.
{% endblocktrans %}
</p>
<p>
{{ course_name }} {{ course_run_number }} <a href="{{ course_run_page_url }}">{% trans "View the course run in Publisher" %}</a> {% trans "to make changes and republish the course run." %}
</p>
{% comment %}Translators: It's closing of mail.{% endcomment %}
{% trans "Thanks," %}<br>
{{ course_team }}
{% blocktrans trimmed %}
<p>Note: This email address is unable to receive replies. For questions or comments, contact {{ contact_us_email }}.</p>
{% endblocktrans %}
<!-- End Message Body -->
{% endblock body %}
{% load i18n %}
{% blocktrans trimmed %}
Dear {{ recipient_name }},
{% endblocktrans %}
{% blocktrans trimmed %}
{{ course_team }} has made changes to the following published course run.
{% endblocktrans %}
{{ course_name }} {{ course_run_number }} <a href="{{ course_run_page_url }}">{% trans "View the course run in Publisher" %}</a> {% trans "to make changes and republish the course run." %}
{% comment %}Translators: It's closing of mail.{% endcomment %}
{% trans "Thanks," %}<br>
{{ course_team }}
{% blocktrans trimmed %}
Note: This email address is unable to receive replies. For questions or comments, contact {{ contact_us_email }}.
{% endblocktrans %}
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