Skip to content

Use MinimalUserProfileSerializer for AccountViewSet for non-developers #23192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
23 changes: 22 additions & 1 deletion src/olympia/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,28 @@ def test_view_deleted(self):
response = self.client.get(self.url)
assert response.status_code == 404

def test_is_not_full_public_profile_because_not_developer(self):
def test_is_not_full_public_profile_because_not_developer_but_fields_present(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would rather this be two different tests, but since we are trying to cherry-pick no need.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is two tests:

  • test_is_not_full_public_profile_because_not_developer_but_fields_present tests the case with the shim
  • test_is_not_full_public_profile_because_not_developer_no_fields tests without the shim is, but as it's identical to the original test_is_not_full_public_profile_because_not_developer it doesn't show any changed lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the 2 sets of assertions in the first test.

# TODO: when mimimal-profile-has-all-fields-shim is removed for v5, we should
# change self.url to use v4 or v3
assert not self.user.has_full_profile
response = self.client.get(self.url) # No auth.
assert response.data['name'] == self.user.name
assert response.data['biography'] is None
assert 'email' not in response.data
assert response.data['url'] == absolutify(self.user.get_url_path())

# Login as a random user and check it's still not visible.
self.client.login_api(user_factory())
response = self.client.get(self.url)
assert response.data['name'] == self.user.name
assert response.data['biography'] is None
assert 'email' not in response.data
assert response.data['url'] == absolutify(self.user.get_url_path())

@override_settings(DRF_API_GATES={'v5': ()})
def test_is_not_full_public_profile_because_not_developer_no_fields(self):
# TODO: when mimimal-profile-has-all-fields-shim is removed for v5, we won't
# need the override_settings
assert not self.user.has_full_profile
response = self.client.get(self.url) # No auth.
assert response.data['name'] == self.user.name
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
from . import verify
from .serializers import (
AccountSuperCreateSerializer,
BaseUserSerializer,
FullUserProfileSerializer,
MinimalUserProfileSerializer,
SelfUserProfileSerializer,
UserNotificationSerializer,
)
Expand Down Expand Up @@ -506,7 +506,7 @@ def get_serializer_class(self):
elif self.get_object().has_full_profile:
return FullUserProfileSerializer
else:
return BaseUserSerializer
return MinimalUserProfileSerializer

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
Expand Down
Loading