Skip to content

Commit

Permalink
chore: notify stakeholders to add the vertical and sub-vertical on co…
Browse files Browse the repository at this point in the history
…urse publish
  • Loading branch information
hamza-56 committed Jan 23, 2025
1 parent 77319f5 commit 50e7a58
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
22 changes: 22 additions & 0 deletions course_discovery/apps/course_metadata/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.mail import EmailMessage
from django.core.mail.message import EmailMultiAlternatives
from django.template.loader import get_template
from django.urls import reverse
from django.utils.translation import gettext as _
from opaque_keys.edx.keys import CourseKey

Expand Down Expand Up @@ -444,3 +445,24 @@ def send_email_for_course_archival(report, csv_report, to_users):
email.attach("report.csv", csv_report, "text/csv")
email.content_subtype = "html"
email.send()


def send_email_for_course_vertical_assignment(course, to_users):
course_tagging_detail_url = reverse('tagging:course_tagging_detail', kwargs={'uuid': course.uuid})
full_course_tagging_url = f"{settings.DISCOVERY_BASE_URL}{course_tagging_detail_url}"

context = {
'course_name': course.title,
'course_tagging_url': full_course_tagging_url
}
html_template = 'course_metadata/email/vertical_assigment.html'
template = get_template(html_template)
html_content = template.render(context)

email = EmailMessage(
f"Action Required: Assign Verticals for Course '{course.title}'",
html_content,
settings.PUBLISHER_FROM_EMAIL,
to_users,
)
email.send()
27 changes: 27 additions & 0 deletions course_discovery/apps/course_metadata/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete, pre_save
Expand All @@ -18,6 +19,7 @@
from course_discovery.apps.core.models import Partner
from course_discovery.apps.course_metadata.constants import MASTERS_PROGRAM_TYPE_SLUG
from course_discovery.apps.course_metadata.data_loaders.api import CoursesApiDataLoader
from course_discovery.apps.course_metadata.emails import send_email_for_course_vertical_assignment
from course_discovery.apps.course_metadata.models import (
AdditionalMetadata, CertificateInfo, Course, CourseEditor, CourseEntitlement, CourseLocationRestriction, CourseRun,
Curriculum, CurriculumCourseMembership, CurriculumProgramMembership, Fact, GeoLocation, Organization, ProductMeta,
Expand Down Expand Up @@ -217,6 +219,31 @@ def update_or_create_salesforce_course(instance, created, **kwargs):
util.update_course(instance)


@receiver(post_save, sender=Course)
def notify_vertical_assignment(sender, instance, created, **kwargs):
"""
Sends email notifications to vertical managers when a new
non-draft course is created.
"""
if instance.draft or not created:
return

management_groups = getattr(settings, 'VERTICALS_MANAGEMENT_GROUPS', [])

recipients = set()
for group_name in management_groups:
try:
group = Group.objects.get(name=group_name)
recipients.update(group.user_set.values_list('email', flat=True))
except Group.DoesNotExist:
continue

if not recipients:
return

send_email_for_course_vertical_assignment(instance, recipients)


@receiver(m2m_changed, sender=Course.authoring_organizations.through)
def authoring_organizations_changed(sender, instance, action, **kwargs): # pylint: disable=unused-argument
# Only do this after an auth org has been added, the salesforce_id isn't set and it's a draft (new)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "course_metadata/email/email_base.html" %}
{% load i18n %}
{% load django_markup %}
{% block body %}
<!-- Message Body -->

<p>
A new course '{{course_name}}' has been published.
Please assign verticals and sub-verticals to this course here: {{course_tagging_url}}.
</p>

<!-- End Message Body -->
{% endblock body %}

0 comments on commit 50e7a58

Please sign in to comment.