@@ -18,15 +18,18 @@ def add_notification_subscription(user, notification_type, frequency, subscribed
1818 Create a NotificationSubscription for a user.
1919 If the notification type corresponds to a subscribed_object, set subscribed_object to get the provider.
2020 """
21- from osf .models import NotificationSubscription
21+ from osf .models import NotificationSubscription , AbstractProvider
2222 kwargs = {
2323 'user' : user ,
2424 'notification_type' : NotificationType .objects .get (name = notification_type ),
2525 'message_frequency' : frequency ,
2626 }
2727 if subscribed_object is not None :
2828 kwargs ['object_id' ] = subscribed_object .id
29- kwargs ['content_type' ] = ContentType .objects .get_for_model (subscribed_object )
29+ if isinstance (subscribed_object , AbstractProvider ):
30+ kwargs ['content_type' ] = ContentType .objects .get_for_model (subscribed_object , for_concrete_model = False ) if subscribed_object else None
31+ else :
32+ kwargs ['content_type' ] = ContentType .objects .get_for_model (subscribed_object ) if subscribed_object else None
3033 if subscription is not None :
3134 kwargs ['object_id' ] = subscription .id
3235 kwargs ['content_type' ] = ContentType .objects .get_for_model (subscription )
@@ -113,16 +116,17 @@ def test_send_user_email_task_no_notifications(self):
113116 def test_send_moderator_email_task_registration_provider_admin (self ):
114117 user = AuthUserFactory (fullname = 'Admin User' )
115118 reg_provider = RegistrationProviderFactory (_id = 'abc123' )
116- reg = RegistrationFactory (provider = reg_provider )
117- admin_group = reg_provider .get_group ('admin' )
118- admin_group .user_set .add (user )
119+ reg_provider_content_type = ContentType .objects .get_for_model (reg_provider )
120+ RegistrationFactory (provider = reg_provider )
121+ moderator_group = reg_provider .get_group ('moderator' )
122+ moderator_group .user_set .add (user )
119123 notification_type = NotificationType .objects .get (name = NotificationType .Type .PROVIDER_NEW_PENDING_SUBMISSIONS )
120124 notification = Notification .objects .create (
121125 subscription = add_notification_subscription (
122126 user ,
123127 notification_type ,
124128 'daily' ,
125- subscribed_object = reg
129+ subscribed_object = reg_provider
126130 ),
127131 event_context = {
128132 'profile_image_url' : 'http://example.com/profile.png' ,
@@ -137,7 +141,7 @@ def test_send_moderator_email_task_registration_provider_admin(self):
137141 )
138142 notification_ids = [notification .id ]
139143 with capture_notifications () as notifications :
140- send_moderator_email_task .apply (args = (user ._id , notification_ids )).get ()
144+ send_moderator_email_task .apply (args = (user ._id , notification_ids , reg_provider_content_type . id , reg_provider . id )).get ()
141145 assert len (notifications ['emits' ]) == 1
142146 assert notifications ['emits' ][0 ]['type' ] == NotificationType .Type .DIGEST_REVIEWS_MODERATORS
143147 assert notifications ['emits' ][0 ]['kwargs' ]['user' ] == user
@@ -150,30 +154,30 @@ def test_send_moderator_email_task_registration_provider_admin(self):
150154 def test_send_moderator_email_task_no_notifications (self ):
151155 user = AuthUserFactory (fullname = 'Admin User' )
152156 provider = RegistrationProviderFactory ()
153- reg = RegistrationFactory (provider = provider )
157+ reg_provider_content_type = ContentType .objects .get_for_model (provider )
158+ RegistrationFactory (provider = provider )
154159
155160 notification_ids = []
156161 notification_type = NotificationType .objects .get (name = NotificationType .Type .PROVIDER_NEW_PENDING_SUBMISSIONS )
157162 add_notification_subscription (
158163 user ,
159164 notification_type ,
160165 'daily' ,
161- subscribed_object = reg
166+ subscribed_object = provider
162167 )
163-
164- send_moderator_email_task .apply (args = (user ._id , notification_ids )).get ()
168+ send_moderator_email_task .apply (args = (user ._id , notification_ids , reg_provider_content_type .id , provider .id )).get ()
165169 email_task = EmailTask .objects .filter (user_id = user .id ).first ()
166170 assert email_task .status == 'SUCCESS'
167171
168172 def test_send_moderator_email_task_user_not_found (self ):
169- send_moderator_email_task .apply (args = ('nouser' , [])).get ()
173+ send_moderator_email_task .apply (args = ('nouser' , [], 1 , 1 )).get ()
170174 email_task = EmailTask .objects .filter ()
171175 assert email_task .exists ()
172176 assert email_task .first ().status == 'NO_USER_FOUND'
173177
174178 def test_get_users_emails (self ):
175179 user = AuthUserFactory ()
176- notification_type = NotificationType .objects .get (name = NotificationType .Type .USER_DIGEST )
180+ notification_type = NotificationType .objects .get (name = NotificationType .Type .USER_FILE_UPDATED )
177181 notification1 = Notification .objects .create (
178182 subscription = add_notification_subscription (user , notification_type , 'daily' ),
179183 sent = None ,
@@ -249,10 +253,12 @@ def test_send_users_digest_email_end_to_end(self):
249253 def test_send_moderators_digest_email_end_to_end (self ):
250254 user = AuthUserFactory ()
251255 provider = RegistrationProviderFactory ()
252- reg = RegistrationFactory (provider = provider )
256+ RegistrationFactory (provider = provider )
257+ moderator_group = provider .get_group ('moderator' )
258+ moderator_group .user_set .add (user )
253259 notification_type = NotificationType .objects .get (name = NotificationType .Type .PROVIDER_NEW_PENDING_SUBMISSIONS )
254260 Notification .objects .create (
255- subscription = add_notification_subscription (user , notification_type , 'daily' , subscribed_object = reg ),
261+ subscription = add_notification_subscription (user , notification_type , 'daily' , subscribed_object = provider ),
256262 sent = None ,
257263 event_context = {
258264 'submitter_fullname' : 'submitter_fullname' ,
0 commit comments