provisionning: use actual field's max_length when truncating (#56411)

This commit is contained in:
Benjamin Dauvergne 2021-08-26 16:19:45 +02:00
parent e6ce17b1dc
commit cd1e3ce53e
2 changed files with 9 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import random
from django.contrib.auth.models import Group
from django.db import IntegrityError
from django.db.models.query import Q
from django.db.transaction import atomic
from hobo.agent.common.models import Role
@ -77,7 +78,9 @@ class NotificationProcessing:
user = mellon_user.user
except UserSAMLIdentifier.DoesNotExist:
try:
user = User.objects.get(username=o['uuid'][:30])
user = User.objects.get(
Q(username=o['uuid'][:30]) | Q(username=o['uuid'][:150])
)
except User.DoesNotExist:
# temp user object
random_uid = str(random.randint(1, 10000000000000))
@ -86,9 +89,9 @@ class NotificationProcessing:
user=user, issuer=issuer, name_id=o['uuid']
)
user.first_name = o['first_name'][:30]
user.last_name = o['last_name'][:30]
user.email = o['email'][:75]
user.username = o['uuid'][:30]
user.last_name = o['last_name'][:150]
user.email = o['email'][:254]
user.username = o['uuid'][:150]
user.is_superuser = o['is_superuser']
user.is_staff = o['is_superuser']
user.is_active = o.get('is_active', True)

View File

@ -278,7 +278,7 @@ def test_provision_users(tenants):
assert Role.objects.count() == 1
assert Group.objects.count() == 1
user = User.objects.get()
assert user.username == 'a' * 30
assert user.username == 'a' * 32
assert user.first_name == 'John'
assert user.last_name == 'Doe'
assert user.email == 'john.doe@example.net'
@ -331,7 +331,7 @@ def test_provision_users(tenants):
assert Role.objects.count() == 1
assert Group.objects.count() == 1
user = User.objects.get()
assert user.username == 'a' * 30
assert user.username == 'a' * 32
assert user.first_name == 'John'
assert user.last_name == 'Doe'
assert user.email == 'john.doe@example.net'