34
34
from framework .flask import redirect
35
35
from framework .sentry import log_exception
36
36
from framework .transactions .handlers import no_auto_transaction
37
+ from website import mails
37
38
from website import settings
38
39
from addons .base import signals as file_signals
39
40
from addons .base .utils import format_last_known_metadata , get_mfr_url
51
52
DraftRegistration ,
52
53
Guid ,
53
54
FileVersionUserMetadata ,
54
- FileVersion , NotificationType
55
+ FileVersion
55
56
)
56
57
from osf .metrics import PreprintView , PreprintDownload
57
58
from osf .utils import permissions
63
64
from website .util import rubeus
64
65
65
66
# 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
67
68
68
69
ERROR_MESSAGES = {'FILE_GONE' : """
69
70
<style>
@@ -225,6 +226,8 @@ def get_auth(auth, **kwargs):
225
226
_check_resource_permissions (resource , auth , action )
226
227
227
228
provider_name = waterbutler_data ['provider' ]
229
+ waterbutler_settings = None
230
+ waterbutler_credentials = None
228
231
file_version = file_node = None
229
232
if provider_name == 'osfstorage' or (not flag_is_active (request , features .ENABLE_GV )):
230
233
file_version , file_node = _get_osfstorage_file_version_and_node (
@@ -573,31 +576,20 @@ def create_waterbutler_log(payload, **kwargs):
573
576
params = payload
574
577
)
575
578
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
600
591
)
592
+
601
593
if payload .get ('errors' ):
602
594
# Action failed but our function succeeded
603
595
# Bail out to avoid file_signals
@@ -611,8 +603,10 @@ def create_waterbutler_log(payload, **kwargs):
611
603
target_node = AbstractNode .load (metadata .get ('nid' ))
612
604
if target_node and payload ['action' ] != 'download_file' :
613
605
update_storage_usage_with_size (payload )
606
+
614
607
with transaction .atomic ():
615
608
file_signals .file_updated .send (target = node , user = user , event_type = action , payload = payload )
609
+
616
610
return {'status' : 'success' }
617
611
618
612
0 commit comments