Skip to content

Commit d23481a

Browse files
committed
double import celery
1 parent 7fef010 commit d23481a

10 files changed

Lines changed: 45 additions & 51 deletions

File tree

addons/base/views.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -610,34 +610,37 @@ def create_waterbutler_log(payload, **kwargs):
610610
with transaction.atomic():
611611
file_signals.file_updated.send(target=node, user=user, payload=payload)
612612

613-
with transaction.atomic():
614-
match action:
615-
case NotificationType.Type.FILE_ADDED:
616-
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_ADDED)
617-
case NotificationType.Type.FILE_REMOVED:
618-
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_REMOVED)
619-
case NotificationType.Type.FILE_UPDATED:
620-
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_UPDATED)
621-
case NotificationType.Type.ADDON_FILE_RENAMED:
622-
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_RENAMED)
623-
case NotificationType.Type.ADDON_FILE_COPIED:
624-
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_COPIED)
625-
case NotificationType.Type.ADDON_FILE_REMOVED:
626-
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_REMOVED)
627-
case NotificationType.Type.ADDON_FILE_MOVED:
628-
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_MOVED)
629-
case _:
630-
raise NotImplementedError(f'action {action} not implemented')
631-
632-
notification.emit(
633-
user=user,
634-
event_context={
635-
'profile_image_url': user.profile_image_url(),
636-
'localized_timestamp': str(timezone.now()),
637-
'user_fullname': user.fullname,
638-
'url': node.absolute_url,
639-
}
640-
)
613+
614+
@file_signals.file_viewed.connect
615+
def emit_notification(self, target, user, payload):
616+
action = payload['action']
617+
match action:
618+
case NotificationType.Type.FILE_ADDED:
619+
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_ADDED)
620+
case NotificationType.Type.FILE_REMOVED:
621+
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_REMOVED)
622+
case NotificationType.Type.FILE_UPDATED:
623+
notification = NotificationType.objects.get(name=NotificationType.Type.FILE_UPDATED)
624+
case NotificationType.Type.ADDON_FILE_RENAMED:
625+
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_RENAMED)
626+
case NotificationType.Type.ADDON_FILE_COPIED:
627+
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_COPIED)
628+
case NotificationType.Type.ADDON_FILE_REMOVED:
629+
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_REMOVED)
630+
case NotificationType.Type.ADDON_FILE_MOVED:
631+
notification = NotificationType.objects.get(name=NotificationType.Type.ADDON_FILE_MOVED)
632+
case _:
633+
raise NotImplementedError(f'action {action} not implemented')
634+
635+
notification.emit(
636+
user=user,
637+
event_context={
638+
'profile_image_url': user.profile_image_url(),
639+
'localized_timestamp': str(timezone.now()),
640+
'user_fullname': user.fullname,
641+
'url': target.absolute_url,
642+
}
643+
)
641644

642645
return {'status': 'success'}
643646

