Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
413 commits
Select commit Hold shift + click to select a range
fb6086b
fix up auth_views tests
Johnetordoff Jul 25, 2025
53b89ac
fix up contributor and desk notifications
Johnetordoff Jul 25, 2025
46b6944
deletes detect_duplicate notifications as that only applied to legacy…
Johnetordoff Jul 25, 2025
dcdbdc7
fix spam ban notification type and split up webtests into smaller files
Johnetordoff Jul 25, 2025
68b0494
more clean-up from self-CR
Johnetordoff Jul 25, 2025
d65288e
fix user claim and i forgot email notifications
Johnetordoff Jul 27, 2025
9501714
remove old notification mocking and simplify celery config
Johnetordoff Jul 27, 2025
8c6785a
update tasks for queued_email system
Johnetordoff Jul 27, 2025
3d80365
improve automatic subscription methods
Johnetordoff Jul 27, 2025
2e98358
remove child node subscription list
Johnetordoff Jul 27, 2025
38d7caa
refactor and fix mailhog tests
Johnetordoff Jul 28, 2025
ddd78d4
refactor add_contributors to use notification_type
Johnetordoff Jul 28, 2025
c89399f
remove _ensure_subscriptions
Johnetordoff Jul 28, 2025
bf99451
add draft_registration notificationtype for send_email
Johnetordoff Jul 28, 2025
1781656
upgrade institutional request access notification subscriptions
Johnetordoff Jul 28, 2025
75d6f45
fix archiver notifications
Johnetordoff Jul 28, 2025
9e8bd85
fix schema response tests
Johnetordoff Jul 28, 2025
b89846f
fix machine actions
Johnetordoff Jul 29, 2025
8e9126a
fix institution deactivation notifications
Johnetordoff Jul 29, 2025
61a072f
Merge remote-tracking branch 'upstream/develop' into feature/pbs-25-13
adlius Jul 29, 2025
5a8f453
Merge branch 'feature/pbs-25-13' of https://github.com/CenterForOpenS…
Johnetordoff Jul 29, 2025
df19159
fix preprint moderation
Johnetordoff Jul 29, 2025
ddd1cbb
update node contributor view to include preprints as resource
Johnetordoff Jul 29, 2025
c1c12bd
clean up file notification events
Johnetordoff Jul 29, 2025
7c79222
fix contributor email notifications with new throttle
Johnetordoff Jul 29, 2025
e04d901
remove old notification routes and routes
Johnetordoff Jul 29, 2025
b0d0521
fix addons logs
Johnetordoff Jul 29, 2025
d77eed2
clean up claim new user email throttle
Johnetordoff Jul 30, 2025
74f42bf
clean-up contributor throttle tests
Johnetordoff Jul 30, 2025
6eacd4d
fix reporter and preprint tests
Johnetordoff Jul 30, 2025
59c5c2f
fix throttle
Johnetordoff Jul 30, 2025
3c6dfa8
fix addons and campaign tests
Johnetordoff Jul 30, 2025
24c503b
fix schema response tests
Johnetordoff Jul 30, 2025
94734fd
clean-up sanction code
Johnetordoff Jul 30, 2025
51df115
remove mails and copy over subject lines
Johnetordoff Jul 30, 2025
5ec04a0
remove old comment based notification tests
Johnetordoff Jul 30, 2025
f281e99
remove mails.py
Johnetordoff Jul 31, 2025
dbf4815
fixing mailhog tests to use Django mail BE
Johnetordoff Jul 31, 2025
ebffbe4
more mails removal
Johnetordoff Jul 31, 2025
795a7e6
fix send grid code
Johnetordoff Jul 31, 2025
a90a234
fix more sanctions code
Johnetordoff Jul 31, 2025
8421403
fix more schema responses
Johnetordoff Jul 31, 2025
f9d4249
fix boa
Johnetordoff Jul 31, 2025
4c2d145
fix mock user
Johnetordoff Jul 31, 2025
8d9a26f
[ENG-8401] Earlier preprint versions download the current file (#11245)
ihorsokhanexoft Jul 31, 2025
7ccc8fb
fix schema response tests
Johnetordoff Jul 31, 2025
c418021
fix insti reporter tests
Johnetordoff Jul 31, 2025
57ba198
clean resource contributors create method
Johnetordoff Jul 31, 2025
8745da4
[ENG-8462] Institution setup fixes (#11241)
antkryt Jul 31, 2025
c635beb
remove logs groups embedding
Johnetordoff Jul 31, 2025
681a960
remove logs groups embedding
Johnetordoff Jul 31, 2025
9aed0ad
Merge branch 'refactor-notifications' of https://github.com/CenterFor…
Johnetordoff Aug 1, 2025
bb1d1f5
re-expose quickfiles migrated logs
Johnetordoff Aug 1, 2025
519b710
mock mail for tests
Johnetordoff Aug 1, 2025
4c50c6c
fix mail mocking issues for password reset
Johnetordoff Aug 1, 2025
e228bd4
Merge branch 'feature/pbs-25-13' of https://github.com/CenterForOpenS…
Johnetordoff Aug 4, 2025
8bbe32f
Merge branch 'feature/digest_notifications_update' of github.com:john…
Johnetordoff Aug 4, 2025
40db424
Merge branch 'refactor-notifications' of https://github.com/CenterFor…
Johnetordoff Aug 4, 2025
496fc23
fix boa send_mail
Johnetordoff Aug 4, 2025
a73fb3a
remove old archiver test
Johnetordoff Aug 4, 2025
466685a
fix migrate management command
Johnetordoff Aug 4, 2025
a4e1fab
Merge branch 'feature/notifications_admin' of https://github.com/Osta…
Johnetordoff Aug 4, 2025
96db17a
refactor email subscriptions into separate tasks
Johnetordoff Aug 5, 2025
5993dad
improve digests by queuing emails with retry mechanism condensing ema…
Johnetordoff Aug 6, 2025
e7319cd
write reverse migration for notification indexes
Johnetordoff Aug 6, 2025
e2d70b1
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 7, 2025
5c6c61e
fix migrations
Johnetordoff Aug 7, 2025
5ef1089
update celery to remove old tasks that sent notifications
Johnetordoff Aug 7, 2025
a6cc270
fix issue with subscriptions without types
Johnetordoff Aug 8, 2025
9686ae4
update notification subscription get or create to create the notifica…
Johnetordoff Aug 8, 2025
7fef010
delete old send email task
Johnetordoff Aug 8, 2025
21a54f4
double import celery
Johnetordoff Aug 8, 2025
f624258
fix file updated signal issues
Johnetordoff Aug 8, 2025
263b952
fix double imports again
Johnetordoff Aug 8, 2025
93f9544
clean-up celery worker
Johnetordoff Aug 9, 2025
725d79d
clean-up celery worker by moving to base dir
Johnetordoff Aug 9, 2025
fd85623
clean up notifications v1 routes and file update events
Johnetordoff Aug 9, 2025
0f793a9
fix template and notification capture issues
Johnetordoff Aug 9, 2025
e7a8e3c
fix schema response template issues
Johnetordoff Aug 9, 2025
eae2207
stop notify contributors in tests
Johnetordoff Aug 10, 2025
fcce6d4
improve notification mocking
Johnetordoff Aug 10, 2025
d2dd171
notifications DB optimization
Ostap-Zherebetskyi Aug 11, 2025
c92ca40
improve notification mocking
Johnetordoff Aug 10, 2025
04a91be
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 11, 2025
6fc1923
fix password reset template
Johnetordoff Aug 11, 2025
229e08b
fix legacy subscriptions
Johnetordoff Aug 11, 2025
839af9a
fix legacy subscriptions
Johnetordoff Aug 11, 2025
efee288
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 11, 2025
bcb085d
fix template tests
Johnetordoff Aug 11, 2025
7c8c7dd
use TEST_ENV instead of DEV_MODE
Johnetordoff Aug 11, 2025
c8c73f0
fix sendgrid mailer
Johnetordoff Aug 11, 2025
a1fb86d
fix up collection submission templates
Johnetordoff Aug 12, 2025
5e817c8
Merge branch 'refactor-notifications' of https://github.com/CenterFor…
Johnetordoff Aug 12, 2025
51c416b
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Johnetordoff Aug 12, 2025
d2e4925
new mailer code
Johnetordoff Aug 12, 2025
68b68ac
fix template code
Johnetordoff Aug 13, 2025
9658544
fix notification save
Ostap-Zherebetskyi Aug 13, 2025
f9043b6
fix mailer code
Johnetordoff Aug 13, 2025
a2dd86a
removes OSF Groups
Johnetordoff Aug 12, 2025
46e8726
Merge branch 'develop' into refactor-notifications
Johnetordoff Aug 13, 2025
18e6e89
fix mailer template
Johnetordoff Aug 13, 2025
5a0d535
more test fixes
Johnetordoff Aug 18, 2025
944692a
reintroduce quickfiles db constraint
Johnetordoff Aug 18, 2025
13d22f7
more template fixes
Johnetordoff Aug 18, 2025
d9d0d0b
fix issue with user institutional messages
Johnetordoff Aug 18, 2025
95bea2d
fix add contributor defaults
Johnetordoff Aug 19, 2025
b87fa3f
fix add a new public project notification
Johnetordoff Aug 19, 2025
aecc2ed
fix collection submissions
Johnetordoff Aug 19, 2025
0776c2a
Merge branch 'feature/notifications_DB_optimization' into add-new-not…
Johnetordoff Aug 19, 2025
2939b71
more template fixes
Johnetordoff Aug 19, 2025
1901d84
update mako templates
Johnetordoff Aug 19, 2025
baea6eb
clean-uo new public projects emails
Johnetordoff Aug 19, 2025
208d0ba
fix forking node notification issues
Johnetordoff Aug 20, 2025
8bb9287
fix preprint emails
Johnetordoff Aug 20, 2025
873f28d
refactored migrate_notifications.py
bodintsov Aug 21, 2025
9cac232
cleaning
bodintsov Aug 21, 2025
3fed9a4
fix notify comment template context var
Johnetordoff Aug 21, 2025
dbe1f2f
fix more templates
Johnetordoff Aug 21, 2025
980a986
fix up node update assertions
Johnetordoff Aug 21, 2025
0f43255
fix up node update assertions
Johnetordoff Aug 21, 2025
57d7a1a
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Johnetordoff Aug 21, 2025
7c41d2b
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 21, 2025
877cccb
remove silencing now defaulted no sends
Johnetordoff Aug 21, 2025
9ffac6f
fix issue with throttle not recognizing subed object
Johnetordoff Aug 21, 2025
95e749d
fix mailhog tests
Johnetordoff Aug 21, 2025
f512919
fix more template problems
Johnetordoff Aug 21, 2025
cc0689e
fix up more templates
Johnetordoff Aug 21, 2025
679ee8d
fix up institutional access request mocking
Johnetordoff Aug 21, 2025
f1d560d
fix up institutional access request mocking
Johnetordoff Aug 21, 2025
de372a2
mailhog provider tests
Ostap-Zherebetskyi Aug 18, 2025
6dda64c
update provider emails tests
Ostap-Zherebetskyi Aug 21, 2025
0e5d22a
fixed mutable reference problem
Ostap-Zherebetskyi Aug 22, 2025
0304ab5
fix mailhog provider tests
Ostap-Zherebetskyi Aug 22, 2025
05e692c
fix indentation in test_mailhog_received_mail method
Ostap-Zherebetskyi Aug 22, 2025
6178df1
fix double quoted strings
Ostap-Zherebetskyi Aug 22, 2025
c4c2649
fix tests tried to use SendGrid
Ostap-Zherebetskyi Aug 22, 2025
07af650
fix submissions tests
Johnetordoff Aug 22, 2025
ce48563
fix api_tests/mailhog/provider/test_schema_responses tests
Ostap-Zherebetskyi Aug 22, 2025
f8245d3
fix draft registration tests
Johnetordoff Aug 22, 2025
547aaad
fix collection submission tests
Johnetordoff Aug 22, 2025
a0f238b
fix institutional request system
Johnetordoff Aug 22, 2025
6038ce2
fix reviewable templates
Johnetordoff Aug 22, 2025
eb4452b
registration withdraw requests fixes
Johnetordoff Aug 22, 2025
72b7280
fix more template errors
Aug 24, 2025
7f2066f
fix more template errors
Aug 24, 2025
bc54d93
clean up desk notifications
Aug 24, 2025
1f237f5
add contributor default notification types
Aug 24, 2025
6fb6e7f
add contributor default notification types
Johnetordoff Aug 24, 2025
aeba2aa
remove sendgrid whiltelist
Johnetordoff Aug 25, 2025
14e26f3
Merge branch 'feature/subscriptions-migration' of https://github.com/…
Johnetordoff Aug 25, 2025
c836a71
Merge branch 'feature/provider_test_coverage' of https://github.com/O…
Johnetordoff Aug 25, 2025
62918d2
merge the tests attribute
Johnetordoff Aug 25, 2025
0e73a2a
add more test fixes
Johnetordoff Aug 25, 2025
5591ea2
add more test fixes
Johnetordoff Aug 25, 2025
ea2503a
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 25, 2025
64ff3b0
fix population notification template updating
Johnetordoff Aug 25, 2025
a243f12
fix population notification template updating
Johnetordoff Aug 25, 2025
244b54f
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 25, 2025
abf316d
fix schema response tests
Johnetordoff Aug 25, 2025
04268ba
add dry_run arg
Johnetordoff Aug 25, 2025
c977eaa
Merge branch 'add-new-notifications-data-model' of https://github.com…
Aug 25, 2025
b9caab4
fix draft registration add contributors notifications
Aug 25, 2025
a0f1aa5
add dry_run arg
Johnetordoff Aug 25, 2025
0cd2fab
clean-up admin and collection submission tests
Johnetordoff Aug 26, 2025
872bafe
assert no notifications
Johnetordoff Aug 26, 2025
1983847
assert no notifications
Johnetordoff Aug 26, 2025
5089376
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Aug 26, 2025
01690b1
fix preprint factory issue
Johnetordoff Aug 26, 2025
54f0999
fix py socket problem
Johnetordoff Aug 26, 2025
b981312
fix notifications
Johnetordoff Aug 26, 2025
1d55350
update addon tests
Johnetordoff Aug 27, 2025
7a8e401
update institutional addon tests
Johnetordoff Aug 27, 2025
1c43a13
fix misc issues
Johnetordoff Aug 27, 2025
b643b79
Merge branch 'add-new-notifications-data-model' of https://github.com…
Aug 27, 2025
30351cd
fix misc issues
Johnetordoff Aug 27, 2025
6b90076
clean-up auth views code
Johnetordoff Aug 28, 2025
e460497
fix curator logging
Johnetordoff Aug 28, 2025
7ba77c1
Merge branch 'add-new-notifications-data-model' of https://github.com…
Aug 28, 2025
7ff55b2
clean-up more context variables
Aug 28, 2025
cceab95
clean-up more context variables
Johnetordoff Aug 28, 2025
36db21e
Merge branch 'refactor-notifications' of https://github.com/CenterFor…
Johnetordoff Aug 29, 2025
68cf978
update more tests
Johnetordoff Aug 29, 2025
6799824
more template fixes
Johnetordoff Aug 29, 2025
c0aa54d
Merge branch 'add-new-notifications-data-model' of https://github.com…
Aug 30, 2025
dc24645
clean-up more collections submission
Aug 30, 2025
a98d958
fix tests
Aug 30, 2025
b241b26
update tests
Aug 30, 2025
05aad5e
update tests
Johnetordoff Aug 30, 2025
282defc
revert ResourceContributorsCreateSerializer refactor
Johnetordoff Aug 31, 2025
499d823
revert some syntax changes to shrink diff
Johnetordoff Aug 31, 2025
c646a43
Merge branch 'add-new-notifications-data-model' of https://github.com…
Aug 31, 2025
d3c238c
update moderation notification tests
Aug 31, 2025
8937680
update moderation notification tests
Aug 31, 2025
5109912
Merge branch 'add-new-notifications-data-model' of https://github.com…
Sep 1, 2025
de56134
fix submission templates
Sep 1, 2025
7981aaf
update subjects and mailhog tests
Sep 1, 2025
bf9a444
update subjects and mailhog tests
Sep 1, 2025
f985d70
Merge branch 'add-new-notifications-data-model' of https://github.com…
Sep 1, 2025
0a46af1
clean-up submissions collection tests
Johnetordoff Sep 1, 2025
698ce5d
add more test fixes
Johnetordoff Sep 1, 2025
6816040
update tests
Sep 1, 2025
6733701
fix mailhog tests
Sep 1, 2025
b8fdc80
fix more test stuff
Sep 2, 2025
89dc4ed
fix more test stuff
Sep 2, 2025
1f5adb4
Merge branch 'add-new-notifications-data-model' of https://github.com…
Sep 2, 2025
c88a2da
fix review_flow tests
Johnetordoff Sep 2, 2025
80ab307
fix submissions flow tests
Johnetordoff Sep 2, 2025
b7102b0
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Johnetordoff Sep 2, 2025
ab02fa7
fix generate site map tests
Johnetordoff Sep 2, 2025
114c130
fix broken merge
Johnetordoff Sep 2, 2025
6244b56
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Sep 2, 2025
9124543
fix schema response tests
Johnetordoff Sep 2, 2025
860430b
fix datacite and sanctions tests
Johnetordoff Sep 2, 2025
02d0b13
fix more sanctions tests
Johnetordoff Sep 2, 2025
335eafd
fix more sanctions tests
Johnetordoff Sep 2, 2025
da3d15a
fix TestPreprintCreate
Ostap-Zherebetskyi Sep 3, 2025
9b9a9de
Merge pull request #11277 from Ostap-Zherebetskyi/fix/TestPreprintCreate
Johnetordoff Sep 3, 2025
f9bd245
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Sep 3, 2025
eb33db2
fix archiver tests
Johnetordoff Sep 3, 2025
7d082a4
clean up more tests
Johnetordoff Sep 3, 2025
c274041
fix notifications tests
Johnetordoff Sep 3, 2025
c0b1314
fix template notification tests
Johnetordoff Sep 3, 2025
ff7010d
fix template notification tests
Johnetordoff Sep 3, 2025
b24de31
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Sep 3, 2025
1ae1a92
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Sep 3, 2025
9e898a0
fix approve pending schema tests
Johnetordoff Sep 3, 2025
bd15318
fix test user tests
Johnetordoff Sep 3, 2025
f46eb8a
fix test registrations
Johnetordoff Sep 3, 2025
d03d5fa
fix more tests
Johnetordoff Sep 3, 2025
02b7adf
fix collection submission tests
Johnetordoff Sep 3, 2025
200fcf8
fix misc errors
Sep 3, 2025
e8f7e1f
revert celery changes
Sep 3, 2025
efc3a81
add test fixes
Sep 4, 2025
bc0ec38
add test fixes
Johnetordoff Sep 4, 2025
287ae30
remove legacy tests
Johnetordoff Sep 4, 2025
f9003e8
fix more test notification silences
Johnetordoff Sep 4, 2025
566ca6a
fix make public captures
Johnetordoff Sep 4, 2025
a28feef
revert test class changes
Johnetordoff Sep 4, 2025
33d6fda
revert
Johnetordoff Sep 5, 2025
e2dcfe5
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
Johnetordoff Sep 8, 2025
ee98f7f
revert more old changes
Johnetordoff Sep 8, 2025
4f988c9
revert more old changes
Johnetordoff Sep 8, 2025
27d4ec4
Merge branch 'add-new-notifications-data-model' of https://github.com…
Johnetordoff Sep 8, 2025
76ae430
refactor migration command for legacy notifications
Ostap-Zherebetskyi Sep 8, 2025
ea5839c
Merge pull request #11287 from Ostap-Zherebetskyi/feature/notificatio…
Johnetordoff Sep 8, 2025
9e638ef
fix throttle
Johnetordoff Sep 8, 2025
13fc874
add support for merged accounts and fix mock
Johnetordoff Sep 8, 2025
2f2d281
add create folder file event
Johnetordoff Sep 8, 2025
26a8c28
fix multiple add contrbutors
Johnetordoff Sep 9, 2025
d9ca75f
fix throttle test mocking
Johnetordoff Sep 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
68 changes: 49 additions & 19 deletions addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from framework.flask import redirect
from framework.sentry import log_exception
from framework.transactions.handlers import no_auto_transaction
from website import mails
from website import settings
from addons.base import signals as file_signals
from addons.base.utils import format_last_known_metadata, get_mfr_url
Expand All @@ -52,7 +51,7 @@
DraftRegistration,
Guid,
FileVersionUserMetadata,
FileVersion
FileVersion, NotificationType
)
from osf.metrics import PreprintView, PreprintDownload
from osf.utils import permissions
Expand All @@ -64,7 +63,7 @@
from website.util import rubeus

# import so that associated listener is instantiated and gets emails
from website.notifications.events.files import FileEvent # noqa
from notifications.file_event_notifications import FileEvent # noqa

ERROR_MESSAGES = {'FILE_GONE': """
<style>
Expand Down Expand Up @@ -576,20 +575,25 @@ def create_waterbutler_log(payload, **kwargs):
params=payload
)

if payload.get('email') is True or payload.get('errors'):
mails.send_mail(
user.username,
mails.FILE_OPERATION_FAILED if payload.get('errors')
else mails.FILE_OPERATION_SUCCESS,
action=payload['action'],
source_node=source_node,
destination_node=destination_node,
source_path=payload['source']['materialized'],
source_addon=payload['source']['addon'],
destination_addon=payload['destination']['addon'],
osf_support_email=settings.OSF_SUPPORT_EMAIL
if payload.get('email') or payload.get('errors'):
if payload.get('email'):
notification_type = NotificationType.Type.USER_FILE_OPERATION_SUCCESS.instance
if payload.get('errors'):
notification_type = NotificationType.Type.USER_FILE_OPERATION_FAILED.instance
notification_type.emit(
user=user,
subscribed_object=node,
event_context={
'user_fullname': user.fullname,
'action': payload['action'],
'source_node': source_node,
'destination_node': destination_node,
'source_path': payload['source']['materialized'],
'source_addon': payload['source']['addon'],
'destination_addon': payload['destination']['addon'],
'osf_support_email': settings.OSF_SUPPORT_EMAIL
}
)

if payload.get('errors'):
# Action failed but our function succeeded
# Bail out to avoid file_signals
Expand All @@ -605,18 +609,44 @@ def create_waterbutler_log(payload, **kwargs):
update_storage_usage_with_size(payload)

with transaction.atomic():
file_signals.file_updated.send(target=node, user=user, event_type=action, payload=payload)

file_signals.file_updated.send(target=node, user=user, payload=payload)
return {'status': 'success'}


@file_signals.file_updated.connect
def addon_delete_file_node(self, target, user, event_type, payload):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice event_type is gone as that was always derived from the payload anyway, cleans up the logic a lot.

def emit_notification(self, target, user, payload, *args, **kwargs):
notification_types = {
'rename': NotificationType.Type.ADDON_FILE_RENAMED.instance,
'copy': NotificationType.Type.ADDON_FILE_COPIED.instance,
'create': NotificationType.Type.FILE_UPDATED.instance,
'move': NotificationType.Type.ADDON_FILE_MOVED.instance,
'delete': NotificationType.Type.FILE_REMOVED.instance,
'update': NotificationType.Type.FILE_UPDATED.instance,
'create_folder': NotificationType.Type.FOLDER_CREATED.instance,
}
notification_type = notification_types[payload.get('action')]
if notification_type not in notification_types.values():
raise NotImplementedError(f'Notification type {notification_type} is not supported')
notification_type.emit(
user=user,
subscribed_object=target,
event_context={
'profile_image_url': user.profile_image_url(),
'localized_timestamp': str(timezone.now()),
'message': payload.get('message'),
'user_fullname': user.fullname,
'url': target.absolute_url,
}
)

@file_signals.file_updated.connect
def addon_delete_file_node(self, target, user, payload):
""" Get addon BaseFileNode(s), move it into the TrashedFileNode collection
and remove it from StoredFileNode.
Required so that the guids of deleted addon files are not re-pointed when an
addon file or folder is moved or renamed.
"""
event_type = payload['action']
if event_type == 'file_removed' and payload.get('provider', None) != 'osfstorage':
provider = payload['provider']
path = payload['metadata']['path']
Expand Down
64 changes: 33 additions & 31 deletions addons/boa/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
from addons.boa.boa_error_code import BoaErrorCode
from framework import sentry
from framework.celery_tasks import app as celery_app
from osf.models import OSFUser
from osf.models import OSFUser, NotificationType
from osf.utils.fields import ensure_str, ensure_bytes
from website import settings as osf_settings
from website.mails import send_mail, ADDONS_BOA_JOB_COMPLETE, ADDONS_BOA_JOB_FAILURE

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -184,18 +183,19 @@ async def submit_to_boa_async(host, username, password, user_guid, project_guid,

logger.info('Successfully uploaded query output to OSF.')
logger.debug('Task ends <<<<<<<<')
await sync_to_async(send_mail)(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it was necessary for this to be async

to_addr=user.username,
mail=ADDONS_BOA_JOB_COMPLETE,
fullname=user.fullname,
query_file_name=query_file_name,
query_file_full_path=file_full_path,
output_file_name=output_file_name,
job_id=boa_job.id,
project_url=project_url,
boa_job_list_url=boa_settings.BOA_JOB_LIST_URL,
boa_support_email=boa_settings.BOA_SUPPORT_EMAIL,
osf_support_email=osf_settings.OSF_SUPPORT_EMAIL,
NotificationType.Type.ADDONS_BOA_JOB_COMPLETE.instance.emit(
user=user,
event_context={
'fullname': user.fullname,
'query_file_name': query_file_name,
'query_file_full_path': file_full_path,
'output_file_name': output_file_name,
'job_id': boa_job.id,
'project_url': project_url,
'boa_job_list_url': boa_settings.BOA_JOB_LIST_URL,
'boa_support_email': boa_settings.BOA_SUPPORT_EMAIL,
'osf_support_email': osf_settings.OSF_SUPPORT_EMAIL,
}
)
return BoaErrorCode.NO_ERROR

Expand All @@ -209,22 +209,24 @@ def handle_boa_error(message, code, username, fullname, project_url, query_file_
sentry.log_message(message, skip_session=True)
except Exception:
pass
send_mail(
to_addr=username,
mail=ADDONS_BOA_JOB_FAILURE,
fullname=fullname,
code=code,
message=message,
query_file_name=query_file_name,
file_size=file_size,
max_file_size=boa_settings.MAX_SUBMISSION_SIZE,
query_file_full_path=query_file_full_path,
output_file_name=output_file_name,
job_id=job_id,
max_job_wait_hours=boa_settings.MAX_JOB_WAITING_TIME / 3600,
project_url=project_url,
boa_job_list_url=boa_settings.BOA_JOB_LIST_URL,
boa_support_email=boa_settings.BOA_SUPPORT_EMAIL,
osf_support_email=osf_settings.OSF_SUPPORT_EMAIL,
NotificationType.Type.ADDONS_BOA_JOB_FAILURE.instance.emit(
destination_address=username,
event_context={
'user_fullname': fullname,
'code': code,
'query_file_name': query_file_name,
'file_size': file_size,
'message': message,
'max_file_size': boa_settings.MAX_SUBMISSION_SIZE,
'query_file_full_path': query_file_full_path,
'output_file_name': output_file_name,
'job_id': job_id,
'max_job_wait_hours': boa_settings.MAX_JOB_WAITING_TIME / 3600,
'project_url': project_url,
'boa_job_list_url': boa_settings.BOA_JOB_LIST_URL,
'boa_support_email': boa_settings.BOA_SUPPORT_EMAIL,
'osf_support_email': osf_settings.OSF_SUPPORT_EMAIL,

}
)
return code
54 changes: 21 additions & 33 deletions addons/boa/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from addons.boa import settings as boa_settings
from addons.boa.boa_error_code import BoaErrorCode
from addons.boa.tasks import submit_to_boa, submit_to_boa_async, handle_boa_error
from osf.models import NotificationType
from osf_tests.factories import AuthUserFactory, ProjectFactory
from tests.base import OsfTestCase
from tests.utils import capture_notifications
from website import settings as osf_settings
from website.mails import ADDONS_BOA_JOB_COMPLETE, ADDONS_BOA_JOB_FAILURE

DEFAULT_REFRESH_JOB_INTERVAL = boa_settings.REFRESH_JOB_INTERVAL
DEFAULT_MAX_JOB_WAITING_TIME = boa_settings.MAX_JOB_WAITING_TIME
Expand All @@ -38,9 +39,6 @@ def setUp(self):
self.output_file_name = 'fake_boa_script_results.txt'
self.job_id = '1a2b3c4d5e6f7g8'

from conftest import start_mock_send_grid
self.mock_send_grid = start_mock_send_grid(self)

def tearDown(self):
super().tearDown()

Expand All @@ -55,27 +53,26 @@ def test_boa_error_code(self):
assert BoaErrorCode.FILE_TOO_LARGE_ERROR == 6
assert BoaErrorCode.JOB_TIME_OUT_ERROR == 7

@mock.patch('website.mails.settings.USE_EMAIL', True)
@mock.patch('website.mails.settings.USE_CELERY', False)
def test_handle_boa_error(self):
with mock.patch('addons.boa.tasks.sentry.log_message', return_value=None) as mock_sentry_log_message, \
mock.patch('addons.boa.tasks.logger.error', return_value=None) as mock_logger_error:
return_value = handle_boa_error(
self.error_message,
BoaErrorCode.UNKNOWN,
self.user_username,
self.user_fullname,
self.project_url,
self.file_full_path,
query_file_name=self.query_file_name,
file_size=self.file_size,
output_file_name=self.output_file_name,
job_id=self.job_id
)
self.mock_send_grid.assert_called()
mock_sentry_log_message.assert_called_with(self.error_message, skip_session=True)
mock_logger_error.assert_called_with(self.error_message)
assert return_value == BoaErrorCode.UNKNOWN
with mock.patch('addons.boa.tasks.sentry.log_message', return_value=None) as mock_sentry_log_message:
with mock.patch('addons.boa.tasks.logger.error', return_value=None) as mock_logger_error:
with capture_notifications() as notifications:
return_value = handle_boa_error(
self.error_message,
BoaErrorCode.UNKNOWN,
self.user_username,
self.user_fullname,
self.project_url,
self.file_full_path,
file_size=self.file_size,
output_file_name=self.output_file_name,
job_id=self.job_id
)
assert len(notifications['emits']) == 1
assert notifications['emits'][0]['type'] == NotificationType.Type.ADDONS_BOA_JOB_FAILURE
mock_sentry_log_message.assert_called_with(self.error_message, skip_session=True)
mock_logger_error.assert_called_with(self.error_message)
assert return_value == BoaErrorCode.UNKNOWN


class TestSubmitToBoa(OsfTestCase):
Expand Down Expand Up @@ -154,14 +151,6 @@ def setUp(self):
boa_settings.REFRESH_JOB_INTERVAL = DEFAULT_REFRESH_JOB_INTERVAL
boa_settings.MAX_JOB_WAITING_TIME = DEFAULT_MAX_JOB_WAITING_TIME

from conftest import start_mock_send_grid
self.mock_send_grid = start_mock_send_grid(self)

def tearDown(self):
super().tearDown()

@mock.patch('website.mails.settings.USE_EMAIL', True)
@mock.patch('website.mails.settings.USE_CELERY', False)
async def test_submit_success(self):
with mock.patch('osf.models.user.OSFUser.objects.get', return_value=self.user), \
mock.patch('osf.models.user.OSFUser.get_or_create_cookie', return_value=self.user_cookie), \
Expand Down Expand Up @@ -190,7 +179,6 @@ async def test_submit_success(self):
assert self.mock_job.refresh.call_count == 4
assert mock_async_sleep.call_count == 4
mock_close.assert_called()
self.mock_send_grid.assert_called()
mock_handle_boa_error.assert_not_called()

async def test_download_error(self):
Expand Down
7 changes: 5 additions & 2 deletions addons/osfstorage/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from osf import models
from addons.osfstorage import utils
from addons.osfstorage import settings
from tests.utils import capture_notifications
from website.files.exceptions import FileNodeCheckedOutError, FileNodeIsPrimaryFile

SessionStore = import_module(django_conf_settings.SESSION_ENGINE).SessionStore
Expand Down Expand Up @@ -745,7 +746,8 @@ def test_after_fork_copies_versions(self, node, node_settings, auth_obj):
version = factories.FileVersionFactory()
record.add_version(version)

fork = node.fork_node(auth_obj)
with capture_notifications():
fork = node.fork_node(auth_obj)
fork_node_settings = fork.get_addon('osfstorage')
fork_node_settings.reload()

Expand All @@ -757,7 +759,8 @@ def test_fork_reverts_to_node_storage_region(self, user2, region, region2, node,
"""
Despite different user regions defaults, the forked node always stay in the same region as it's orginal node.
"""
fork = node.fork_node(Auth(user2))
with capture_notifications():
fork = node.fork_node(Auth(user2))
assert fork.get_addon('osfstorage').region_id == region.id

# don't inherit or override region
Expand Down
7 changes: 5 additions & 2 deletions addons/wiki/tests/test_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from framework.auth import Auth
from django.utils import timezone
from addons.wiki.utils import to_mongo_key
from tests.utils import capture_notifications

from .config import EXAMPLE_DOCS, EXAMPLE_OPS

Expand Down Expand Up @@ -818,7 +819,8 @@ def test_uuids_differ_between_forks(self):
assert project_res.status_code == 200
self.project.reload()

fork = self.project.fork_node(Auth(self.user))
with capture_notifications():
fork = self.project.fork_node(Auth(self.user))
assert fork.is_fork_of(self.project)
fork_url = fork.web_url_for('project_wiki_view', wname=self.wname)
fork_res = self.app.get(fork_url, auth=self.user.auth)
Expand Down Expand Up @@ -1084,7 +1086,8 @@ def test_get_sharejs_uuid(self):
# Differs across projects and forks
project = ProjectFactory()
assert sharejs_uuid != get_sharejs_uuid(project, wname)
fork = self.project.fork_node(Auth(self.project.creator))
with capture_notifications():
fork = self.project.fork_node(Auth(self.project.creator))
assert sharejs_uuid != get_sharejs_uuid(fork, wname)

def test_generate_share_uuid(self):
Expand Down
12 changes: 1 addition & 11 deletions admin/common_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.contrib.auth import login, REDIRECT_FIELD_NAME, authenticate, logout

from osf.models.user import OSFUser
from osf.models import AdminProfile, AbstractProvider
from osf.models import AdminProfile
from admin.common_auth.forms import LoginForm, UserRegistrationForm, DeskUserForm


Expand Down Expand Up @@ -69,16 +69,6 @@ def form_valid(self, form):

# create AdminProfile for this new user
profile, created = AdminProfile.objects.get_or_create(user=osf_user)

for group in form.cleaned_data.get('group_perms'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Johnetordoff Should get done on demand now

osf_user.groups.add(group)
split = group.name.split('_')
group_type = split[0]
if group_type == 'reviews':
provider_id = split[2]
provider = AbstractProvider.objects.get(id=provider_id)
provider.notification_subscriptions.get(event_name='new_pending_submissions').add_user_to_subscription(osf_user, 'email_transactional')

osf_user.save()

if created:
Expand Down
4 changes: 1 addition & 3 deletions admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from admin.base.utils import change_embargo_date
from admin.base.views import GuidView
from admin.base.forms import GuidForm
from admin.notifications.views import detect_duplicate_notifications, delete_selected_notifications
from admin.notifications.views import delete_selected_notifications

from api.share.utils import update_share
from api.caching.tasks import update_storage_usage_cache
Expand Down Expand Up @@ -100,7 +100,6 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
node = self.get_object()

detailed_duplicates = detect_duplicate_notifications(node_id=node.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't have duplicate subscriptions, so no reason to detect,

children = node.get_nodes(is_node_link=False)
# Annotate guid because django templates prohibit accessing attributes that start with underscores
children = AbstractNode.objects.filter(
Expand All @@ -111,7 +110,6 @@ def get_context_data(self, **kwargs):
'STORAGE_LIMITS': settings.StorageLimits,
'node': node,
'children': children,
'duplicates': detailed_duplicates
})

return context
Expand Down
Loading