Skip to content

Commit 2993988

Browse files
authored
API V3: use a restricted serializer for when showing org info from a project (#11732)
* API V3: use a restricted serializer for when showing org info from a project If a project is public, we don't want to show the organization information, but it can still be useful to see which organization the project belongs to. * Linter
1 parent cf49d99 commit 2993988

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

readthedocs/api/v3/serializers.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,12 @@ class Meta:
806806
"many": True,
807807
},
808808
),
809-
# NOTE: we use a serializer without expandable fields to avoid
810-
# leaking information about the organization through the project.
809+
# NOTE: we use a different serializer with just a subset of fields
810+
# to avoid leaking information about the organization through a public project.
811+
# Users can use the /api/v3/organizations/ endpoint to get more information
812+
# about the organization.
811813
"organization": (
812-
"readthedocs.api.v3.serializers.OrganizationSerializer",
814+
"readthedocs.api.v3.serializers.RestrictedOrganizationSerializer",
813815
# NOTE: we cannot have a Project with multiple organizations.
814816
{"source": "organizations.first"},
815817
),
@@ -1209,6 +1211,26 @@ class Meta:
12091211
)
12101212

12111213

1214+
class RestrictedOrganizationSerializer(serializers.ModelSerializer):
1215+
1216+
"""
1217+
Stripped version of the OrganizationSerializer to be used when listing projects.
1218+
1219+
This serializer is used to avoid leaking information about the organization through a public project.
1220+
Instead of checking if user has access to the organization, we just show the name and slug.
1221+
"""
1222+
1223+
_links = OrganizationLinksSerializer(source="*")
1224+
1225+
class Meta:
1226+
model = Organization
1227+
fields = (
1228+
"name",
1229+
"slug",
1230+
"_links",
1231+
)
1232+
1233+
12121234
class RemoteOrganizationSerializer(serializers.ModelSerializer):
12131235
class Meta:
12141236
model = RemoteOrganization

0 commit comments

Comments
 (0)