@@ -24,13 +24,15 @@ def subscribe_creator(resource):
2424 if user .is_registered :
2525 NotificationSubscription .objects .get_or_create (
2626 user = user ,
27- notification_type__name = NotificationType .Type .USER_FILE_UPDATED ,
27+ notification_type = NotificationType .objects .get (name = NotificationType .Type .USER_FILE_UPDATED ),
28+ _is_digest = True ,
2829 )
2930 NotificationSubscription .objects .get_or_create (
3031 user = user ,
31- notification_type__name = NotificationType .Type .FILE_UPDATED ,
32+ notification_type = NotificationType .objects . get ( name = NotificationType . Type .FILE_UPDATED ) ,
3233 object_id = resource .id ,
33- content_type = ContentType .objects .get_for_model (resource )
34+ content_type = ContentType .objects .get_for_model (resource ),
35+ _is_digest = True ,
3436 )
3537
3638@contributor_added .connect
@@ -45,28 +47,25 @@ def subscribe_contributor(resource, contributor, auth=None, *args, **kwargs):
4547 if contributor .is_registered :
4648 NotificationSubscription .objects .get_or_create (
4749 user = contributor ,
48- notification_type__name = NotificationType .Type .USER_FILE_UPDATED ,
50+ notification_type = NotificationType .objects .get (name = NotificationType .Type .USER_FILE_UPDATED ),
51+ _is_digest = True ,
4952 )
5053 NotificationSubscription .objects .get_or_create (
5154 user = contributor ,
52- notification_type__name = NotificationType .Type .FILE_UPDATED ,
55+ notification_type = NotificationType .objects . get ( name = NotificationType . Type .FILE_UPDATED ) ,
5356 object_id = resource .id ,
54- content_type = ContentType .objects .get_for_model (resource )
57+ content_type = ContentType .objects .get_for_model (resource ),
58+ _is_digest = True ,
5559 )
5660
5761@user_confirmed .connect
5862def subscribe_confirmed_user (user ):
5963 NotificationSubscription = apps .get_model ('osf.NotificationSubscription' )
6064 NotificationType = apps .get_model ('osf.NotificationType' )
61- user_events = [
62- NotificationType .Type .USER_FILE_UPDATED ,
63- NotificationType .Type .USER_REVIEWS ,
64- ]
65- for user_event in user_events :
66- NotificationSubscription .objects .get_or_create (
67- user = user ,
68- notification_type__name = user_event
69- )
65+ NotificationSubscription .objects .get_or_create (
66+ user = user ,
67+ notification_type = NotificationType .objects .get (name = NotificationType .Type .USER_FILE_UPDATED )
68+ )
7069
7170@privacy_set_public .connect
7271def queue_first_public_project_email (user , node ):
@@ -94,8 +93,7 @@ def reviews_submit_notification_moderators(self, timestamp, context, resource):
9493 """
9594
9695 # imports moved here to avoid AppRegistryNotReady error
97- from osf .models import NotificationSubscription , NotificationType
98- from django .contrib .contenttypes .models import ContentType
96+ from osf .models import NotificationType
9997 from website .settings import DOMAIN
10098
10199 provider = resource .provider
@@ -120,17 +118,15 @@ def reviews_submit_notification_moderators(self, timestamp, context, resource):
120118 context ['message' ] = f'resubmitted "{ resource .title } ".'
121119 else :
122120 context ['message' ] = f'submitted "{ resource .title } ".'
123- provider_subscription , created = NotificationSubscription .objects .get_or_create (
124- notification_type__name = NotificationType .Type .PROVIDER_NEW_PENDING_SUBMISSIONS ,
125- object_id = provider .id ,
126- content_type = ContentType .objects .get_for_model (provider .__class__ ),
127- )
128- for recipient in provider_subscription .subscribed_object .get_group ('moderator' ).user_set .all ():
121+
122+ for recipient in resource .provider .get_group ('moderator' ).user_set .all ():
129123 NotificationType .objects .get (
130124 name = NotificationType .Type .PROVIDER_NEW_PENDING_SUBMISSIONS
131125 ).emit (
132126 user = recipient ,
133- event_context = context
127+ subscribed_object = provider ,
128+ event_context = context ,
129+ is_digest = True ,
134130 )
135131
136132# Handle email notifications to notify moderators of new submissions.
0 commit comments