Skip to content

Commit 5d9b0be

Browse files
only show organization credit fields for single retrieves
1 parent e056ee4 commit 5d9b0be

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

documentcloud/organizations/serializers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ def to_representation(self, instance):
8282
if "monthly_credits" in self.fields:
8383
# skip checks if we have already removed the fields
8484
request = self.context and self.context.get("request")
85+
view = self.context and self.context.get("view")
86+
action = view.action if view else None
8587
user = request and request.user
8688
is_org = isinstance(instance, Organization)
8789
if not (
88-
is_org and user and user.is_authenticated and instance.has_member(user)
90+
is_org
91+
and user
92+
and user.is_authenticated
93+
and instance.has_member(user)
94+
and action == "retrieve"
8995
):
9096
# only members may see AI credit information
9197
self.fields.pop("monthly_credits")

documentcloud/users/tests/test_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def test_retrieve_me_expanded(self, client, user):
114114
response_json = json.loads(response.content)
115115
context = {"request": MagicMock(), "view": MagicMock()}
116116
context["request"].user = user
117+
context["view"].action = "retrieve"
117118
organization_serializer = OrganizationSerializer(
118119
user.organization, context=context
119120
)

0 commit comments

Comments
 (0)