77from framework .auth .decorators import must_be_logged_in
88from framework .exceptions import HTTPError
99
10- from osf .models import AbstractNode , Registration
10+ from osf .models import AbstractNode , Registration , Node
11+
1112NOTIFICATION_TYPES = {}
1213USER_SUBSCRIPTIONS_AVAILABLE = {}
1314NODE_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):
167165def 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
176173def 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