[ENG-10080] Create global_file_updated, global_reviews and node_file_updated subscriptions if missing#11556
Open
cslzchen wants to merge 20 commits intoCenterForOpenScience:feature/notifications-refactor-post-releasefrom
Conversation
* Use USER_FILE_UPDATED for group global_file_updated * Use REVIEWS_SUBMISSION_STATUS for group global_reviews
cslzchen
commented
Jan 20, 2026
Ostap-Zherebetskyi
requested changes
Jan 27, 2026
api/subscriptions/views.py
Outdated
Comment on lines
198
to
237
| if not existing_subscriptions.exists(): | ||
| # `global_file_updated` and `global_reviews` should exist by default for every user. | ||
| # If not found, create them with `none` frequency and `_is_digest=True` as default. | ||
| if subscription_id == f'{user_guid}_global_file_updated': | ||
| notification_type = user_file_updated_nt | ||
| content_type = user_ct | ||
| object_id = self.request.user.id | ||
| elif subscription_id == f'{user_guid}_global_reviews': | ||
| notification_type = reviews_submission_status_nt | ||
| content_type = user_ct | ||
| object_id = self.request.user.id | ||
| elif subscription_id.endswith('_global_file_updated') or subscription_id.endswith('_global_reviews'): | ||
| # Mismatched request user and subscription user | ||
| sentry.log_message(f'Permission denied: [user={user_guid}, legacy_id={subscription_id}]') | ||
| raise PermissionDenied | ||
| elif subscription_id.endswith('_files_updated'): | ||
| notification_type = node_file_updated_nt | ||
| content_type = node_ct | ||
| node_guid = subscription_id[:-len('_files_updated')] | ||
| node = AbstractNode.objects.filter(guids___id=node_guid, is_deleted=False, type='osf.node').first() | ||
| if not node: | ||
| # The node in the legacy subscription ID does not exist or is invalid | ||
| sentry.log_message(f'Node not found in legacy subscription ID: [user={user_guid}, legacy_id={subscription_id}]') | ||
| raise NotFound | ||
| if not node.is_contributor(self.request.user): | ||
| # The request user is not a contributor of the node | ||
| sentry.log_message(f'Permission denied: [user={user_guid}], node={node_guid}, legacy_id={subscription_id}]') | ||
| raise PermissionDenied | ||
| object_id = node.id | ||
| else: | ||
| sentry.log_message(f'Subscription not found: [user={user_guid}, legacy_id={subscription_id}]') | ||
| raise NotFound | ||
| missing_subscription_created = NotificationSubscription.objects.create( | ||
| notification_type=notification_type, | ||
| user=self.request.user, | ||
| content_type=content_type, | ||
| object_id=object_id, | ||
| _is_digest=True, | ||
| message_frequency='none', | ||
| ) |
Collaborator
There was a problem hiding this comment.
This needs to be moved to the SubscriptionList API view because users must have subscriptions before they can edit them.
| notification_id = res.json['data']['id'] | ||
| assert res.status_code == 200 | ||
| assert notification_id == f'{user._id}_global_file_updated' | ||
| res = app.get(url_user_global_reviews, auth=user.auth) |
| object_id=user_missing_subscriptions.id, | ||
| content_type=ContentType.objects.get_for_model(OSFUser) | ||
| ).exists() | ||
| res = app.get(url_user_global_file_updated_missing, auth=user_missing_subscriptions.auth) |
8a9fee8 to
8d9658f
Compare
Note: only works for when filter on "legacy id"; logs message to sentry for tracking purpose when filter on "event names".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
https://openscience.atlassian.net/browse/ENG-10080
Purpose
Create
global_file_updated,global_reviewsandnode_file_updatedsubscriptions if missingUSER_FILE_UPDATEDfor group_global_file_updatedREVIEWS_SUBMISSION_STATUSfor group_global_reviewsNODE_FILE_UPDATEDfor group_node_file_updatedChanges
global_file_updated,global_reviewsandnode_file_updatedsubscriptions if missing_is_digest=Truefor newly created OSF user and node default subscriptionslegacy_idfor serializer to handle newly created subscriptionsannotated_obj_qsfornode_file_updatedandglobal_reviewsSide Effects
N/A
QE Notes
N/A
CE Notes
N/A
Documentation
N/A