From 21653ee2c238a4e2102b409e3de91d0a20fafbc6 Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Tue, 22 Nov 2022 20:18:58 -0500 Subject: [PATCH 1/2] feat: Add email field to UserMappingView (cherry picked from commit 2ed3c202f6ba4b428ee74dcc6a2254f45edd604b) --- common/djangoapps/third_party_auth/api/serializers.py | 5 +++++ common/djangoapps/third_party_auth/api/views.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/common/djangoapps/third_party_auth/api/serializers.py b/common/djangoapps/third_party_auth/api/serializers.py index 3e8513de7312..22385b6a9686 100644 --- a/common/djangoapps/third_party_auth/api/serializers.py +++ b/common/djangoapps/third_party_auth/api/serializers.py @@ -9,6 +9,7 @@ class UserMappingSerializer(serializers.Serializer): # pylint: disable=abstract provider = None username = serializers.SerializerMethodField() remote_id = serializers.SerializerMethodField() + email = serializers.SerializerMethodField() def __init__(self, *args, **kwargs): self.provider = kwargs['context'].get('provider', None) @@ -21,3 +22,7 @@ def get_username(self, social_user): def get_remote_id(self, social_user): """ Gets remote id from social user based on provider """ return self.provider.get_remote_id_from_social_auth(social_user) + + def get_email(self, social_user): + """ Gets the edx email from a social user """ + return social_user.user.email diff --git a/common/djangoapps/third_party_auth/api/views.py b/common/djangoapps/third_party_auth/api/views.py index 97d1a7d6dba4..865eeab162ef 100644 --- a/common/djangoapps/third_party_auth/api/views.py +++ b/common/djangoapps/third_party_auth/api/views.py @@ -334,6 +334,8 @@ class UserMappingView(ListAPIView): * username: The edx username * remote_id: The Id from third party auth provider + + * email: The edx email """ authentication_classes = (JwtAuthentication, BearerAuthentication, ) permission_classes = (TPA_PERMISSIONS, ) From a214b3c6e503c1831e85f54b1da081d4aa4a12a1 Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Mon, 29 Jan 2024 15:20:10 -0500 Subject: [PATCH 2/2] fix: tests with extra mapping email field --- common/djangoapps/third_party_auth/api/tests/test_views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/third_party_auth/api/tests/test_views.py b/common/djangoapps/third_party_auth/api/tests/test_views.py index aea4c18367e6..8b13f4cfb7c2 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_views.py +++ b/common/djangoapps/third_party_auth/api/tests/test_views.py @@ -38,7 +38,10 @@ def get_mapping_data_by_usernames(usernames): """ Generate mapping data used in response """ - return [{'username': username, 'remote_id': 'remote_' + username} for username in usernames] + return [ + {"username": username, "remote_id": "remote_" + username, "email": f"{username}@example.com"} + for username in usernames + ] class TpaAPITestCase(ThirdPartyAuthTestMixin, APITestCase):