Skip to content

Commit e88cfb9

Browse files
committed
API v3: less overrides
So, conditionally setting attributes at the class is good, but when running tests it doesn't re-evaluate the class, so we are stuck with the previous values. Since no project on .org has organizations/teams it doesn't matter exposing these fields (they return null, empty when passed to ?expand=).
1 parent 1dcccfc commit e88cfb9

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

readthedocs/api/v3/permissions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rest_framework.permissions import IsAuthenticated, BasePermission
1+
from rest_framework.permissions import BasePermission, IsAuthenticated
22

33
from readthedocs.core.utils.extend import SettingsOverrideObject
44

@@ -17,7 +17,7 @@ def has_permission(self, request, view):
1717
return True
1818

1919

20-
class PublicDetailPrivateListing(IsAuthenticated):
20+
class PublicDetailPrivateListing(BasePermission):
2121

2222
"""
2323
Permission class for our custom use case.

readthedocs/api/v3/serializers.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -592,26 +592,22 @@ class Meta:
592592
{
593593
'many': True,
594594
}
595-
)
595+
),
596+
'organization': (
597+
'readthedocs.api.v3.serializers.OrganizationSerializer',
598+
# NOTE: we cannot have a Project with multiple organizations.
599+
{'source': 'organizations.first'},
600+
),
601+
'teams': (
602+
serializers.SlugRelatedField,
603+
{
604+
'slug_field': 'slug',
605+
'many': True,
606+
'read_only': True,
607+
},
608+
),
596609
}
597610

598-
if settings.RTD_ALLOW_ORGANIZATIONS:
599-
expandable_fields.update({
600-
'organization': (
601-
'readthedocs.api.v3.serializers.OrganizationSerializer',
602-
# NOTE: we cannot have a Project with multiple organizations.
603-
{'source': 'organizations.first'},
604-
),
605-
'teams': (
606-
serializers.SlugRelatedField,
607-
{
608-
'slug_field': 'slug',
609-
'many': True,
610-
'read_only': True,
611-
},
612-
),
613-
})
614-
615611
def get_homepage(self, obj):
616612
# Overridden only to return ``None`` when the project_url is ``''``
617613
return obj.project_url or None

readthedocs/api/v3/tests/mixins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def setUp(self):
4343
# objects (like a Project for translations/subprojects)
4444
self.project = fixture.get(
4545
Project,
46+
id=1,
4647
pub_date=self.created,
4748
modified_date=self.modified,
4849
description='Project description',

readthedocs/api/v3/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class ProjectsViewSetBase(APIv3Settings, NestedViewSetMixin, ProjectQuerySetMixi
120120
'active_versions',
121121
'active_versions.last_build',
122122
'active_versions.last_build.config',
123+
'organization',
124+
'teams',
123125
]
124126

125127
def get_view_name(self):

0 commit comments

Comments
 (0)