Skip to content

Commit

Permalink
Make resubmissions more like submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Aug 19, 2024
1 parent 3920a29 commit 061642c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
15 changes: 10 additions & 5 deletions osf/utils/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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['recipient'] = 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
)


Expand Down
28 changes: 28 additions & 0 deletions osf_tests/test_reviewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions website/mails/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
9 changes: 6 additions & 3 deletions website/reviews/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from website.settings import OSF_PREPRINTS_LOGO, OSF_REGISTRIES_LOGO, DOMAIN


# Handle email notifications including: update comment, accept, and reject of submission.
# Handle email notifications including: update comment, accept, and reject of submission. Res
@reviews_signals.reviews_email.connect
def reviews_notification(self, creator, template, context, action):
# Avoid AppRegistryNotReady error
Expand All @@ -27,7 +27,10 @@ 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):
if not template:
template = mails.REVIEWS_SUBMISSION_CONFIRMATION

# Avoid AppRegistryNotReady error
from website.notifications.emails import get_user_subscriptions

Expand All @@ -51,7 +54,7 @@ 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
)
Expand Down

0 comments on commit 061642c

Please sign in to comment.