Skip to content

Commit a9241eb

Browse files
committed
refactored to NotificationType
1 parent 9d87d84 commit a9241eb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

osf/models/mixins.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
BlockedEmailError,
2828
)
2929
from website.settings import OSF_CONTACT_EMAIL, DOMAIN
30+
from osf.models.notification_type import NotificationType, FrequencyChoices
3031
from .node_relation import NodeRelation
3132
from .nodelog import NodeLog
32-
from .notification import NotificationType, FrequencyChoices
3333
from .subject import Subject
3434
from .spam import SpamMixin, SpamStatus
3535
from .validators import validate_title
@@ -1456,21 +1456,23 @@ def add_contributor(self, contributor, permissions=None, visible=True,
14561456
self.save()
14571457
if self._id and contrib_to_add:
14581458
# Get or create the notification type
1459-
notification_type, created = NotificationType.objects.get_or_create(
1460-
name='Add contributor',
1461-
defaults={
1462-
'notification_freq': FrequencyChoices.INSTANTLY.value,
1463-
'template': send_email
1464-
}
1465-
)
1459+
if send_email == 'default':
1460+
notification_type_name = NotificationType.Type.USER_CONTRIBUTOR_ADDED_DEFAULT.value
1461+
else:
1462+
notification_type_name = NotificationType.Type.USER_CONTRIBUTOR_ADDED_DEFAULT.value
1463+
notification_type = NotificationType.objects.get(name=notification_type_name)
1464+
1465+
auth_user_fullname = None
1466+
if auth:
1467+
auth_user_fullname = auth.user.fullname
14661468

14671469
event_context = {
14681470
'node': {
14691471
'id': self._id,
14701472
'title': self.title,
14711473
'absolute_url': getattr(self, 'absolute_url', ''),
14721474
},
1473-
'referrer_name': auth.user.fullname,
1475+
'referrer_name': auth_user_fullname,
14741476
'user': {
14751477
'id': contrib_to_add._id,
14761478
'fullname': contrib_to_add.fullname,
@@ -1482,9 +1484,10 @@ def add_contributor(self, contributor, permissions=None, visible=True,
14821484
'DOMAIN': DOMAIN
14831485
}
14841486
}
1485-
1487+
breakpoint()
14861488
notification_type.emit(
1487-
user=contributor,
1489+
user=contrib_to_add,
1490+
message_frequency=FrequencyChoices.INSTANTLY.value,
14881491
subscribed_object=self,
14891492
event_context=event_context
14901493
)

0 commit comments

Comments
 (0)