Repository: svthalia/concrexit

Issue:
Send an email to the Educacie when there is a new document to approve
### Is your feature request related to a problem? Please describe.
Currently, the Educacie has to manually check if there are any documents (i.e. exams and summaries) to approve.  

### Describe the solution you'd like
Send the Educacie an email when there is a new document to approve.

### Motivation
As the committee needs to manually check, this only happens a few times a year. If a summary is submitted a few days before an exam and the committee checks after the exam week, students will not be able to access the summary in time.

### Describe alternatives you've considered
My first idea was to publish the files automatically and remove bad documents when they are checked. However, Isolde told me that a significant portion of the files is not approved, which means that this solution would result in a lot of poor quality/joke documents on the site.

### Additional context
I discussed this with Isolde and this is the solution that the Educacie prefers.



Discussion:
I like this idea, saw a few weeks ago that the documents were not checked for at least a year.

Resolving patch:
diff --git a/website/education/emails.py b/website/education/emails.py
new file mode 100644
--- /dev/null
+++ b/website/education/emails.py
@@ -0,0 +1,34 @@
+"""The emails defined by the education package."""
+import logging
+
+from django.conf import settings
+from django.core import mail
+from django.template import loader
+from django.urls import reverse
+
+logger = logging.getLogger(__name__)
+
+
+def send_document_notification(document):
+    """Send an email to a configured email.
+
+    :param document: The document we are sending the email for
+    """
+    info = (document._meta.app_label, document._meta.model_name)
+    admin_url = reverse("admin:%s_%s_change" % info, args=(document.pk,))
+
+    email_body = loader.render_to_string(
+        "education/email/document_notification.txt",
+        {
+            "document": document.name,
+            "uploader": document.uploader.get_full_name(),
+            "url": settings.BASE_URL + admin_url,
+            "course": f"{document.course.name} ({document.course.course_code})",
+        },
+    )
+    mail.EmailMessage(
+        "Education document ready for review",
+        email_body,
+        settings.DEFAULT_FROM_EMAIL,
+        [settings.EDUCATION_NOTIFICATION_ADDRESS],
+    ).send()
diff --git a/website/education/views.py b/website/education/views.py
--- a/website/education/views.py
+++ b/website/education/views.py
@@ -14,6 +14,7 @@
 from django_sendfile import sendfile
 
 from members.decorators import membership_required
+from . import emails
 from .forms import AddExamForm, AddSummaryForm
 from .models import Category, Course, Exam, Summary
 
@@ -168,6 +169,7 @@ def form_valid(self, form) -> HttpResponse:
         self.object.uploader = self.request.member
         self.object.uploader_date = datetime.now()
         self.object.save()
+        emails.send_document_notification(self.object)
         return super().form_valid(form)
 
 
@@ -193,6 +195,7 @@ def form_valid(self, form) -> HttpResponse:
         self.object.uploader = self.request.member
         self.object.uploader_date = datetime.now()
         self.object.save()
+        emails.send_document_notification(self.object)
         return super().form_valid(form)
 
 
diff --git a/website/thaliawebsite/settings.py b/website/thaliawebsite/settings.py
--- a/website/thaliawebsite/settings.py
+++ b/website/thaliawebsite/settings.py
@@ -152,6 +152,9 @@ def from_env(
 PARTNER_NOTIFICATION_ADDRESS = (
     f"{os.environ.get('ADDRESS_COLLABORATION', 'samenwerking')}@{SITE_DOMAIN}"
 )
+EDUCATION_NOTIFICATION_ADDRESS = (
+    f"{os.environ.get('ADDRESS_EDUCATION', 'educacie')}@{SITE_DOMAIN}"
+)
 
 # The scheme the app uses for oauth redirection
 APP_OAUTH_SCHEME = os.environ.get("APP_OAUTH_SCHEME", "nu.thalia")


Test patch: