diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index 8cf1d1bd5b36003cd080395dc29a16c6f1d37a50..b17d599d51d68a3ea89ad2fcd3227204dc7f7b93 100644 --- a/opentech/apply/activity/messaging.py +++ b/opentech/apply/activity/messaging.py @@ -52,6 +52,7 @@ class AdapterBase: def process(self, message_type, **kwargs): message = self.message(message_type, **kwargs) + kwargs.update(self.extra_kwargs(message_type, **kwargs)) if not message: return @@ -122,17 +123,22 @@ class SlackAdapter(AdapterBase): self.target_room = settings.SLACK_DESTINATION_ROOM def message(self, message_type, **kwargs): - submission = kwargs['submission'] - request = kwargs['request'] - link = link_to(submission, request) + message = super().message(message_type, **kwargs) - message = super().message(message_type, link=link, **kwargs) + user = kwargs['user'] + submission = kwargs['submission'] slack_target = self.slack_id(submission.lead) message = ' '.join([slack_target, message]).strip() return message + def extra_kwargs(self, message_type, **kwargs): + submission = kwargs['submission'] + request = kwargs['request'] + link = link_to(submission, request) + return {'link': link} + def notify_reviewers(self, submission, **kwargs): reviewers_to_notify = [] for reviewer in submission.reviewers.all(): @@ -175,6 +181,10 @@ class EmailAdapter(AdapterBase): MESSAGES.TRANSITION: 'messages/email/transition.html', MESSAGES.DETERMINATION_OUTCOME: 'messages/email/determination.html', MESSAGES.INVITED_TO_PROPOSAL: 'messages/email/invited_to_proposal.html', + MESSAGES.READY_FOR_REVIEW: 'messages/email/ready_to_review.html', + } + recipients = { + MESSAGES.READY_FOR_REVIEW: 'get_reviewers', } def notify_comment(self, **kwargs): @@ -182,17 +192,30 @@ class EmailAdapter(AdapterBase): if not comment.private: return self.render_message('messages/email/comment.html', **kwargs) + def get_recipients(self, submission): + try: + return getattr(self, self.recipients['']) + + def get_reviewers(self, ) + return [ + [reviewer.email] + for reviewer in submission.reviewers.all() + if submission.phase.permissions.can_review(reviewer) + ] + def render_message(self, template, **kwargs): return render_to_string(template, kwargs) def send_message(self, message, submission, **kwargs): subject = submission.page.specific.subject or 'Your application to Open Technology Fund: {submission.title}'.format(submission=submission) - send_mail( - subject, - message, - submission.page.specific.from_address, - (submission.user.email,), - ) + recipients = self.get_recipients(submission) or [(submission.user.email,)] + for recipient in recipients: + send_mail( + subject, + message, + submission.page.specific.from_address, + recipient, + ) class MessengerBackend: diff --git a/opentech/apply/activity/templates/messages/email/applicant_base.html b/opentech/apply/activity/templates/messages/email/applicant_base.html new file mode 100644 index 0000000000000000000000000000000000000000..4405cab7b2cb888abf87d6418b4a630f830063d6 --- /dev/null +++ b/opentech/apply/activity/templates/messages/email/applicant_base.html @@ -0,0 +1,9 @@ +{% block salutation %} +Dear {{ submission.user.get_full_name|default:"applicant" }}, +{% endblock %} + +{% block more_info %} +You can access your application here: {{ request.scheme }}://{{ request.get_host }}{{ submission.get_absolute_url }} + +If you have any questions, please leave a message on your application or email us at info@opentechfund.org. +{% endblock %} diff --git a/opentech/apply/activity/templates/messages/email/base.html b/opentech/apply/activity/templates/messages/email/base.html index 99ea0b562ffaf80f9b9cbc5b16947e935e9f4f4a..80cc2fbbe31649c15bbc8781499e9d6550d0a24a 100644 --- a/opentech/apply/activity/templates/messages/email/base.html +++ b/opentech/apply/activity/templates/messages/email/base.html @@ -1,10 +1,8 @@ -Dear {{ submission.user.get_full_name|default:"applicant" }}, +{% block salutation %}Dear {{ user }}{% endblock %} {% block content %}{% endblock %} -You can access your application here: {{ request.scheme }}://{{ request.get_host }}{{ submission.get_absolute_url }} - -If you have any questions, please leave a message on your application or email us at info@opentechfund.org. +{% block more_info %}{% endblock %} Kind Regards, The OTF Team diff --git a/opentech/apply/activity/templates/messages/email/comment.html b/opentech/apply/activity/templates/messages/email/comment.html index c5714b9a59d2018efb1d5ce7226fc66329ed8ad8..845e7fe7598a0f7a421da871e13bcf2d6f849304 100644 --- a/opentech/apply/activity/templates/messages/email/comment.html +++ b/opentech/apply/activity/templates/messages/email/comment.html @@ -1,4 +1,4 @@ -{% extends "messages/email/base.html" %} +{% extends "messages/email/applicant_base.html" %} {% block content %} There has been a new comment on your application: {{ submission.title }} diff --git a/opentech/apply/activity/templates/messages/email/determination.html b/opentech/apply/activity/templates/messages/email/determination.html index b4bee91feb90e870f0e8a1c2b522380b0bda5f2f..b51f4dcb3c5b7fcb1a452b8c7d3ee5eb145bf617 100644 --- a/opentech/apply/activity/templates/messages/email/determination.html +++ b/opentech/apply/activity/templates/messages/email/determination.html @@ -1,4 +1,4 @@ -{% extends "messages/email/base.html" %} +{% extends "messages/email/applicant_base.html" %} {% load bleach_tags %} {% block content %} diff --git a/opentech/apply/activity/templates/messages/email/invited_to_proposal.html b/opentech/apply/activity/templates/messages/email/invited_to_proposal.html index f840778810b1783f1e29d394fbbe54fa0e503b6b..d77afc516b4b1c90ecd1be0a8d94825782b50e25 100644 --- a/opentech/apply/activity/templates/messages/email/invited_to_proposal.html +++ b/opentech/apply/activity/templates/messages/email/invited_to_proposal.html @@ -1,4 +1,4 @@ -{% extends "messages/email/base.html" %} +{% extends "messages/email/applicant_base.html" %} {% block content %} We’ve reviewed your Concept Note and think it could be a good fit for OTF funding. We would like to invite you to submit a Proposal with more details about your project. diff --git a/opentech/apply/activity/templates/messages/email/ready_to_review.html b/opentech/apply/activity/templates/messages/email/ready_to_review.html new file mode 100644 index 0000000000000000000000000000000000000000..bef3718e392b9469c8841a78749538bb794f52d6 --- /dev/null +++ b/opentech/apply/activity/templates/messages/email/ready_to_review.html @@ -0,0 +1,9 @@ +{% extends "messages/email/base.html" %} +{% block salutation %}Dear Reviewer{% endblock %} + +{% block content %} +A new proposal has been added to your review list. + +Title: {submission.title} +Link: {{ request.scheme }}://{{ request.get_host }}{{ submission.get_absolute_url }} +{% endblock %} diff --git a/opentech/apply/activity/templates/messages/email/transition.html b/opentech/apply/activity/templates/messages/email/transition.html index b11b6919c4e7c52942bdf282aec628d930b31cda..2318ef7eae0b9715e0e7f38f275e6e5655accb59 100644 --- a/opentech/apply/activity/templates/messages/email/transition.html +++ b/opentech/apply/activity/templates/messages/email/transition.html @@ -1,4 +1,4 @@ -{% extends "messages/email/base.html" %} +{% extends "messages/email/applicant_base.html" %} {% block content %} Your application has been progressed from {{ old_phase.display_name }} to {{ submission.phase }}. diff --git a/opentech/apply/activity/tests/test_messaging.py b/opentech/apply/activity/tests/test_messaging.py index 48a6260477e2a4929030012d1a88cd554fd9dbfa..a27299f5137b531caa550501822e0ccfad5f7826 100644 --- a/opentech/apply/activity/tests/test_messaging.py +++ b/opentech/apply/activity/tests/test_messaging.py @@ -9,7 +9,7 @@ from django.contrib.messages import get_messages from opentech.apply.utils.testing import make_request from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory -from opentech.apply.users.tests.factories import UserFactory +from opentech.apply.users.tests.factories import UserFactory, ReviewerFactory from ..models import Activity from ..messaging import ( @@ -209,3 +209,12 @@ class TestEmailAdapter(TestCase): adapter.process(MESSAGES.NEW_SUBMISSION, submission=submission) self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].to, [submission.user.email]) + + def test_reviewers_email(self): + adapter = EmailAdapter() + reviewers = ReviewerFactory.create_batch(4) + submission = ApplicationSubmissionFactory(status='external_review', reviewers=reviewers, workflow_stages=2) + adapter.process(MESSAGES.READY_FOR_REVIEW, submission=submission) + + self.assertEqual(len(mail.outbox), 4) diff --git a/opentech/apply/funds/tests/factories/models.py b/opentech/apply/funds/tests/factories/models.py index 98ca5a7734f8fddd1086cea5a42d5021b0cb6cd4..a305c94ab53d9432c87e9ef1fed9c8d6474fbb78 100644 --- a/opentech/apply/funds/tests/factories/models.py +++ b/opentech/apply/funds/tests/factories/models.py @@ -200,6 +200,11 @@ class ApplicationSubmissionFactory(factory.DjangoModelFactory): live_revision = None draft_revision = None + @factory.post_generation + def reviewers(self, create, reviewers, **kwargs): + if create and reviewers: + self.reviewers.set(reviewers) + @classmethod def _generate(cls, strat, params): params.update(**build_form(params))