Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion documentcloud/organizations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ def to_representation(self, instance):
if "monthly_credits" in self.fields:
# skip checks if we have already removed the fields
request = self.context and self.context.get("request")
view = self.context and self.context.get("view")
action = view.action if view else None
user = request and request.user
is_org = isinstance(instance, Organization)
if not (
is_org and user and user.is_authenticated and instance.has_member(user)
is_org
and user
and user.is_authenticated
and instance.has_member(user)
and action == "retrieve"
):
# only members may see AI credit information
self.fields.pop("monthly_credits")
Expand Down
1 change: 1 addition & 0 deletions documentcloud/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_retrieve_me_expanded(self, client, user):
response_json = json.loads(response.content)
context = {"request": MagicMock(), "view": MagicMock()}
context["request"].user = user
context["view"].action = "retrieve"
organization_serializer = OrganizationSerializer(
user.organization, context=context
)
Expand Down