api/institutions/authentication.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def authenticate(self, request):
372372
name=NotificationType.Type.USER_DUPLICATE_ACCOUNTS_OSF4I,
373373
).emit(
374374
user=user,
375+
subscribed_object=user,
375376
event_context={
376377
'user_fullname': user.fullname,
377378
'user_username': user.username,

framework/auth/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ def send_confirm_email(user, email, renew=False, external_id_provider=None, exte
861861

862862
NotificationType.objects.get(name=notification_type).emit(
863863
user=user,
864+
subscribed_object=user,
864865
event_context={
865866
'user_fullname': user.fullname,
866867
'confirmation_url': confirmation_url,

notifications.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ notification_types:
2727
__docs__: ...
2828
object_content_type_model_name: osfuser
2929
template: 'website/templates/emails/password_reset.html.mako'
30-
- name: user_contributor_added_draft_registration
31-
__docs__: ...
32-
object_content_type_model_name: osfuser
33-
template: 'website/templates/emails/contributor_added_draft_registration.html.mako'
3430
- name: user_contributor_added_preprint_node_from_osf
3531
__docs__: ...
3632
object_content_type_model_name: osfuser
@@ -39,10 +35,6 @@ notification_types:
3935
__docs__: ...
4036
object_content_type_model_name: osfuser
4137
template: 'website/templates/emails/contributor_added_access_request.html.mako'
42-
- name: user_contributor_added_draft_registration
43-
__docs__: ...
44-
object_content_type_model_name: osfuser
45-
template: 'website/templates/emails/contributor_added_draft_registration.html.mako'
4638
- name: user_contributor_added_osf_preprint
4739
subject: 'You have been added as a contributor to an OSF preprint.'
4840
__docs__: ...

osf/models/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ def set_password(self, raw_password, notify=True):
10611061
NotificationType.objects.get(
10621062
name=NotificationType.Type.USER_PASSWORD_RESET
10631063
).emit(
1064+
subscribed_object=self,
10641065
user=self,
10651066
message_frequency='instantly',
10661067
event_context={

website/notifications/listeners.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from framework.celery_tasks import app
66
from framework.postcommit_tasks.handlers import run_postcommit
77
from website.project.signals import contributor_added, project_created, node_deleted, contributor_removed
8-
from framework.auth.signals import user_confirmed
98
from website.project.signals import privacy_set_public
109
from website import settings
1110
from website.reviews import signals as reviews_signals
@@ -58,15 +57,6 @@ def subscribe_contributor(resource, contributor, auth=None, *args, **kwargs):
5857
_is_digest=True,
5958
)
6059

61-
@user_confirmed.connect
62-
def subscribe_confirmed_user(user):
63-
NotificationSubscription = apps.get_model('osf.NotificationSubscription')
64-
NotificationType = apps.get_model('osf.NotificationType')
65-
NotificationSubscription.objects.get_or_create(
66-
user=user,
67-
notification_type=NotificationType.objects.get(name=NotificationType.Type.USER_FILE_UPDATED)
68-
)
69-
7060
@privacy_set_public.connect
7161
def queue_first_public_project_email(user, node):
7262
"""Queue and email after user has made their first
@@ -77,6 +67,7 @@ def queue_first_public_project_email(user, node):
7767
NotificationType.objects.get(
7868
name=NotificationType.Type.USER_NEW_PUBLIC_PROJECT,
7969
).emit(
70+
subscribed_object=user,
8071
user=user,
8172
event_context={
8273
'nid': node._id,
@@ -143,6 +134,7 @@ def reviews_withdraw_requests_notification_moderators(self, timestamp, context,
143134
NotificationType.objects.get(
144135
name=NotificationType.Type.PROVIDER_NEW_PENDING_WITHDRAW_REQUESTS
145136
).emit(
137+
subscribed_object=provider,
146138
user=user,
147139
event_context=context
148140
)

website/notifications/tasks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from django.utils import timezone
77

88
from framework.celery_tasks import app as celery_app
9-
from celery import shared_task
109
from celery.utils.log import get_task_logger
1110
from osf.models import OSFUser, Notification, NotificationType, EmailTask, AbstractProvider, RegistrationProvider, \
1211
CollectionProvider
@@ -17,7 +16,7 @@
1716

1817
logger = get_task_logger(__name__)
1918

20-
@shared_task(bind=True, max_retries=3, default_retry_delay=60)
19+
@celery_app.task
2120
def send_user_email_task(self, user_id, notification_ids, message_freq):
2221
try:
2322
user = OSFUser.objects.get(
@@ -79,7 +78,7 @@ def send_user_email_task(self, user_id, notification_ids, message_freq):
7978
logger.exception('Retrying send_user_email_task due to exception')
8079
raise self.retry(exc=e)
8180

82-
@shared_task(bind=True, max_retries=3, default_retry_delay=60)
81+
@celery_app.task
8382
def send_moderator_email_task(self, user_id, provider_id, notification_ids, message_freq):
8483
try:
8584
user = OSFUser.objects.get(

website/profile/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def update_user(auth):
190190
NotificationType.objects.get(
191191
name=NotificationType.Type.USER_PRIMARY_EMAIL_CHANGED
192192
).emit(
193+
subscribed_object=user,
193194
user=user,
194195
event_context={
195196
'new_address': username,

website/project/views/contributor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def send_claim_registered_email(claimer, unclaimed_user, node, throttle=24 * 360
453453
NotificationType.objects.get(
454454
name=NotificationType.Type.USER_PENDING_VERIFICATION_REGISTERED
455455
).emit(
456+
subscribed_object=claimer,
456457
user=claimer,
457458
event_context={
458459
'claim_url': claim_url,
@@ -534,6 +535,7 @@ def send_claim_email(
534535
NotificationType.objects.get(
535536
name=NotificationType.Type.USER_PENDING_VERIFICATION
536537
).emit(
538+
subscribed_object=unclaimed_user,
537539
user=unclaimed_user,
538540
event_context={
539541
'user': unclaimed_user.id,

website/settings/defaults.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ class CeleryConfig:
553553
'osf.management.commands.registration_schema_metrics',
554554
'website.mailchimp_utils',
555555
'website.notifications.tasks',
556+
'website.notifications.tasks.send_users_digest_email',
557+
'website.notifications.tasks.send_moderators_digest_email',
556558
'website.archiver.tasks',
557559
'website.identifiers.tasks',
558560
'website.search.search',
@@ -625,12 +627,12 @@ class CeleryConfig:
625627
'kwargs': {'dry_run': False},
626628
},
627629
'send_moderators_digest_email': {
628-
'task': 'website.notifications.tasks.send_moderators_digest_email',
630+
'task': 'website.notifications.tasks',
629631
'schedule': crontab(minute=0, hour=5), # Daily 12 a.m
630632
'kwargs': {'dry_run': False},
631633
},
632634
'send_users_digest_email': {
633-
'task': 'website.notifications.tasks.send_users_digest_email',
635+
'task': 'website.notifications.tasks',
634636
'schedule': crontab(minute=0, hour=5), # Daily 12 a.m
635637
'kwargs': {'dry_run': False},
636638
},

0 commit comments

Comments
 (0)