diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-07 17:41:59 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-07 17:41:59 +0000 |
commit | 6d09c1fed8f140670b6983faf536a7380e3271b0 (patch) | |
tree | ccec9bae2a81dc0e7226c0242533aac2cae13a1d /lib | |
parent | 986eff1cf230eee7792fcce8ebb1a00320a7f691 (diff) | |
parent | 469acd190e497cda8516da0ee481f33e038d7e9e (diff) | |
download | gitlab-ce-6d09c1fed8f140670b6983faf536a7380e3271b0.tar.gz |
Merge branch 'sync-email-from-omniauth' into 'master'
Sync email address from specified omniauth provider
See merge request !11268
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ldap/user.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/o_auth/user.rb | 17 |
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 2d5e47a6f3b..5e299e26c54 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -41,11 +41,6 @@ module Gitlab def update_user_attributes if persisted? - if auth_hash.has_email? - gl_user.skip_reconfirmation! - gl_user.email = auth_hash.email - end - # 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) @@ -55,10 +50,6 @@ module Gitlab # For an existing identity with no change in DN, this line changes nothing. identity.extern_uid = auth_hash.uid end - - gl_user.ldap_email = auth_hash.has_email? - - gl_user end def changed? @@ -69,6 +60,10 @@ module Gitlab ldap_config.block_auto_created_users end + def sync_email_from_provider? + true + end + def allowed? Gitlab::LDAP::Access.allowed?(gl_user) end diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb index afd24b4dcc5..7307f8c2c87 100644 --- a/lib/gitlab/o_auth/user.rb +++ b/lib/gitlab/o_auth/user.rb @@ -12,6 +12,7 @@ module Gitlab def initialize(auth_hash) self.auth_hash = auth_hash + update_email end def persisted? @@ -174,6 +175,22 @@ module Gitlab } end + def sync_email_from_provider? + auth_hash.provider.to_s == Gitlab.config.omniauth.sync_email_from_provider.to_s + end + + def update_email + if auth_hash.has_email? && sync_email_from_provider? + if persisted? + gl_user.skip_reconfirmation! + gl_user.email = auth_hash.email + end + + gl_user.external_email = true + gl_user.email_provider = auth_hash.provider + end + end + def log Gitlab::AppLogger end |