Skip to content

Commit e7266b9

Browse files
committed
add notification type emit for institutional requests
1 parent cfc1f97 commit e7266b9

File tree

5 files changed

+58
-23
lines changed

5 files changed

+58
-23
lines changed

notifications.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ notification_types:
1919
object_content_type_model_name: osfuser
2020
template: 'website/templates/emails/password_reset.html.mako'
2121
notification_freq_default: instantly
22+
- name: user_contributor_added_default
23+
__docs__: ...
24+
object_content_type_model_name: osfuser
25+
template: 'website/templates/emails/contributor_added_default.html.mako'
26+
notification_freq_default: instantly
2227
- name: forgot_password
2328
__docs__: ...
2429
object_content_type_model_name: osfuser
@@ -122,6 +127,21 @@ notification_types:
122127
object_content_type_model_name: abstractnode
123128
template: 'website/templates/emails/pending_embargo_non_admin.html.mako'
124129
notification_freq_default: instantly
130+
- name: node_affiliation_changed
131+
__docs__: ...
132+
object_content_type_model_name: abstractnode
133+
template: 'website/templates/emails/project_affiliation_changed.html.mako'
134+
notification_freq_default: instantly
135+
- name: node_request_access_denied
136+
__docs__: ...
137+
object_content_type_model_name: abstractnode
138+
template: 'website/templates/emails/access_request_rejected.html.mako'
139+
notification_freq_default: instantly
140+
- name: node_access_request_submitted
141+
__docs__: ...
142+
object_content_type_model_name: abstractnode
143+
template: 'website/templates/emails/access_request_submitted.html.mako'
144+
notification_freq_default: instantly
125145

126146
#### PREPRINT
127147
- name: pending_retraction_admin

osf/models/mixins.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,18 @@ def add_affiliated_institution(self, inst, user, log=True, ignore_user_affiliati
306306
if not self.is_affiliated_with_institution(inst):
307307
self.affiliated_institutions.add(inst)
308308
self.update_search()
309+
from . import NotificationType
310+
309311
if notify and getattr(self, 'type', False) == 'osf.node':
310312
for user, _ in self.get_admin_contributors_recursive(unique_users=True):
311-
mails.send_mail(
312-
user.username,
313-
mails.PROJECT_AFFILIATION_CHANGED,
314-
**{
313+
NotificationType.objects.get(
314+
name=NotificationType.Type.NODE_AFFILIATION_CHANGED
315+
).emit(
316+
user=user,
317+
event_context={
315318
'user': user,
316319
'node': self,
317-
},
320+
}
318321
)
319322
if log:
320323
params = self.log_params
@@ -345,16 +348,18 @@ def remove_affiliated_institution(self, inst, user, save=False, log=True, notify
345348
if save:
346349
self.save()
347350
self.update_search()
351+
from . import NotificationType
348352

349353
if notify and getattr(self, 'type', False) == 'osf.node':
350354
for user, _ in self.get_admin_contributors_recursive(unique_users=True):
351-
mails.send_mail(
352-
user.username,
353-
mails.PROJECT_AFFILIATION_CHANGED,
354-
**{
355+
NotificationType.objects.get(
356+
name=NotificationType.Type.NODE_AFFILIATION_CHANGED
357+
).emit(
358+
user=user,
359+
event_context={
355360
'user': user,
356361
'node': self,
357-
},
362+
}
358363
)
359364

360365
return True

osf/models/notification_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Type(str, Enum):
7979
USER_INVITE_DRAFT_REGISTRATION = 'user_invite_draft_registration'
8080
USER_INVITE_OSF_PREPRINT = 'user_invite_osf_preprint'
8181
USER_CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF = 'user_contributor_added_preprint_node_from_osf'
82+
USER_CONTRIBUTOR_ADDED_ACCESS_REQUEST = 'user_contributor_added_access_request'
8283

8384
# Node notifications
8485
NODE_COMMENT = 'node_comments'

osf/utils/machines.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,18 @@ def notify_submit(self, ev):
238238
context = self.get_context()
239239
context['contributors_url'] = f'{self.machineable.target.absolute_url}contributors/'
240240
context['project_settings_url'] = f'{self.machineable.target.absolute_url}settings/'
241+
from osf.models import NotificationType
242+
241243
if not self.machineable.request_type == NodeRequestTypes.INSTITUTIONAL_REQUEST.value:
242244
for admin in self.machineable.target.get_users_with_perm(permissions.ADMIN):
243-
mails.send_mail(
244-
admin.username,
245-
mails.ACCESS_REQUEST_SUBMITTED,
246-
admin=admin,
247-
osf_contact_email=OSF_CONTACT_EMAIL,
248-
**context
245+
NotificationType.objects.get(
246+
name=NotificationType.Type.NODE_REQUEST_ACCESS_SUBMITTED,
247+
).emit(
248+
user=admin,
249+
event_context={
250+
'osf_contact_email': OSF_CONTACT_EMAIL,
251+
**context
252+
}
249253
)
250254

251255
def notify_resubmit(self, ev):
@@ -257,13 +261,18 @@ def notify_resubmit(self, ev):
257261
def notify_accept_reject(self, ev):
258262
""" Notify requester that admins have approved/denied
259263
"""
264+
from osf.models import NotificationType
265+
260266
if ev.event.name == DefaultTriggers.REJECT.value:
261267
context = self.get_context()
262-
mails.send_mail(
263-
self.machineable.creator.username,
264-
mails.ACCESS_REQUEST_DENIED,
265-
osf_contact_email=OSF_CONTACT_EMAIL,
266-
**context
268+
NotificationType.objects.get(
269+
name=NotificationType.Type.NODE_REQUEST_ACCESS_DENIED
270+
).emit(
271+
user=self.machineable.creator,
272+
event_context={
273+
'osf_contact_email': OSF_CONTACT_EMAIL,
274+
**context
275+
}
267276
)
268277
else:
269278
# add_contributor sends approval notification email

website/project/views/contributor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,15 @@ def notify_added_contributor(node, contributor, auth=None, email_template='defau
592592
elif email_template == 'draft_registration':
593593
email_template = NotificationType.Type.USER_CONTRIBUTOR_ADDED_DRAFT_REGISTRATION
594594
elif email_template == 'access_request':
595-
email_template = mails.CONTRIBUTOR_ADDED_ACCESS_REQUEST
595+
email_template = NotificationType.Type.USER_CONTRIBUTOR_ADDED_ACCESS_REQUEST
596596
elif node.has_linked_published_preprints:
597597
# Project holds supplemental materials for a published preprint
598598
email_template = NotificationType.Type.USER_CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF
599599
logo = settings.OSF_PREPRINTS_LOGO
600600
else:
601601
email_template = NotificationType.Type.USER_CONTRIBUTOR_ADDED_DEFAULT
602602

603-
NotificationType.objects.create(name=email_template).emit(
603+
NotificationType.objects.get(name=email_template).emit(
604604
user=contributor,
605605
event_context={
606606
'node': node.id,

0 commit comments

Comments
 (0)