fix: add feature flag to has_object_permission method (#2198)

fix: add feature flag to has_object_permission method (#2198)

diff --git a/ankihub/decks/api/permissions.py b/ankihub/decks/api/permissions.py
index 8838eae..a31276d 100644
--- a/ankihub/decks/api/permissions.py
+++ b/ankihub/decks/api/permissions.py
@@ -1,5 +1,6 @@
 from django.urls import reverse
 from rest_framework.permissions import BasePermission
+from waffle import flag_is_active
 
 from ankihub.deck_extensions.models import DeckExtension
 from ankihub.decks.models import ChangeNoteSuggestion, Deck, NewNoteSuggestion, Note
@@ -31,9 +32,12 @@ class HasDeckAccess(BasePermission):
     )
 
     def has_object_permission(self, request, view, obj):
-        return obj.sponsored or request.user.has_perm(
-            "memberships.has_access", "paid_decks_collaboration"
-        )
+        if flag_is_active(request, "new_pricing_tier"):
+            return obj.sponsored or request.user.has_perm(
+                "memberships.has_access", "paid_decks_collaboration"
+            )
+
+        return obj.sponsored or request.user.has_active_membership
 
 
 class HasRelationToDeck(BasePermission):
diff --git a/ankihub/decks/api/tests/test_notes_api.py b/ankihub/decks/api/tests/test_notes_api.py
index 578e9a7..010a9ef 100644
--- a/ankihub/decks/api/tests/test_notes_api.py
+++ b/ankihub/decks/api/tests/test_notes_api.py
@@ -4,6 +4,7 @@ import pytest
 from django.urls import reverse
 from knox.models import AuthToken
 from rest_framework.exceptions import ValidationError
+from waffle.testutils import override_flag
 
 from ankihub.decks.api import permissions
 from ankihub.decks.api.serializers import InputNoteSerializer
@@ -53,6 +54,21 @@ class TestNoteRetrieveAPIView:
         response = api_client.get(reverse("api:decks:get-note", args=[note.id]))
         assert response.status_code == 401
 
+    @override_flag("new_pricing_tier", active=True)
+    def test_queries_count_get_note_by_id_as_owner_new_pricing_tier_active(
+        self, api_client_subscribed, django_assert_num_queries, anki_user
+    ):
+        deck = DeckFactory(owner=anki_user)
+        for _ in range(30):
+            NoteFactory(deck=deck)
+        note = NoteFactory(deck=deck)
+        with django_assert_num_queries(11):
+            response = api_client_subscribed.get(
+                reverse("api:decks:get-note", args=[note.id])
+            )
+            assert response.status_code == 200
+
+    @override_flag("new_pricing_tier", active=False)
     def test_queries_count_get_note_by_id_as_owner(
         self, api_client_subscribed, django_assert_num_queries, anki_user
     ):
@@ -60,7 +76,7 @@ class TestNoteRetrieveAPIView:
         for _ in range(30):
             NoteFactory(deck=deck)
         note = NoteFactory(deck=deck)
-        with django_assert_num_queries(10):
+        with django_assert_num_queries(8):
             response = api_client_subscribed.get(
                 reverse("api:decks:get-note", args=[note.id])
             )

GitHub
sha: 9ce99c37d98cd7c95d752402ebe41ad2d645f23f