3434from framework .flask import redirect
3535from framework .sentry import log_exception
3636from framework .transactions .handlers import no_auto_transaction
37- from website import mails
3837from website import settings
3938from addons .base import signals as file_signals
4039from addons .base .utils import format_last_known_metadata , get_mfr_url
5251 DraftRegistration ,
5352 Guid ,
5453 FileVersionUserMetadata ,
55- FileVersion
54+ FileVersion , NotificationType
5655)
5756from osf .metrics import PreprintView , PreprintDownload
5857from osf .utils import permissions
6463from website .util import rubeus
6564
6665# import so that associated listener is instantiated and gets emails
67- from website . notifications .events . files import FileEvent # noqa
66+ from notifications .file_event_notifications import FileEvent # noqa
6867
6968ERROR_MESSAGES = {'FILE_GONE' : """
7069<style>
@@ -226,8 +225,6 @@ def get_auth(auth, **kwargs):
226225 _check_resource_permissions (resource , auth , action )
227226
228227 provider_name = waterbutler_data ['provider' ]
229- waterbutler_settings = None
230- waterbutler_credentials = None
231228 file_version = file_node = None
232229 if provider_name == 'osfstorage' or (not flag_is_active (request , features .ENABLE_GV )):
233230 file_version , file_node = _get_osfstorage_file_version_and_node (
@@ -576,20 +573,32 @@ def create_waterbutler_log(payload, **kwargs):
576573 params = payload
577574 )
578575
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
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+ 'domain' : settings .DOMAIN ,
600+ }
591601 )
592-
593602 if payload .get ('errors' ):
594603 # Action failed but our function succeeded
595604 # Bail out to avoid file_signals
@@ -603,10 +612,8 @@ def create_waterbutler_log(payload, **kwargs):
603612 target_node = AbstractNode .load (metadata .get ('nid' ))
604613 if target_node and payload ['action' ] != 'download_file' :
605614 update_storage_usage_with_size (payload )
606-
607615 with transaction .atomic ():
608616 file_signals .file_updated .send (target = node , user = user , event_type = action , payload = payload )
609-
610617 return {'status' : 'success' }
611618
612619
0 commit comments