From 0c1fc5080524ecdd5f099ac9c65f85dabee15af4 Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Mon, 24 Nov 2025 12:56:19 +0200 Subject: [PATCH 1/3] fix notifications settings --- api/subscriptions/views.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/api/subscriptions/views.py b/api/subscriptions/views.py index 8f15677d643..64009228612 100644 --- a/api/subscriptions/views.py +++ b/api/subscriptions/views.py @@ -6,7 +6,7 @@ from rest_framework import permissions as drf_permissions from rest_framework.exceptions import NotFound from django.core.exceptions import ObjectDoesNotExist, PermissionDenied - +from rest_framework.response import Response from framework.auth.oauth_scopes import CoreScopes from api.base.views import JSONAPIBaseView from api.base.filters import ListFilterMixin @@ -88,7 +88,7 @@ def get_queryset(self): then=Value(f'{user_guid}_global_reviews'), ), ), - ) + ).distinct('legacy_id') # Apply manual filter for legacy_id if requested filter_id = self.request.query_params.get('filter[id]') @@ -158,7 +158,7 @@ def get_object(self): raise NotFound try: - obj = obj.filter(user=self.request.user).get() + obj = obj.filter(user=self.request.user).first() except ObjectDoesNotExist: raise PermissionDenied @@ -169,12 +169,32 @@ def update(self, request, *args, **kwargs): """ Update a notification subscription """ - ret = super().update(request, *args, **kwargs) - # Copy global_reviews subscription changes to new_pending_submissions subscriptions [ENG-9666] - if self.get_object().notification_type.name == NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.value: + if '_global_file_updated' in self.kwargs['subscription_id']: + # Copy _global_file_updated subscription changes to all file subscriptions + qs = NotificationSubscription.objects.filter( + user=self.request.user, + notification_type__name__in=[ + NotificationType.Type.USER_FILE_UPDATED.value, + NotificationType.Type.FILE_ADDED.value, + NotificationType.Type.FILE_REMOVED.value, + NotificationType.Type.ADDON_FILE_COPIED.value, + NotificationType.Type.ADDON_FILE_RENAMED.value, + NotificationType.Type.ADDON_FILE_MOVED.value, + NotificationType.Type.ADDON_FILE_REMOVED.value, + NotificationType.Type.FOLDER_CREATED.value, + ], + ) + for instance in qs: + serializer = self.get_serializer(instance=instance, data=request.data, partial=True) + serializer.is_valid(raise_exception=True) + self.perform_update(serializer) + return Response(serializer.data) + elif '_global_reviews' in self.kwargs['subscription_id']: + # Copy global_reviews subscription changes to all provider subscriptions [ENG-9666] qs = NotificationSubscription.objects.filter( user=self.request.user, notification_type__name__in=[ + NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.value, NotificationType.Type.PROVIDER_REVIEWS_SUBMISSION_CONFIRMATION.value, NotificationType.Type.PROVIDER_REVIEWS_RESUBMISSION_CONFIRMATION.value, NotificationType.Type.PROVIDER_NEW_PENDING_WITHDRAW_REQUESTS.value, @@ -185,7 +205,10 @@ def update(self, request, *args, **kwargs): serializer = self.get_serializer(instance=instance, data=request.data, partial=True) serializer.is_valid(raise_exception=True) self.perform_update(serializer) - return ret + return Response(serializer.data) + else: + ret = super().update(request, *args, **kwargs) + return ret class AbstractProviderSubscriptionDetail(SubscriptionDetail): From 27d7129ba5bce42ea3cc18acf273633378754bee Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Mon, 24 Nov 2025 13:52:08 +0200 Subject: [PATCH 2/3] fix unit tests --- api/subscriptions/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/subscriptions/views.py b/api/subscriptions/views.py index 64009228612..6438e3f56e6 100644 --- a/api/subscriptions/views.py +++ b/api/subscriptions/views.py @@ -161,6 +161,8 @@ def get_object(self): obj = obj.filter(user=self.request.user).first() except ObjectDoesNotExist: raise PermissionDenied + if not obj: + raise PermissionDenied self.check_object_permissions(self.request, obj) return obj @@ -184,6 +186,9 @@ def update(self, request, *args, **kwargs): NotificationType.Type.FOLDER_CREATED.value, ], ) + if not qs.exists(): + raise PermissionDenied + for instance in qs: serializer = self.get_serializer(instance=instance, data=request.data, partial=True) serializer.is_valid(raise_exception=True) @@ -201,6 +206,9 @@ def update(self, request, *args, **kwargs): NotificationType.Type.REVIEWS_SUBMISSION_STATUS.value, ], ) + if not qs.exists(): + raise PermissionDenied + for instance in qs: serializer = self.get_serializer(instance=instance, data=request.data, partial=True) serializer.is_valid(raise_exception=True) From 330f6164487efbfe809f162381944987f7490d6e Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Mon, 24 Nov 2025 14:52:46 +0200 Subject: [PATCH 3/3] fix review comments --- api/subscriptions/views.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/subscriptions/views.py b/api/subscriptions/views.py index 6438e3f56e6..c1cd36186e1 100644 --- a/api/subscriptions/views.py +++ b/api/subscriptions/views.py @@ -157,10 +157,7 @@ def get_object(self): except ObjectDoesNotExist: raise NotFound - try: - obj = obj.filter(user=self.request.user).first() - except ObjectDoesNotExist: - raise PermissionDenied + obj = obj.filter(user=self.request.user).first() if not obj: raise PermissionDenied @@ -215,8 +212,7 @@ def update(self, request, *args, **kwargs): self.perform_update(serializer) return Response(serializer.data) else: - ret = super().update(request, *args, **kwargs) - return ret + return super().update(request, *args, **kwargs) class AbstractProviderSubscriptionDetail(SubscriptionDetail):