Skip to content

Commit cf68080

Browse files
committed
Update v2 subscription API for Ag and new data
1 parent d24cb2c commit cf68080

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

api/subscriptions/views.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.db.models import Value, When, Case, F, Q, OuterRef, Subquery
1+
from django.db.models import Value, When, Case, Q, OuterRef, Subquery
22
from django.db.models.fields import CharField, IntegerField
33
from django.db.models.functions import Concat, Cast
44
from django.contrib.contenttypes.models import ContentType
@@ -56,35 +56,38 @@ def get_queryset(self):
5656
id=Cast(OuterRef('object_id'), IntegerField()),
5757
).values('guids___id')[:1]
5858

59-
return NotificationSubscription.objects.filter(user=self.request.user).annotate(
59+
return NotificationSubscription.objects.filter(
60+
notification_type__in=[
61+
NotificationType.Type.USER_FILE_UPDATED.instance,
62+
NotificationType.Type.NODE_FILE_UPDATED.instance,
63+
NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance,
64+
],
65+
user=self.request.user,
66+
).annotate(
6067
event_name=Case(
6168
When(
62-
notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value,
69+
notification_type=NotificationType.Type.USER_FILE_UPDATED.instance,
6370
then=Value('files_updated'),
6471
),
6572
When(
66-
notification_type__name=NotificationType.Type.USER_FILE_UPDATED.value,
73+
notification_type=NotificationType.Type.USER_FILE_UPDATED.instance,
6774
then=Value('global_file_updated'),
6875
),
69-
default=F('notification_type__name'),
70-
output_field=CharField(),
7176
),
7277
legacy_id=Case(
7378
When(
74-
notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value,
79+
notification_type=NotificationType.Type.NODE_FILES_UPDATED.instance,
7580
then=Concat(Subquery(node_subquery), Value('_file_updated')),
7681
),
7782
When(
78-
notification_type__name=NotificationType.Type.USER_FILE_UPDATED.value,
83+
notification_type=NotificationType.Type.USER_FILE_UPDATED.instance,
7984
then=Value(f'{user_guid}_global'),
8085
),
8186
When(
82-
Q(notification_type__name=NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.value) &
87+
Q(notification_type=NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance) &
8388
Q(content_type=provider_ct),
8489
then=Concat(Subquery(provider_subquery), Value('_new_pending_submissions')),
8590
),
86-
default=F('notification_type__name'),
87-
output_field=CharField(),
8891
),
8992
)
9093

@@ -144,6 +147,11 @@ def get_object(self):
144147

145148
try:
146149
obj = NotificationSubscription.objects.annotate(
150+
notification_type__in=[
151+
NotificationType.Type.USER_FILE_UPDATED.instance,
152+
NotificationType.Type.NODE_FILE_UPDATED.instance,
153+
NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance,
154+
],
147155
legacy_id=Case(
148156
When(
149157
notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value,

osf/models/notification_subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def emit(
107107
@property
108108
def absolute_api_v2_url(self):
109109
from api.base.utils import absolute_reverse
110-
return absolute_reverse('institutions:institution-detail', kwargs={'institution_id': self._id, 'version': 'v2'})
110+
return absolute_reverse('subscriptions:subscription-detail', kwargs={'subscription_id': self._id, 'version': 'v2'})
111111

112112
@property
113113
def _id(self):

0 commit comments

Comments
 (0)