From 63c6eeff4ca56bb187d55d984f50f91bd0103b61 Mon Sep 17 00:00:00 2001
From: Fredrik Jonsson <frjo@xdeb.org>
Date: Mon, 25 May 2020 09:19:02 +0200
Subject: [PATCH] Add setting SEND_READY_FOR_REVIEW, defaults to true but if
 set to false will stop reiewer notifications.

---
 hypha/apply/activity/messaging.py             | 22 +++++++++++++++++--
 .../messages/email/batch_ready_to_review.html |  2 +-
 .../messages/email/ready_to_review.html       |  1 -
 hypha/settings/base.py                        |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/hypha/apply/activity/messaging.py b/hypha/apply/activity/messaging.py
index bebe80f3f..e73025fe5 100644
--- a/hypha/apply/activity/messaging.py
+++ b/hypha/apply/activity/messaging.py
@@ -661,8 +661,8 @@ class EmailAdapter(AdapterBase):
         MESSAGES.DETERMINATION_OUTCOME: 'handle_determination',
         MESSAGES.BATCH_DETERMINATION_OUTCOME: 'handle_batch_determination',
         MESSAGES.INVITED_TO_PROPOSAL: 'messages/email/invited_to_proposal.html',
-        MESSAGES.BATCH_READY_FOR_REVIEW: 'messages/email/batch_ready_to_review.html',
-        MESSAGES.READY_FOR_REVIEW: 'messages/email/ready_to_review.html',
+        MESSAGES.BATCH_READY_FOR_REVIEW: 'handle_batch_ready_for_review',
+        MESSAGES.READY_FOR_REVIEW: 'handle_ready_for_review',
         MESSAGES.PARTNERS_UPDATED: 'partners_updated_applicant',
         MESSAGES.PARTNERS_UPDATED_PARTNER: 'partners_updated_partner',
         MESSAGES.UPLOAD_CONTRACT: 'messages/email/contract_uploaded.html',
@@ -746,6 +746,24 @@ class EmailAdapter(AdapterBase):
                 **kwargs
             )
 
+    def handle_ready_for_review(self, request, source, **kwargs):
+        if settings.SEND_READY_FOR_REVIEW:
+            return self.render_message(
+                'messages/email/ready_to_review.html',
+                source=source,
+                request=request,
+                **kwargs
+            )
+
+    def handle_batch_ready_for_review(self, request, sources, **kwargs):
+        if settings.SEND_READY_FOR_REVIEW:
+            return self.render_message(
+                'messages/email/batch_ready_to_review.html',
+                sources=sources,
+                request=request,
+                **kwargs
+            )
+
     def notify_comment(self, **kwargs):
         comment = kwargs['comment']
         source = kwargs['source']
diff --git a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html
index 19ae54272..1591a1ab3 100644
--- a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html
+++ b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html
@@ -2,7 +2,7 @@
 {% block salutation %}Dear Reviewer,{% endblock %}
 
 {% block content %}
-New proposals have been added to your review list.
+New applications have been added to your review list.
 {% for submission in sources %}
 
 Title: {{ submission.title }}
diff --git a/hypha/apply/activity/templates/messages/email/ready_to_review.html b/hypha/apply/activity/templates/messages/email/ready_to_review.html
index d2713c6c5..4aa9a622a 100644
--- a/hypha/apply/activity/templates/messages/email/ready_to_review.html
+++ b/hypha/apply/activity/templates/messages/email/ready_to_review.html
@@ -1,6 +1,5 @@
 {% extends "messages/email/base.html" %}
 {% block salutation %}Dear Reviewer,{% endblock %}
-
 {% block content %}
 This application is awaiting your review.
 
diff --git a/hypha/settings/base.py b/hypha/settings/base.py
index 1ae71ef9d..8b93ec7d4 100644
--- a/hypha/settings/base.py
+++ b/hypha/settings/base.py
@@ -524,6 +524,9 @@ if not SEND_MESSAGES:
     from django.contrib.messages import constants as message_constants
     MESSAGE_LEVEL = message_constants.DEBUG
 
+
+SEND_READY_FOR_REVIEW = env.get('SEND_READY_FOR_REVIEW', 'true').lower() == 'true'
+
 SLACK_DESTINATION_URL = env.get('SLACK_DESTINATION_URL', None)
 SLACK_DESTINATION_ROOM = env.get('SLACK_DESTINATION_ROOM', None)
 SLACK_DESTINATION_ROOM_COMMENTS = env.get('SLACK_DESTINATION_ROOM_COMMENTS', None)
-- 
GitLab