From 1f241677432ea0b5eb18e388484b7f3d2d78d2a6 Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Sat, 28 Apr 2018 21:26:43 +0200
Subject: [PATCH] Add email for EIC: replace unresponsive referee

---
 .../commands/send_refereeing_reminders.py     | 13 ++++++------
 templates/email/eic/referee_unresponsive.html | 21 +++++++++++++++++++
 templates/email/eic/referee_unresponsive.json |  8 +++++++
 3 files changed, 36 insertions(+), 6 deletions(-)
 create mode 100644 templates/email/eic/referee_unresponsive.html
 create mode 100644 templates/email/eic/referee_unresponsive.json

diff --git a/submissions/management/commands/send_refereeing_reminders.py b/submissions/management/commands/send_refereeing_reminders.py
index cc5b6b4b3..bc000bba6 100644
--- a/submissions/management/commands/send_refereeing_reminders.py
+++ b/submissions/management/commands/send_refereeing_reminders.py
@@ -15,8 +15,6 @@ class Command(BaseCommand):
     help = 'Sends all email reminders needed for Submissions undergoing refereeing'
     def handle(self, *args, **options):
         for submission in Submission.objects.open_for_reporting():
-            # fewer than 3 referees invited within 48 hours? EIC must take action
-            # TODO
             # Send reminders to referees who have not responded:
             for invitation in submission.referee_invitations.pending():
                 # 2 days after ref invite sent out: first auto reminder
@@ -49,10 +47,13 @@ class Command(BaseCommand):
                     invitation.nr_reminders += 1
                     invitation.date_last_reminded = timezone.now()
                     invitation.save()
-
-            # after 6 days of no response, EIC is automatically emailed
-            # with the suggestion of removing and replacing this referee
-            # TODO
+                # after 6 days of no response, EIC is automatically emailed
+                # with the suggestion of removing and replacing this referee
+                if workdays_between(invitation.date_invited, timezone.now()) == 6:
+                    mail_sender = DirectMailUtil(
+                        mail_code='eic/referee_unresponsive',
+                        instance=invitation)
+                    mail_sender.send()
             # one week before refereeing deadline: auto email reminder to ref
             if workdays_between(timezone.now(), submission.reporting_deadline) == 5:
                 for invitation in submission.refereeing_invitations.in_process():
diff --git a/templates/email/eic/referee_unresponsive.html b/templates/email/eic/referee_unresponsive.html
new file mode 100644
index 000000000..e784458f0
--- /dev/null
+++ b/templates/email/eic/referee_unresponsive.html
@@ -0,0 +1,21 @@
+<p>
+    Dear {{invitation.submission.editor_in_charge.get_title_display}} {{invitation.submission.editor_in_charge.user.last_name}},
+</p>
+<p>
+  Referee {{ invitation.get_title_display }} {{ invitation.last_name }}, whom you invited to referee
+  Submission
+    <br><br>
+    <a href="https://scipost.org{{invitation.submission.get_absolute_url}}">{{invitation.submission.title}}</a>
+    <br>by {{invitation.submission.author_list}}<br>
+    (see https://scipost.org{{ invitation.submission.get_absolute_url }} - first submitted {{ invitation.submission.original_submission_date|date:"d M Y" }}),<br>
+    has failed to respond to the invitation (after being sent {{invitation.nr_reminders}} reminders).
+</p>
+<p>
+  Unless you are confident that this referee will really deliver a Report, and to ensure that this Submission does not suffer from unnecessary delays in processing, you should ideally invite a replacement referee using the tols on the <a href="https://scipost.org{% url 'submissions:editorial_page' assignment.submission.arxiv_identifier_w_vn_nr %}">Editorial page</a>.
+</p>
+<p>
+    We are very grateful for your prompt action.
+    <br>
+    SciPost Editorial Administration
+</p>
+{% include 'email/_footer.html' %}
diff --git a/templates/email/eic/referee_unresponsive.json b/templates/email/eic/referee_unresponsive.json
new file mode 100644
index 000000000..d774973b6
--- /dev/null
+++ b/templates/email/eic/referee_unresponsive.json
@@ -0,0 +1,8 @@
+{
+    "subject": "SciPost: unresponsive referee",
+    "to_address": "submission.editor_in_charge.user.email",
+    "bcc_to": "admin@scipost.org",
+    "from_address_name": "SciPost Refereeing",
+    "from_address": "refereeing@scipost.org",
+    "context_object": "invitation"
+}
-- 
GitLab