Commit d92f4280 authored by Douwe Maan's avatar Douwe Maan

Minor refactor

parent 4d2f3611
...@@ -44,13 +44,14 @@ module Gitlab ...@@ -44,13 +44,14 @@ module Gitlab
gl_user.skip_reconfirmation! gl_user.skip_reconfirmation!
gl_user.email = auth_hash.email gl_user.email = auth_hash.email
# If we don't have an identity for this provider yet, create one # find_or_initialize_by doesn't update `gl_user.identities`, and isn't autosaved.
if gl_user.identities.find_by(provider: auth_hash.provider).nil? identity = gl_user.identities.find { |identity| identity.provider == auth_hash.provider }
gl_user.identities.new(extern_uid: auth_hash.uid, provider: auth_hash.provider) identity ||= gl_user.identities.build(provider: auth_hash.provider)
else # Update the UID attribute for this provider in case it has changed
identity = gl_user.identities.select { |identity| identity.provider == auth_hash.provider } # For a new user set extern_uid to the LDAP DN
identity.first.extern_uid = auth_hash.uid # For an existing user with matching email but changed DN, update the DN.
end # For an existing user with no change in DN, this line changes nothing.
identity.extern_uid = auth_hash.uid
gl_user gl_user
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment