@@ -576,25 +576,24 @@ def create_waterbutler_log(payload, **kwargs):
576576 params = payload
577577 )
578578
579- if payload .get ('email' ) is True :
580- notification_type = NotificationType .Type .FILE_OPERATION_SUCCESS
581- elif payload .get ('errors' ):
582- notification_type = NotificationType .Type .FILE_OPERATION_FAILED
583- else :
584- raise NotImplementedError ('No email template for this' )
585-
586- NotificationType .objects .get (name = notification_type .value ).emit (
587- user = user ,
588- event_context = {
589- 'action' : payload ['action' ],
590- 'source_node' : source_node ,
591- 'destination_node' : destination_node ,
592- 'source_path' : payload ['source' ]['materialized' ],
593- 'source_addon' : payload ['source' ]['addon' ],
594- 'destination_addon' : payload ['destination' ]['addon' ],
595- 'osf_support_email' : settings .OSF_SUPPORT_EMAIL
596- }
597- )
579+ if payload .get ('email' ) or payload .get ('errors' ):
580+ if payload .get ('email' ):
581+ notification_type = NotificationType .Type .FILE_OPERATION_SUCCESS
582+ if payload .get ('errors' ):
583+ notification_type = NotificationType .Type .FILE_OPERATION_FAILED
584+
585+ NotificationType .objects .get (name = notification_type .value ).emit (
586+ user = user ,
587+ event_context = {
588+ 'action' : payload ['action' ],
589+ 'source_node' : source_node ,
590+ 'destination_node' : destination_node ,
591+ 'source_path' : payload ['source' ]['materialized' ],
592+ 'source_addon' : payload ['source' ]['addon' ],
593+ 'destination_addon' : payload ['destination' ]['addon' ],
594+ 'osf_support_email' : settings .OSF_SUPPORT_EMAIL
595+ }
596+ )
598597 if payload .get ('errors' ):
599598 # Action failed but our function succeeded
600599 # Bail out to avoid file_signals
@@ -608,27 +607,35 @@ def create_waterbutler_log(payload, **kwargs):
608607 if target_node and payload ['action' ] != 'download_file' :
609608 update_storage_usage_with_size (payload )
610609
611- with transaction .atomic ():
612- f_type , item_action = action .split ('_' )
613- if payload ['metadata' ]['materialized' ].endswith ('/' ):
614- f_type = 'folder'
615- match f'node_{ action } ' :
616- case NotificationType .Type .NODE_FILE_ADDED :
617- NotificationType .objects .get (
618- name = NotificationType .Type .NODE_FILE_ADDED
619- ).emit (
620- user = user ,
621- event_context = {
622- 'message' : f'{ markupsafe .escape (item_action )} { markupsafe .escape (f_type )} "'
623- f'<b>{ markupsafe .escape (payload ['metadata' ]['materialized' ].lstrip ('/' ))} </b>".' ,
624- 'profile_image_url' : user .profile_image_url (),
625- 'localized_timestamp' : localize_timestamp (timezone .now (), user ),
626- 'user_fullname' : user .fullname ,
627- 'url' : node .absolute_url ,
628- }
629- )
630- case _:
631- raise NotImplementedError (f'action { action } not implemented' )
610+ file_signals .file_updated .send (target = node , user = user , event_type = action , payload = payload )
611+
612+ match f'node_{ action } ' :
613+ case NotificationType .Type .NODE_FILE_ADDED :
614+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_FILE_ADDED )
615+ case NotificationType .Type .NODE_FILE_REMOVED :
616+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_FILE_REMOVED )
617+ case NotificationType .Type .NODE_FILE_UPDATED :
618+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_FILE_UPDATED )
619+ case NotificationType .Type .NODE_ADDON_FILE_RENAMED :
620+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_ADDON_FILE_RENAMED )
621+ case NotificationType .Type .NODE_ADDON_FILE_COPIED :
622+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_ADDON_FILE_COPIED )
623+ case NotificationType .Type .NODE_ADDON_FILE_REMOVED :
624+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_ADDON_FILE_REMOVED )
625+ case NotificationType .Type .NODE_ADDON_FILE_MOVED :
626+ notification = NotificationType .objects .get (name = NotificationType .Type .NODE_ADDON_FILE_MOVED )
627+ case _:
628+ raise NotImplementedError (f'action { action } not implemented' )
629+
630+ notification .emit (
631+ user = user ,
632+ event_context = {
633+ 'profile_image_url' : user .profile_image_url (),
634+ 'localized_timestamp' : localize_timestamp (timezone .now (), user ),
635+ 'user_fullname' : user .fullname ,
636+ 'url' : node .absolute_url ,
637+ }
638+ )
632639
633640 return {'status' : 'success' }
634641
0 commit comments