Skip to content

Commit 4b81676

Browse files
committed
fix legacy subscriptions
1 parent 32a14dd commit 4b81676

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

website/notifications/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ def get_configured_projects(user):
168168

169169
for subscription in user_subscriptions:
170170
# If the user has opted out of emails skip
171-
node = subscription.owner
171+
node = subscription.subscribed_object
172172

173-
if (
174-
(subscription.none.filter(id=user.id).exists() and not node.parent_id) or
175-
node._id not in user.notifications_configured
176-
):
173+
if subscription.message_frequency == 'none':
177174
continue
178175

179176
root = node.root
@@ -240,7 +237,10 @@ def format_data(user, nodes):
240237

241238
if can_read:
242239
node_sub_available = list(constants.NODE_SUBSCRIPTIONS_AVAILABLE.keys())
243-
subscriptions = get_all_node_subscriptions(user, node, user_subscriptions=user_subscriptions).filter(event_name__in=node_sub_available)
240+
subscriptions = get_all_node_subscriptions(
241+
user,
242+
node,
243+
user_subscriptions=user_subscriptions).filter(notification_type__name__in=node_sub_available)
244244

245245
for subscription in subscriptions:
246246
index = node_sub_available.index(getattr(subscription, 'event_name'))

website/notifications/views.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from framework.auth.decorators import must_be_logged_in
88
from framework.exceptions import HTTPError
99

10-
from osf.models import AbstractNode, Registration
10+
from osf.models import AbstractNode, Registration, Node
11+
1112
NOTIFICATION_TYPES = {}
1213
USER_SUBSCRIPTIONS_AVAILABLE = {}
1314
NODE_SUBSCRIPTIONS_AVAILABLE = {}
@@ -136,18 +137,15 @@ def get_configured_projects(user):
136137

137138
for subscription in user_subscriptions:
138139
# If the user has opted out of emails skip
139-
node = subscription.owner
140+
node = subscription.subscribed_object
140141

141-
if (
142-
(subscription.none.filter(id=user.id).exists() and not node.parent_id) or
143-
node._id not in user.notifications_configured
144-
):
142+
if subscription.message_frequency == 'none':
145143
continue
144+
if isinstance(node, Node):
145+
root = node.root
146146

147-
root = node.root
148-
149-
if not root.is_deleted:
150-
configured_projects.add(root)
147+
if not root.is_deleted:
148+
configured_projects.add(root)
151149

152150
return sorted(configured_projects, key=lambda n: n.title.lower())
153151

@@ -167,10 +165,9 @@ def check_project_subscriptions_are_all_none(user, node):
167165
def get_all_user_subscriptions(user, extra=None):
168166
""" Get all Subscription objects that the user is subscribed to"""
169167
NotificationSubscription = apps.get_model('osf.NotificationSubscription')
170-
queryset = NotificationSubscription.objects.filter(
168+
return NotificationSubscription.objects.filter(
171169
user=user,
172170
)
173-
return queryset.filter(extra) if extra else queryset
174171

175172

176173
def get_all_node_subscriptions(user, node, user_subscriptions=None):
@@ -213,7 +210,13 @@ def format_data(user, nodes):
213210

214211
if can_read:
215212
node_sub_available = list(NODE_SUBSCRIPTIONS_AVAILABLE.keys())
216-
subscriptions = get_all_node_subscriptions(user, node, user_subscriptions=user_subscriptions).filter(event_name__in=node_sub_available)
213+
subscriptions = get_all_node_subscriptions(
214+
user,
215+
node,
216+
user_subscriptions=user_subscriptions
217+
).filter(
218+
notification_type__name__in=node_sub_available
219+
)
217220

218221
for subscription in subscriptions:
219222
index = node_sub_available.index(getattr(subscription, 'event_name'))
@@ -254,7 +257,7 @@ def format_user_subscriptions(user):
254257
event_description=user_subs_available.pop(user_subs_available.index(getattr(subscription, 'event_name')))
255258
)
256259
for subscription in get_all_user_subscriptions(user)
257-
if subscription is not None and getattr(subscription, 'event_name') in user_subs_available
260+
if subscription is not None in user_subs_available
258261
]
259262
subscriptions.extend([serialize_event(user, event_description=sub) for sub in user_subs_available])
260263
return subscriptions
@@ -534,10 +537,4 @@ def configure_subscription(auth):
534537
)
535538
subscription.save()
536539

537-
if node and node._id not in user.notifications_configured:
538-
user.notifications_configured[node._id] = True
539-
user.save()
540-
541-
subscription.save()
542-
543540
return {'message': f'Successfully subscribed to {notification_type} list on {event_id}'}

0 commit comments

Comments
 (0)