Skip to content

Commit d7c263e

Browse files
authored
Use MinimalUserProfileSerializer for AccountViewSet for non-developers (#23192)
1 parent 59db5eb commit d7c263e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/olympia/accounts/tests/test_views.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,28 @@ def test_view_deleted(self):
12681268
response = self.client.get(self.url)
12691269
assert response.status_code == 404
12701270

1271-
def test_is_not_full_public_profile_because_not_developer(self):
1271+
def test_is_not_full_public_profile_because_not_developer_but_fields_present(self):
1272+
# TODO: when mimimal-profile-has-all-fields-shim is removed for v5, we should
1273+
# change self.url to use v4 or v3
1274+
assert not self.user.has_full_profile
1275+
response = self.client.get(self.url) # No auth.
1276+
assert response.data['name'] == self.user.name
1277+
assert response.data['biography'] is None
1278+
assert 'email' not in response.data
1279+
assert response.data['url'] == absolutify(self.user.get_url_path())
1280+
1281+
# Login as a random user and check it's still not visible.
1282+
self.client.login_api(user_factory())
1283+
response = self.client.get(self.url)
1284+
assert response.data['name'] == self.user.name
1285+
assert response.data['biography'] is None
1286+
assert 'email' not in response.data
1287+
assert response.data['url'] == absolutify(self.user.get_url_path())
1288+
1289+
@override_settings(DRF_API_GATES={'v5': ()})
1290+
def test_is_not_full_public_profile_because_not_developer_no_fields(self):
1291+
# TODO: when mimimal-profile-has-all-fields-shim is removed for v5, we won't
1292+
# need the override_settings
12721293
assert not self.user.has_full_profile
12731294
response = self.client.get(self.url) # No auth.
12741295
assert response.data['name'] == self.user.name

src/olympia/accounts/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
from . import verify
6969
from .serializers import (
7070
AccountSuperCreateSerializer,
71-
BaseUserSerializer,
7271
FullUserProfileSerializer,
72+
MinimalUserProfileSerializer,
7373
SelfUserProfileSerializer,
7474
UserNotificationSerializer,
7575
)
@@ -506,7 +506,7 @@ def get_serializer_class(self):
506506
elif self.get_object().has_full_profile:
507507
return FullUserProfileSerializer
508508
else:
509-
return BaseUserSerializer
509+
return MinimalUserProfileSerializer
510510

511511
def destroy(self, request, *args, **kwargs):
512512
instance = self.get_object()

0 commit comments

Comments
 (0)