|
15 | 15 | PreprintRequest,
|
16 | 16 | Institution,
|
17 | 17 | OSFUser,
|
| 18 | + NotificationType, |
18 | 19 | )
|
| 20 | +from osf.models.notification import FrequencyChoices |
19 | 21 | from osf.utils.workflows import DefaultStates, RequestTypes, NodeRequestTypes
|
20 | 22 | from osf.utils import permissions as osf_permissions
|
21 | 23 | from website import language, settings
|
22 |
| -from website.mails import send_mail, NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST |
| 24 | +from website.mails import NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST |
23 | 25 |
|
24 | 26 | from rest_framework.exceptions import PermissionDenied, ValidationError
|
25 | 27 |
|
@@ -188,20 +190,38 @@ def make_node_institutional_access_request(self, node, validated_data) -> NodeRe
|
188 | 190 |
|
189 | 191 | comment = validated_data.get('comment', '').strip() or language.EMPTY_REQUEST_INSTITUTIONAL_ACCESS_REQUEST_TEXT
|
190 | 192 |
|
191 |
| - send_mail( |
192 |
| - to_addr=recipient.username, |
193 |
| - mail=NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST, |
| 193 | + notification_type_name = NotificationType.Type.NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST.value |
| 194 | + notification_type, created = NotificationType.objects.get_or_create( |
| 195 | + name=notification_type_name, |
| 196 | + defaults={ |
| 197 | + 'notification_freq': FrequencyChoices.INSTANTLY.value, |
| 198 | + 'template': NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST |
| 199 | + } |
| 200 | + ) |
| 201 | + event_context = { |
| 202 | + 'recipient': { |
| 203 | + 'fullname': recipient.full_name, |
| 204 | + }, |
| 205 | + 'sender': { |
| 206 | + 'absolute_url': sender.get_absolute_url(), |
| 207 | + 'full_name': sender.full_name, |
| 208 | + }, |
| 209 | + 'node':{ |
| 210 | + 'absolute_url': node.absolute_url, |
| 211 | + 'title': node.title, |
| 212 | + }, |
| 213 | + 'comment': comment, |
| 214 | + 'settings': { |
| 215 | + 'DOMAIN': settings.DOMAIN, |
| 216 | + 'OSF_CONTACT_EMAIL': settings.OSF_CONTACT_EMAIL, |
| 217 | + }, |
| 218 | + } |
| 219 | + |
| 220 | + notification_type.emit( |
194 | 221 | user=recipient,
|
195 |
| - sender=sender, |
196 |
| - bcc_addr=[sender.username] if validated_data['bcc_sender'] else None, |
197 |
| - reply_to=sender.username if validated_data['reply_to'] else None, |
198 |
| - recipient=recipient, |
199 |
| - comment=comment, |
200 |
| - institution=institution, |
201 |
| - osf_url=settings.DOMAIN, |
202 |
| - node=node_request.target, |
| 222 | + subscribed_object=node_request.target, |
| 223 | + event_context=event_context |
203 | 224 | )
|
204 |
| - |
205 | 225 | return node_request
|
206 | 226 |
|
207 | 227 | def _create_node_request(self, node, validated_data) -> NodeRequest:
|
|
0 commit comments