Merge pull request #10965 from tchellomello/fix_ldap_dn

Associates ldap_dn on a first User() login
This commit is contained in:
Marcelo Moreira de Mello 2021-08-31 14:25:26 -04:00 committed by GitHub
commit 9588ff3b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -395,10 +395,17 @@ def on_populate_user(sender, **kwargs):
remove = bool(team_opts.get('remove', True))
_update_m2m_from_groups(user, ldap_user, team.member_role.members, users_opts, remove)
# Check if user.profile is available, otherwise force user.save()
try:
_ = user.profile
except ValueError:
force_user_update = True
finally:
if force_user_update:
user.save()
# Update user profile to store LDAP DN.
if force_user_update:
user.save()
profile = user.profile
if profile.ldap_dn != ldap_user.dn:
profile.ldap_dn = ldap_user.dn
profile.save()
profile = user.profile
if profile.ldap_dn != ldap_user.dn:
profile.ldap_dn = ldap_user.dn
profile.save()