diff --git a/api/subscriptions/views.py b/api/subscriptions/views.py index d7dfb944ecb..8c5f67b74e6 100644 --- a/api/subscriptions/views.py +++ b/api/subscriptions/views.py @@ -99,6 +99,7 @@ def get_queryset(self): notification_type__name__in=_global_reviews, then=Value('global_reviews'), ), + default=Value('notification_type__name'), ), legacy_id=Case( When( @@ -113,6 +114,7 @@ def get_queryset(self): notification_type__name__in=_global_reviews, then=Value(f'{user_guid}_global_reviews'), ), + default=Value('notification_type__name'), ), ).distinct('legacy_id') @@ -121,6 +123,10 @@ def get_queryset(self): if filter_id: qs = qs.filter(legacy_id=filter_id) # convert to list comprehension because legacy_id is an annotation, not in DB + # Apply manual filter for event_name if requested + filter_event_name = self.request.query_params.get('filter[event_name]') + if filter_event_name: + qs = qs.filter(event_name__in=filter_event_name.split(',')) return qs diff --git a/api_tests/subscriptions/views/test_subscriptions_list.py b/api_tests/subscriptions/views/test_subscriptions_list.py index c376e260014..599df9ddcd6 100644 --- a/api_tests/subscriptions/views/test_subscriptions_list.py +++ b/api_tests/subscriptions/views/test_subscriptions_list.py @@ -91,7 +91,7 @@ def test_cannot_post_patch_put_or_delete(self, app, url, user): assert delete_res.status_code == 405 def test_multiple_values_filter(self, app, url, user): - res = app.get(url + '?filter[event_name]=comments,file_updated', auth=user.auth) + res = app.get(url + '?filter[event_name]=global_file_updated,files_updated', auth=user.auth) assert len(res.json['data']) == 2 for subscription in res.json['data']: subscription['attributes']['event_name'] in ['global', 'comments']