Skip to content

Commit 738b056

Browse files
committed
Fix existing Cyberstorm views permission classes
1 parent 332ca7e commit 738b056

File tree

9 files changed

+20
-9
lines changed

9 files changed

+20
-9
lines changed

django/thunderstore/api/cyberstorm/tests/test_team.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def test_team_api_view__for_inactive_team__returns_404(
5757

5858

5959
@pytest.mark.django_db
60-
def test_team_membership_permission__for_unauthenticated_user__returns_401(
60+
def test_team_membership_permission__for_no_user__returns_403(
6161
api_client: APIClient,
6262
team: Team,
6363
):
6464
response = api_client.get(f"/api/cyberstorm/team/{team.name}/member/")
6565

66-
assert response.status_code == 401
66+
assert response.status_code == 403
6767

6868

6969
@pytest.mark.django_db

django/thunderstore/api/cyberstorm/views/community.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from rest_framework.generics import RetrieveAPIView
2+
from rest_framework.permissions import AllowAny
23

34
from thunderstore.api.cyberstorm.serializers import CyberstormCommunitySerializer
45
from thunderstore.api.utils import CyberstormAutoSchemaMixin
@@ -8,7 +9,7 @@
89
class CommunityAPIView(CyberstormAutoSchemaMixin, RetrieveAPIView):
910
lookup_url_kwarg = "community_id"
1011
lookup_field = "identifier"
11-
permission_classes = []
12+
permission_classes = [AllowAny]
1213

1314
# Unlisted communities are included, as direct links to them should work.
1415
queryset = Community.objects.all()

django/thunderstore/api/cyberstorm/views/community_filters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from rest_framework import serializers
22
from rest_framework.generics import get_object_or_404
3+
from rest_framework.permissions import AllowAny
34
from rest_framework.request import Request
45
from rest_framework.response import Response
56
from rest_framework.views import APIView
@@ -23,6 +24,7 @@ class CommunityFiltersAPIView(APIView):
2324
they can be used as filters.
2425
"""
2526

27+
permission_classes = [AllowAny]
2628
queryset = Community.objects.prefetch_related("package_categories")
2729
serializer_class = CommunityFiltersAPIViewSerializer
2830

django/thunderstore/api/cyberstorm/views/community_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rest_framework.filters import SearchFilter
22
from rest_framework.generics import ListAPIView
33
from rest_framework.pagination import PageNumberPagination
4+
from rest_framework.permissions import AllowAny
45

56
from thunderstore.api.cyberstorm.serializers import CyberstormCommunitySerializer
67
from thunderstore.api.ordering import StrictOrderingFilter
@@ -13,7 +14,7 @@ class CommunityPaginator(PageNumberPagination):
1314

1415

1516
class CommunityListAPIView(CyberstormAutoSchemaMixin, ListAPIView):
16-
permission_classes = []
17+
permission_classes = [AllowAny]
1718
serializer_class = CyberstormCommunitySerializer
1819
pagination_class = CommunityPaginator
1920
queryset = Community.objects.listed()

django/thunderstore/api/cyberstorm/views/markdown.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.http import Http404
44
from rest_framework import serializers
55
from rest_framework.generics import RetrieveAPIView, get_object_or_404
6+
from rest_framework.permissions import AllowAny
67

78
from thunderstore.api.utils import CyberstormAutoSchemaMixin
89
from thunderstore.markdown.templatetags.markdownify import render_markdown
@@ -20,6 +21,7 @@ class PackageVersionReadmeAPIView(CyberstormAutoSchemaMixin, RetrieveAPIView):
2021
If no version number is provided, the latest version is used.
2122
"""
2223

24+
permission_classes = [AllowAny]
2325
serializer_class = CyberstormMarkdownResponseSerializer
2426

2527
def get_object(self):
@@ -39,6 +41,7 @@ class PackageVersionChangelogAPIView(CyberstormAutoSchemaMixin, RetrieveAPIView)
3941
If no version number is provided, the latest version is used.
4042
"""
4143

44+
permission_classes = [AllowAny]
4245
serializer_class = CyberstormMarkdownResponseSerializer
4346

4447
def get_object(self):

django/thunderstore/api/cyberstorm/views/package_listing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from rest_framework import serializers
1616
from rest_framework.generics import RetrieveAPIView, get_object_or_404
17+
from rest_framework.permissions import AllowAny
1718

1819
from thunderstore.api.cyberstorm.serializers import (
1920
CyberstormPackageCategorySerializer,
@@ -114,6 +115,7 @@ class ResponseSerializer(serializers.Serializer):
114115

115116

116117
class PackageListingAPIView(CyberstormAutoSchemaMixin, RetrieveAPIView):
118+
permission_classes = [AllowAny]
117119
serializer_class = ResponseSerializer
118120

119121
def get_object(self):

django/thunderstore/api/cyberstorm/views/package_listing_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rest_framework import serializers
1313
from rest_framework.generics import ListAPIView, get_object_or_404
1414
from rest_framework.pagination import PageNumberPagination
15+
from rest_framework.permissions import AllowAny
1516

1617
from thunderstore.api.cyberstorm.serializers import CyberstormPackagePreviewSerializer
1718
from thunderstore.api.utils import conditional_swagger_auto_schema
@@ -105,6 +106,7 @@ class BasePackageListAPIView(ListAPIView):
105106
methods, whereas the rest are overwritten methods from ListAPIView.
106107
"""
107108

109+
permission_classes = [AllowAny]
108110
pagination_class = PackageListPaginator
109111
serializer_class = CyberstormPackagePreviewSerializer
110112
viewname: str = "" # Define in subclass

django/thunderstore/api/cyberstorm/views/package_version_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from rest_framework import serializers
22
from rest_framework.generics import ListAPIView, get_object_or_404
3+
from rest_framework.permissions import AllowAny
34

45
from thunderstore.api.utils import CyberstormAutoSchemaMixin
56
from thunderstore.repository.models import Package
@@ -18,6 +19,7 @@ class PackageVersionListAPIView(CyberstormAutoSchemaMixin, ListAPIView):
1819
Return a list of available versions of the package.
1920
"""
2021

22+
permission_classes = [AllowAny]
2123
serializer_class = CyberstormPackageVersionSerializer
2224

2325
def get_queryset(self):

django/thunderstore/api/cyberstorm/views/team.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework import serializers
33
from rest_framework.exceptions import PermissionDenied, ValidationError
44
from rest_framework.generics import ListAPIView, RetrieveAPIView, get_object_or_404
5-
from rest_framework.permissions import IsAuthenticated
5+
from rest_framework.permissions import AllowAny
66
from rest_framework.request import Request
77
from rest_framework.response import Response
88
from rest_framework.views import APIView
@@ -23,6 +23,7 @@
2323

2424

2525
class TeamAPIView(CyberstormAutoSchemaMixin, RetrieveAPIView):
26+
permission_classes = [AllowAny]
2627
serializer_class = CyberstormTeamSerializer
2728
queryset = Team.objects.exclude(is_active=False)
2829
lookup_field = "name__iexact"
@@ -34,8 +35,6 @@ class TeamRestrictedAPIView(ListAPIView):
3435
Ensure the user is a member of the Team.
3536
"""
3637

37-
permission_classes = [IsAuthenticated]
38-
3938
def check_permissions(self, request: Request) -> None:
4039
super().check_permissions(request)
4140

@@ -47,6 +46,7 @@ def check_permissions(self, request: Request) -> None:
4746

4847

4948
class TeamMemberListAPIView(CyberstormAutoSchemaMixin, TeamRestrictedAPIView):
49+
permission_classes = [AllowAny]
5050
serializer_class = CyberstormTeamMemberSerializer
5151
filter_backends = [StrictOrderingFilter]
5252
ordering = ["-role", "user__username"]
@@ -73,8 +73,6 @@ class CyberstormTeamAddMemberResponseSerialiazer(serializers.Serializer):
7373

7474

7575
class TeamMemberAddAPIView(APIView):
76-
permission_classes = [IsAuthenticated]
77-
7876
@conditional_swagger_auto_schema(
7977
request_body=CyberstormTeamAddMemberRequestSerialiazer,
8078
responses={200: CyberstormTeamAddMemberResponseSerialiazer},

0 commit comments

Comments
 (0)