From a97fceefddcadfde5baa9cb5232f1a5f0bba764f Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Mon, 19 Aug 2024 11:45:20 -0400 Subject: [PATCH 1/3] Make resubmissions more like submissions --- osf/utils/notifications.py | 15 ++++++---- osf_tests/test_reviewable.py | 28 +++++++++++++++++++ website/mails/mails.py | 5 ++++ website/reviews/listeners.py | 20 +++++++++---- ...eviews_resubmission_confirmation.html.mako | 2 +- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/osf/utils/notifications.py b/osf/utils/notifications.py index 004d0c57d30..54c16ede5c6 100644 --- a/osf/utils/notifications.py +++ b/osf/utils/notifications.py @@ -43,13 +43,18 @@ def notify_submit(resource, user, *args, **kwargs): ) -def notify_resubmit(resource, user, action, *args, **kwargs): +def notify_resubmit(resource, user, *args, **kwargs): context = get_email_template_context(resource) - reviews_signals.reviews_email.send( - creator=user, + context['referrer'] = user + recipients = list(resource.contributors) + reviews_signals.reviews_email_submit.send( + recipients=recipients, context=context, - template='reviews_resubmission_confirmation', - action=action + template=mails.REVIEWS_RESUBMISSION_CONFIRMATION, + ) + reviews_signals.reviews_email_submit_moderators_notifications.send( + timestamp=timezone.now(), + context=context ) diff --git a/osf_tests/test_reviewable.py b/osf_tests/test_reviewable.py index 6ded16a6df3..1d25ca4adac 100644 --- a/osf_tests/test_reviewable.py +++ b/osf_tests/test_reviewable.py @@ -4,6 +4,8 @@ from osf.models import Preprint from osf.utils.workflows import DefaultStates from osf_tests.factories import PreprintFactory, AuthUserFactory +from website import mails + @pytest.mark.django_db class TestReviewable: @@ -31,3 +33,29 @@ def test_state_changes(self, _): assert preprint.machine_state == DefaultStates.ACCEPTED.value from_db.refresh_from_db() assert from_db.machine_state == DefaultStates.ACCEPTED.value + + @mock.patch('website.reviews.listeners.mails.send_mail') + def test_reject_resubmission_sends_emails(self, send_mail): + user = AuthUserFactory() + preprint = PreprintFactory( + reviews_workflow='pre-moderation', + is_published=False + ) + assert preprint.machine_state == DefaultStates.INITIAL.value + assert not send_mail.call_count + + preprint.run_submit(user) + assert send_mail.call_count == 1 + assert preprint.machine_state == DefaultStates.PENDING.value + mail_template = send_mail.call_args[0][1] + assert mail_template == mails.REVIEWS_SUBMISSION_CONFIRMATION + + assert not user.notification_subscriptions.exists() + preprint.run_reject(user, 'comment') + assert preprint.machine_state == DefaultStates.REJECTED.value + + preprint.run_submit(user) # Resubmission alerts users and moderators + assert preprint.machine_state == DefaultStates.PENDING.value + mail_template = send_mail.call_args[0][1] + assert send_mail.call_count == 2 + assert mail_template == mails.REVIEWS_RESUBMISSION_CONFIRMATION diff --git a/website/mails/mails.py b/website/mails/mails.py index 8f1c46b3310..da66ad8d083 100644 --- a/website/mails/mails.py +++ b/website/mails/mails.py @@ -459,6 +459,11 @@ def get_english_article(word): subject='Confirmation of your submission to ${provider_name}' ) +REVIEWS_RESUBMISSION_CONFIRMATION = Mail( + 'reviews_resubmission_confirmation', + subject='Confirmation of your submission to ${provider_name}' +) + ACCESS_REQUEST_SUBMITTED = Mail( 'access_request_submitted', subject='An OSF user has requested access to your ${node.project_or_component}' diff --git a/website/reviews/listeners.py b/website/reviews/listeners.py index aced08f644f..fef2a25196e 100644 --- a/website/reviews/listeners.py +++ b/website/reviews/listeners.py @@ -6,9 +6,12 @@ from website.settings import OSF_PREPRINTS_LOGO, OSF_REGISTRIES_LOGO, DOMAIN -# Handle email notifications including: update comment, accept, and reject of submission. @reviews_signals.reviews_email.connect def reviews_notification(self, creator, template, context, action): + """ + Handle email notifications including: update comment, accept, and reject of submission, but not initial submission + or resubmission. + """ # Avoid AppRegistryNotReady error from website.notifications.emails import notify_global_event recipients = list(action.target.contributors) @@ -25,9 +28,14 @@ def reviews_notification(self, creator, template, context, action): ) -# Handle email notifications for a new submission. @reviews_signals.reviews_email_submit.connect -def reviews_submit_notification(self, recipients, context): +def reviews_submit_notification(self, recipients, context, template=None): + """ + Handle email notifications for a new submission or a resubmission + """ + if not template: + template = mails.REVIEWS_SUBMISSION_CONFIRMATION + # Avoid AppRegistryNotReady error from website.notifications.emails import get_user_subscriptions @@ -51,15 +59,17 @@ def reviews_submit_notification(self, recipients, context): context['provider_name'] = context['reviewable'].provider.name mails.send_mail( recipient.username, - mails.REVIEWS_SUBMISSION_CONFIRMATION, + template, user=recipient, **context ) -# Handle email notifications to notify moderators of new submissions. @reviews_signals.reviews_email_submit_moderators_notifications.connect def reviews_submit_notification_moderators(self, timestamp, context): + """ + Handle email notifications to notify moderators of new submissions or resubmission. + """ # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url diff --git a/website/templates/emails/reviews_resubmission_confirmation.html.mako b/website/templates/emails/reviews_resubmission_confirmation.html.mako index a1ac664992d..ed83e3175bb 100644 --- a/website/templates/emails/reviews_resubmission_confirmation.html.mako +++ b/website/templates/emails/reviews_resubmission_confirmation.html.mako @@ -1,6 +1,6 @@ ## -*- coding: utf-8 -*-
-

Hello ${recipient.fullname},

+

Hello ${referrer.fullname},

The ${document_type} ${reviewable.title} From def208952e9c00fce84c1c2b4496e761340bb21d Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Tue, 20 Aug 2024 16:18:47 -0400 Subject: [PATCH 2/3] update resubmission email to full template HTML --- ...eviews_resubmission_confirmation.html.mako | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/website/templates/emails/reviews_resubmission_confirmation.html.mako b/website/templates/emails/reviews_resubmission_confirmation.html.mako index ed83e3175bb..033ee3fba7b 100644 --- a/website/templates/emails/reviews_resubmission_confirmation.html.mako +++ b/website/templates/emails/reviews_resubmission_confirmation.html.mako @@ -1,39 +1,42 @@ -## -*- coding: utf-8 -*- -

-

Hello ${referrer.fullname},

-

- The ${document_type} - ${reviewable.title} - has been successfully re-submitted to ${reviewable.provider.name}. -

-

- ${reviewable.provider.name} has chosen to moderate their submissions using a - pre-moderation workflow, which means your submission is pending until accepted - by a moderator. - % if not no_future_emails: - You will receive a separate notification informing you of any status changes. +<%inherit file="notify_base.mako"/> +<%def name="content()"> +

+

+ Hello ${recipient.fullname}, +

+

+ The ${document_type} ${reviewable.title} has been successfully + re-submitted to ${reviewable.provider.name}. +

+

+ ${reviewable.provider.name} has chosen to moderate their submissions using a pre-moderation workflow, which + means your submission is pending until accepted by a moderator. + % if not no_future_emails: You will receive + a separate notification informing you of any status changes. % endif -

-

- You will ${'not receive ' if no_future_emails else 'be automatically subscribed to '}future - notification emails for this ${document_type}. -

-

- If you have been erroneously associated with "${reviewable.title}", then you - may visit the ${document_type}'s "Edit" page and remove yourself as a contributor. -

-

- For more information about ${reviewable.provider.name}, visit - ${provider_url} to learn more. To learn about the - Open Science Framework, visit https://osf.io/. -

-

For questions regarding submission criteria, please email ${provider_contact_email}

-
- Sincerely,
- Your ${reviewable.provider.name} and OSF teams -

- Center for Open Science
- 210 Ridge McIntire Road, Suite 500, Charlottesville, VA 22903 -

- Privacy Policy -
+

+

+ You will ${'not receive ' if no_future_emails else 'be automatically subscribed to '}future notification emails + for this ${document_type}. +

+

+ If you have been erroneously associated with "${reviewable.title}", then you may visit the ${document_type}'s + "Edit" page and remove yourself as a contributor. +

+

+ For more information about ${reviewable.provider.name}, visit ${provider_url} to + learn more. To learn about the Open Science Framework, visit . +

+

+ For questions regarding submission criteria, please email ${provider_contact_email} +

+
+ Sincerely, +
+ Your ${reviewable.provider.name} and OSF teams +

+ Center for Open Science
210 Ridge McIntire Road, Suite 500, Charlottesville, VA 22903 +

+ Privacy Policy +
+ From 6822ad9569d4c363ad8468876ced4aebf45a35aa Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Tue, 20 Aug 2024 16:19:37 -0400 Subject: [PATCH 3/3] make moderator digest respect resubmission in it's message --- osf/utils/notifications.py | 1 + website/reviews/listeners.py | 5 ++++- .../emails/reviews_resubmission_confirmation.html.mako | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/osf/utils/notifications.py b/osf/utils/notifications.py index 54c16ede5c6..92ea38fcf70 100644 --- a/osf/utils/notifications.py +++ b/osf/utils/notifications.py @@ -46,6 +46,7 @@ def notify_submit(resource, user, *args, **kwargs): def notify_resubmit(resource, user, *args, **kwargs): context = get_email_template_context(resource) context['referrer'] = user + context['resubmission'] = True recipients = list(resource.contributors) reviews_signals.reviews_email_submit.send( recipients=recipients, diff --git a/website/reviews/listeners.py b/website/reviews/listeners.py index fef2a25196e..27a15c2c337 100644 --- a/website/reviews/listeners.py +++ b/website/reviews/listeners.py @@ -97,7 +97,10 @@ def reviews_submit_notification_moderators(self, timestamp, context): context['message'] = f'submitted updates to "{resource.title}".' context['reviews_submission_url'] += f'&revisionId={revision_id}' else: - context['message'] = f'submitted "{resource.title}".' + if context.get('resubmission'): + context['message'] = f'resubmitted "{resource.title}".' + else: + context['message'] = f'submitted "{resource.title}".' # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription, created = NotificationSubscription.objects.get_or_create( diff --git a/website/templates/emails/reviews_resubmission_confirmation.html.mako b/website/templates/emails/reviews_resubmission_confirmation.html.mako index 033ee3fba7b..23ce18781ba 100644 --- a/website/templates/emails/reviews_resubmission_confirmation.html.mako +++ b/website/templates/emails/reviews_resubmission_confirmation.html.mako @@ -2,17 +2,17 @@ <%def name="content()">

- Hello ${recipient.fullname}, + Hello ${referrer.fullname},

The ${document_type} ${reviewable.title} has been successfully - re-submitted to ${reviewable.provider.name}. + resubmitted to ${reviewable.provider.name}.

${reviewable.provider.name} has chosen to moderate their submissions using a pre-moderation workflow, which means your submission is pending until accepted by a moderator. - % if not no_future_emails: You will receive - a separate notification informing you of any status changes. + % if not no_future_emails: + You will receive a separate notification informing you of any status changes. % endif