diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index 1f0c1ec8c5..26313755cd 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -48,6 +48,8 @@ from django.db.models.query_utils import DeferredAttribute from django.db.models.sql import Query from django.dispatch import receiver +from django.template.loader import render_to_string +from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext as _ from django_cte import CTEManager @@ -87,6 +89,7 @@ from contentcuration.db.models.manager import CustomManager from contentcuration.utils.cache import delete_public_channel_cache_keys from contentcuration.utils.parser import load_json_string +from contentcuration.utils.urls import canonical_url from contentcuration.viewsets.sync.constants import ALL_CHANGES from contentcuration.viewsets.sync.constants import ALL_TABLES from contentcuration.viewsets.sync.constants import PUBLISHABLE_CHANGE_TABLES @@ -3049,6 +3052,42 @@ def notify_update_to_channel_editors(self, exclude_user_id=None): User.notify_users(editors, date=self.date_updated) + def send_resolution_email(self): + """ + Send an email to the submission author letting them know their + Community Library submission has been resolved (approved or + rejected). + """ + is_approved = self.status == community_library_submission.STATUS_APPROVED + + if is_approved: + subject_text = _("Your Community Library submission has been approved") + else: + subject_text = _("Your Community Library submission requires changes") + + subject = render_to_string( + "registration/custom_email_subject.txt", + {"subject": subject_text}, + ) + subject = "".join(subject.splitlines()) + + message = render_to_string( + "community_library/submission_resolved_email.html", + { + "name": f"{self.author.first_name} {self.author.last_name}".strip(), + "channel": self.channel, + "channel_url": canonical_url( + reverse("channel", kwargs={"channel_id": self.channel.pk}) + ), + "approved": is_approved, + "feedback_notes": self.feedback_notes, + }, + ) + + self.author.email_user( + subject, message, settings.DEFAULT_FROM_EMAIL, html_message=message + ) + @classmethod def filter_view_queryset(cls, queryset, user): if user.is_anonymous: diff --git a/contentcuration/contentcuration/templates/community_library/submission_resolved_email.html b/contentcuration/contentcuration/templates/community_library/submission_resolved_email.html new file mode 100644 index 0000000000..0ca5e7a5da --- /dev/null +++ b/contentcuration/contentcuration/templates/community_library/submission_resolved_email.html @@ -0,0 +1,31 @@ + +{% load i18n %} + +
+ + + + + {% autoescape off %} +{% blocktrans with name=name %}Hello {{ name }},{% endblocktrans %}
+ +{% blocktrans with channel_name=channel.name %}{{ channel_name }}{% endblocktrans %} ({{ channel_url }})
+ + {% if approved %} +{% translate "Available in Community Library" %}
+ {% else %} +{% translate "Your previously submitted version needs changes. Make sure you have addressed all comments before resubmitting." %}
+ {% endif %} + + {% if feedback_notes %} +{% translate "Notes from the reviewer" %}: {% blocktrans with notes=feedback_notes %}{{ notes }}{% endblocktrans %}
+ {% endif %} + +
+ {% translate "Thanks for using Kolibri Studio!" %}
+
+ {% translate "The Learning Equality Team" %}
+