Skip to content

Commit 5757d19

Browse files
fix: update unregistered contributor notifications and email templates
1 parent 1e812ee commit 5757d19

File tree

9 files changed

+42
-49
lines changed

9 files changed

+42
-49
lines changed

api/nodes/serializers.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from django.core.exceptions import ValidationError
2929
from framework.auth.core import Auth
3030
from framework.exceptions import PermissionsError
31-
from osf.models import Tag, CollectionSubmission, NotificationType, OSFUser
31+
from osf.models import Tag, CollectionSubmission
3232
from rest_framework import serializers as ser
3333
from rest_framework import exceptions
3434
from addons.base.exceptions import InvalidAuthError, InvalidFolderError
@@ -1269,19 +1269,9 @@ def create(self, validated_data):
12691269
if email_pref not in self.email_preferences:
12701270
raise exceptions.ValidationError(f'{email_pref} is not a valid email preference.')
12711271

1272-
is_published = getattr(resource, 'is_published', False)
1273-
notification_type = {
1274-
'false': False,
1275-
'default': NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT,
1276-
'draft_registration': NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT,
1277-
'preprint': NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT if is_published else False,
1278-
}.get(email_pref, False)
1279-
contributor = OSFUser.load(user_id)
1280-
notification_type = notification_type if email or (contributor and contributor.is_registered) else False
1281-
12821272
try:
12831273
contributor_dict = {
1284-
'auth': auth, 'user_id': user_id, 'email': email, 'full_name': full_name, 'notification_type': notification_type,
1274+
'auth': auth, 'user_id': user_id, 'email': email, 'full_name': full_name,
12851275
'bibliographic': bibliographic, 'index': index, 'permissions': permissions,
12861276
}
12871277
contributor_obj = resource.add_contributor_registered_or_not(**contributor_dict)

notifications.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ notification_types:
109109
tests: ['osf_tests/test_institution.py']
110110
template: 'website/templates/institution_deactivation.html.mako'
111111

112-
- name: user_invite_preprints_osf
112+
- name: user_invite_osf_preprint
113113
subject: 'You have been added as a contributor to an OSF preprint.'
114114
__docs__: ...
115115
object_content_type_model_name: osfuser
116116
tests: []
117117
template: 'website/templates/invite_preprints_osf.html.mako'
118118

119-
- name: user_invite_preprints
119+
- name: provider_user_invite_preprint
120120
subject: 'You have been invited to contribute to a preprint'
121121
__docs__: ...
122122
object_content_type_model_name: osfuser

