3434from framework .flask import redirect
3535from framework .sentry import log_exception
3636from framework .transactions .handlers import no_auto_transaction
37+ from website import mails
3738from website import settings
3839from addons .base import signals as file_signals
3940from addons .base .utils import format_last_known_metadata , get_mfr_url
5152 DraftRegistration ,
5253 Guid ,
5354 FileVersionUserMetadata ,
54- FileVersion , NotificationType
55+ FileVersion
5556)
5657from osf .metrics import PreprintView , PreprintDownload
5758from osf .utils import permissions
6364from website .util import rubeus
6465
6566# import so that associated listener is instantiated and gets emails
66- from notifications .file_event_notifications import FileEvent # noqa
67+ from website . notifications .events . files import FileEvent # noqa
6768
6869ERROR_MESSAGES = {'FILE_GONE' : """
6970<style>
@@ -225,6 +226,8 @@ def get_auth(auth, **kwargs):
225226 _check_resource_permissions (resource , auth , action )
226227
227228 provider_name = waterbutler_data ['provider' ]
229+ waterbutler_settings = None
230+ waterbutler_credentials = None
228231 file_version = file_node = None
229232 if provider_name == 'osfstorage' or (not flag_is_active (request , features .ENABLE_GV )):
230233 file_version , file_node = _get_osfstorage_file_version_and_node (
@@ -573,31 +576,20 @@ def create_waterbutler_log(payload, **kwargs):
573576 params = payload
574577 )
575578
576- if payload .get ('email' ) or payload .get ('errors' ):
577- if payload .get ('email' ):
578- notification_type = NotificationType .Type .USER_FILE_OPERATION_SUCCESS .instance
579- if payload .get ('errors' ):
580- notification_type = NotificationType .Type .USER_FILE_OPERATION_FAILED .instance
581- notification_type .emit (
582- user = user ,
583- subscribed_object = node ,
584- event_context = {
585- 'user_fullname' : user .fullname ,
586- 'action' : payload ['action' ],
587- 'source_node' : source_node ._id ,
588- 'source_node_title' : source_node .title ,
589- 'destination_node' : destination_node ._id ,
590- 'destination_node_title' : destination_node .title ,
591- 'destination_node_parent_node_title' : destination_node .parent_node .title if destination_node .parent_node else None ,
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- 'logo' : settings .OSF_LOGO ,
597- 'OSF_LOGO_LIST' : settings .OSF_LOGO_LIST ,
598- 'OSF_LOGO' : settings .OSF_LOGO ,
599- }
579+ if payload .get ('email' ) is True or payload .get ('errors' ):
580+ mails .send_mail (
581+ user .username ,
582+ mails .FILE_OPERATION_FAILED if payload .get ('errors' )
583+ else mails .FILE_OPERATION_SUCCESS ,
584+ action = payload ['action' ],
585+ source_node = source_node ,
586+ destination_node = destination_node ,
587+ source_path = payload ['source' ]['materialized' ],
588+ source_addon = payload ['source' ]['addon' ],
589+ destination_addon = payload ['destination' ]['addon' ],
590+ osf_support_email = settings .OSF_SUPPORT_EMAIL
600591 )
592+
601593 if payload .get ('errors' ):
602594 # Action failed but our function succeeded
603595 # Bail out to avoid file_signals
@@ -611,8 +603,10 @@ def create_waterbutler_log(payload, **kwargs):
611603 target_node = AbstractNode .load (metadata .get ('nid' ))
612604 if target_node and payload ['action' ] != 'download_file' :
613605 update_storage_usage_with_size (payload )
606+
614607 with transaction .atomic ():
615608 file_signals .file_updated .send (target = node , user = user , event_type = action , payload = payload )
609+
616610 return {'status' : 'success' }
617611
618612
0 commit comments