Skip to content
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

fix(users): remove campo de "last_name" que pode ser undefined #85

Merged
merged 3 commits into from
Nov 15, 2023
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
6 changes: 4 additions & 2 deletions api/users/backends/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ def get_user_data(cls, access_token: str) -> dict | None:
def do_auth(user_data: dict) -> User | None:
user, created = User.objects.get_or_create(
first_name=user_data['given_name'],
last_name=user_data['family_name'],
email=user_data['email'],
)

if user_data.get('family_name'):
user.last_name = user_data['family_name']

if created:
user.email = user_data['email']
user.save()

return user
1 change: 0 additions & 1 deletion api/users/simplejwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def validate(self, attrs: dict[str, any]) -> dict[str, any]:
user = jwt_authentication.get_user(validated_token)

data["first_name"] = str(user.first_name)
data["last_name"] = str(user.last_name)
data["email"] = str(user.email)

return data
2 changes: 0 additions & 2 deletions api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def test_google_register_with_valid_token(self) -> None:

created_user = users.get(email='[email protected]')
self.assertEqual(created_user.first_name, 'given_name')
self.assertEqual(created_user.last_name, 'family_name')
self.assertEqual(created_user.email, '[email protected]')
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -239,7 +238,6 @@ def test_user_login_with_valid_token(self) -> None:

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['first_name'], self.user.first_name)
self.assertEqual(response.data['last_name'], self.user.last_name)
self.assertEqual(response.data['email'], self.user.email)

def test_user_login_access_token(self) -> None:
Expand Down
1 change: 0 additions & 1 deletion api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def post(self, request: Request, *args, **kwargs) -> Response:
'access': str(refresh.access_token),
'refresh': str(refresh),
'first_name': user.first_name,
'last_name': user.last_name,
'email': user.email,
}

Expand Down