osf/models/mixins.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,6 @@ def add_contributors(
14991499
auth=None,
15001500
log=True,
15011501
save=False,
1502-
notification_type=NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
15031502
):
15041503
"""Add multiple contributors
15051504
@@ -1521,7 +1520,6 @@ def add_contributors(
15211520
auth=auth,
15221521
log=False,
15231522
save=False,
1524-
notification_type=notification_type
15251523
)
15261524
if log and contributors:
15271525
params = self.log_params
@@ -1543,7 +1541,6 @@ def add_unregistered_contributor(
15431541
fullname,
15441542
email,
15451543
auth,
1546-
notification_type=False,
15471544
visible=True,
15481545
permissions=None,
15491546
existing_user=None
@@ -1592,6 +1589,18 @@ def add_unregistered_contributor(
15921589
else:
15931590
raise e
15941591

1592+
from osf.models import AbstractNode, Preprint, DraftRegistration
1593+
1594+
if isinstance(self, AbstractNode):
1595+
notification_type = NotificationType.Type.USER_INVITE_DEFAULT
1596+
elif isinstance(self, Preprint):
1597+
if self.provider.is_default:
1598+
notification_type = NotificationType.Type.USER_INVITE_OSF_PREPRINT
1599+
else:
1600+
notification_type = NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT
1601+
elif isinstance(self, DraftRegistration):
1602+
notification_type = NotificationType.Type.USER_INVITE_DRAFT_REGISTRATION
1603+
15951604
self.add_contributor(
15961605
contributor,
15971606
permissions=permissions,
@@ -1610,7 +1619,6 @@ def add_contributor_registered_or_not(self,
16101619
user_id=None,
16111620
full_name=None,
16121621
email=None,
1613-
notification_type=None,
16141622
permissions=None,
16151623
bibliographic=True,
16161624
index=None):
@@ -1629,7 +1637,6 @@ def add_contributor_registered_or_not(self,
16291637
auth=auth,
16301638
visible=bibliographic,
16311639
permissions=permissions,
1632-
notification_type=notification_type,
16331640
save=True
16341641
)
16351642
else:
@@ -1642,7 +1649,6 @@ def add_contributor_registered_or_not(self,
16421649
fullname=full_name,
16431650
email=contributor.username,
16441651
auth=auth,
1645-
notification_type=notification_type,
16461652
permissions=permissions,
16471653
visible=bibliographic,
16481654
existing_user=contributor,
@@ -1658,7 +1664,6 @@ def add_contributor_registered_or_not(self,
16581664
contributor=contributor,
16591665
auth=auth,
16601666
visible=bibliographic,
1661-
notification_type=notification_type,
16621667
permissions=permissions,
16631668
save=True
16641669
)
@@ -1667,7 +1672,6 @@ def add_contributor_registered_or_not(self,
16671672
fullname=full_name,
16681673
email=email,
16691674
auth=auth,
1670-
notification_type=notification_type,
16711675
permissions=permissions,
16721676
visible=bibliographic
16731677
)

website/project/views/contributor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ def notify_added_contributor(resource, contributor, notification_type, auth=None
629629
throttle = kwargs.get('throttle', settings.CONTRIBUTOR_ADDED_EMAIL_THROTTLE)
630630
if notification_type and check_email_throttle(contributor, notification_type, throttle=throttle):
631631
return
632+
633+
claim_url = None
634+
if not contributor.is_confirmed:
635+
claim_url = contributor.get_claim_url(resource._primary_key, external=True)
632636
referrer_name = getattr(getattr(auth, 'user', None), 'fullname', '') if auth else ''
633637
notification_type.instance.emit(
634638
user=contributor,
@@ -651,7 +655,8 @@ def notify_added_contributor(resource, contributor, notification_type, auth=None
651655
'can_change_preferences': False,
652656
'logo': logo,
653657
'osf_contact_email': settings.OSF_CONTACT_EMAIL,
654-
'preprint_list': ''.join(f"- {p['absolute_url']}\n" for p in serialize_preprints(resource, user=None)) if isinstance(resource, Node) else '- (none)\n'
658+
'preprint_list': ''.join(f"- {p['absolute_url']}\n" for p in serialize_preprints(resource, user=None)) if isinstance(resource, Node) else '- (none)\n',
659+
'claim_url': claim_url,
655660
}
656661
)
657662

website/templates/contributor_added_preprints_osf.html.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<td style="border-collapse: collapse;">
66
Hello ${user_fullname},<br>
77
<br>
8-
${referrer_text}} to the preprint "${node_title}" on the Open Science Framework: ${node_absolute_url}<br>
8+
${referrer_text} to the preprint <a href="${node_absolute_url}">${node_title}</a> on the Open Science Framework.<br>
99
<br>
10-
If you are erroneously being associated with "${node_title}," then you may visit the preprint and remove yourself as a contributor.<br>
10+
If you are erroneously being associated with <a href="${node_absolute_url}">${node_title}</a>, then you may visit the preprint and remove yourself as a contributor.<br>
1111
<br>
1212
Sincerely,<br>
1313
<br>

website/templates/invite_default.html.mako

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
%>
99
Hello ${user_fullname},<br>
1010
<br>
11-
You have been added by ${referrer_fullname} as a contributor to the project "${node_title}" on the Open Science Framework. To set a password for your account, visit:<br>
11+
You have been added by ${referrer_name} as a contributor to the project <a href="${node_absolute_url}">${node_title}</a> on the Open Science Framework.<br>
1212
<br>
13-
${claim_url}<br>
13+
<a href="${claim_url}">Click here</a> to set a password for your account.<br>
1414
<br>
15-
Once you have set a password, you will be able to make contributions to "${node_title}" and create your own projects. You will automatically be subscribed to notification emails for this project. To change your email notification preferences, visit your project or your user settings: ${domain + "settings/notifications/"}<br>
16-
<br>
17-
To preview "${node_title}" click the following link: ${node_absolute_url}<br>
15+
Once you have set a password, you will be able to make contributions to <a href="${node_absolute_url}">${node_title}</a> and create your own projects. You will automatically be subscribed to notification emails for this project. To change your email notification preferences, visit your project or your user <a href="${domain + "settings/notifications/"}">settings</a><br>
1816
<br>
1917
(NOTE: if this project is private, you will not be able to view it until you have confirmed your account)<br>
2018
<br>
21-
If you are not ${user_fullname} or you are erroneously being associated with "${node_title}" then email ${osf_contact_email} with the subject line "Claiming Error" to report the problem.<br>
19+
If you are not ${user_fullname} or you are erroneously being associated with <a href="${node_absolute_url}">${node_title}</a> then email ${osf_contact_email} with the subject line "Claiming Error" to report the problem.<br>
2220
<br>
2321
Sincerely,<br>
2422
<br>

website/templates/invite_draft_registration.html.mako

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<td style="border-collapse: collapse;">
66
Hello ${user_fullname},
77
<p>
8-
${referrer_fullname} has added you as a contributor on
9-
% if not node.title or node.title == 'Untitled':
8+
${referrer_name} has added you as a contributor on
9+
% if not node_title or node_title == 'Untitled':
1010
<a href="${node_absolute_url}">a new registration draft</a>
1111
% else:
1212
a new registration draft titled <a href="${node_absolute_url}">${node_title}</a>
1313
% endif
1414
to be submitted for inclusion in the
15-
<a href="${domain}/registries/${node_provider__id if node.provider else 'osf'}">${registry_text}</a>.
15+
<a href="${domain}/registries/${branded_service__id if branded_service__id else 'osf'}">${registry_text}</a>.
1616
</p>
1717
<p>
1818
<a href="${claim_url}">Click here</a> to set a password for your account.
@@ -24,7 +24,7 @@
2424
</p>
2525
<p>
2626
If you are not ${user_fullname} or if you have been erroneously associated with
27-
% if not node.title or node.title == 'Untitled':
27+
% if not node_title or node_title == 'Untitled':
2828
this registration draft
2929
% else:
3030
"${node_title}"

website/templates/invite_preprints.html.mako

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
<td style="border-collapse: collapse;">
66
Hello ${user_fullname},<br>
77
<br>
8-
You have been added by ${referrer_fullname} as a contributor to the ${branded_service_preprint_word} "${node_title}" on ${branded_service_name}, powered by the Open Science Framework. To set a password for your account, visit:<br>
8+
You have been added by ${referrer_name} as a contributor to the ${branded_service_preprint_word} <a href="${node_absolute_url}">${node_title}</a> on ${branded_service_name}, powered by the Open Science Framework.<br>
99
<br>
10-
${claim_url}<br>
10+
<a href="${claim_url}">Click here</a> to set a password for your account.<br>
1111
<br>
12-
Once you have set a password, you will be able to make contributions to "${node_title}" and create your own ${branded_service_preprint_word}. You will automatically be subscribed to notification emails for this ${branded_service_preprint_word}. To change your email notification preferences, visit your user settings: ${domain + "settings/notifications/"}<br>
13-
<br>
14-
To preview "${node_title}" click the following link: ${node_absolute_url}<br>
12+
Once you have set a password, you will be able to make contributions to <a href="${node_absolute_url}">${node_title}</a> and create your own ${branded_service_preprint_word}. You will automatically be subscribed to notification emails for this ${branded_service_preprint_word}. To change your email notification preferences, visit your user <a href="${domain + "settings/notifications/"}">settings</a><br>
1513
<br>
1614
(NOTE: if this preprint is unpublished, you will not be able to view it until you have confirmed your account)<br>
1715
<br>
18-
If you are not ${user_fullname} or you have been erroneously associated with "${node_title}", then email contact+${branded_service._id}@osf.io with the subject line "Claiming Error" to report the problem.<br>
16+
If you are not ${user_fullname} or you have been erroneously associated with <a href="${node_absolute_url}">${node_title}</a>, then email contact+${branded_service__id}@osf.io with the subject line "Claiming Error" to report the problem.<br>
1917
<br>
2018
Sincerely,<br>
2119
<br>
2220
Your ${branded_service_name} and OSF teams<br>
2321
<br>
24-
Want more information? Visit https://osf.io/preprints/${branded_service._id} to learn about ${branded_service_name} or https://osf.io/ to learn about the Open Science Framework, or https://cos.io/ for information about its supporting organization, the Center for Open Science.<br>
22+
Want more information? Visit https://osf.io/preprints/${branded_service__id} to learn about ${branded_service_name} or https://osf.io/ to learn about the Open Science Framework, or https://cos.io/ for information about its supporting organization, the Center for Open Science.<br>
2523
<br>
26-
Questions? Email support+${branded_service._id}@osf.io<br>
24+
Questions? Email support+${branded_service__id}@osf.io<br>
2725
2826
</tr>
2927
</%def>

website/templates/invite_preprints_osf.html.mako

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
<td style="border-collapse: collapse;">
66
Hello ${user_fullname},<br>
77
<br>
8-
You have been added by ${referrer_fullname} as a contributor to the preprint "${node_title}" on the Open Science Framework. To set a password for your account, visit:<br>
8+
You have been added by ${referrer_name} as a contributor to the preprint <a href="${node_absolute_url}">${node_title}</a> on the Open Science Framework.<br>
99
<br>
10-
${claim_url}<br>
10+
<a href="${claim_url}">Click here</a> to set a password for your account.<br>
1111
<br>
12-
Once you have set a password, you will be able to make contributions to "${node_title}" and create your own preprints and projects. You will automatically be subscribed to notification emails for this preprint. To change your email notification preferences, visit your user settings: ${domain + "settings/notifications/"}<br>
13-
<br>
14-
To preview "${node_title}" click the following link: ${node_absolute_url}<br>
12+
Once you have set a password, you will be able to make contributions to <a href="${node_absolute_url}">${node_title}</a> and create your own preprints and projects. You will automatically be subscribed to notification emails for this preprint. To change your email notification preferences, visit your user <a href="${domain + "settings/notifications/"}">settings</a><br>
1513
<br>
1614
(NOTE: if this preprint is unpublished, you will not be able to view it until you have confirmed your account)<br>
1715
<br>
18-
If you are not ${user_fullname} or you are erroneously being associated with "${node_title}" then email ${osf_contact_email} with the subject line "Claiming Error" to report the problem.<br>
16+
If you are not ${user_fullname} or you are erroneously being associated with <a href="${node_absolute_url}">${node_title}</a> then email ${osf_contact_email} with the subject line "Claiming Error" to report the problem.<br>
1917
<br>
2018
Sincerely,<br>
2119
<br>

0 commit comments

Comments
 (0)