diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-25 20:07:45 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-10-02 13:35:09 +0300 |
commit | 011c168bff7174ce4b2defe239aa8d5031aa8269 (patch) | |
tree | 3cf09368b4bd58fd2477a43f99c8a7d253da687e /lib/gitlab/ldap/user.rb | |
parent | cd85a558dc3e568b327e2b0502b59b34d17b19bd (diff) |
Refactors SAML identity creation in gl_user.
Diffstat (limited to 'lib/gitlab/ldap/user.rb')
-rw-r--r-- | lib/gitlab/ldap/user.rb | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 3bf27b37ae6..1793097363e 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -17,41 +17,19 @@ module Gitlab end end - def initialize(auth_hash) - super - update_user_attributes - end - def save super('LDAP') end # instance methods - def gl_user - @gl_user ||= find_by_uid_and_provider || find_by_email || build_new_user + def find_user + find_by_uid_and_provider || find_by_email || build_new_user end def find_by_uid_and_provider self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider) end - def find_by_email - ::User.find_by(email: auth_hash.email.downcase) if auth_hash.has_attribute?(:email) - end - - def update_user_attributes - if persisted? - # find_or_initialize_by doesn't update `gl_user.identities`, and isn't autosaved. - identity = gl_user.identities.find { |identity| identity.provider == auth_hash.provider } - identity ||= gl_user.identities.build(provider: auth_hash.provider) - - # For a new identity set extern_uid to the LDAP DN - # For an existing identity with matching email but changed DN, update the DN. - # For an existing identity with no change in DN, this line changes nothing. - identity.extern_uid = auth_hash.uid - end - end - def changed? gl_user.changed? || gl_user.identities.any?(&:changed?) end |