Skip to content

Commit

Permalink
fix(users): correct comparing self invited_by_code
Browse files Browse the repository at this point in the history
  • Loading branch information
temirovazat committed Nov 16, 2023
1 parent 221fb9d commit 53bc76f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/api/v1/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def validate_invited_by_code(self, value):
"""
user = self.instance

if value == user.invite_code:
if value.lower() == user.invite_code.lower():
raise serializers.ValidationError('Cannot specify your own code.')

try:
Expand Down
5 changes: 5 additions & 0 deletions src/api/v1/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ def post(self, request):
{'invited_by_code': 'Неверный реферальный код.'},
status=status.HTTP_403_FORBIDDEN
)
if user.first().invite_code.lower() == invited_by_code.lower():
return Response(
{'invited_by_code': 'Нельзя использовать свой код.'},
status=status.HTTP_403_FORBIDDEN
)
user_data['invited_by_code'] = invited_by_code

user, _ = User.objects.update_or_create(
Expand Down
2 changes: 1 addition & 1 deletion src/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def clean(self):
"""
if self.invited_by_code:
if self.invited_by_code == self.invite_code:
if self.invited_by_code.lower() == self.invite_code.lower():
raise ValidationError(
{'invited_by_code': 'Cannot specify your own code.'}
)
Expand Down

0 comments on commit 53bc76f

Please sign in to comment.