diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-04-05 03:09:12 +0300 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-04-05 03:09:12 +0300 |
commit | 1a168279fa3eb87c2061917707397af21e7b26ea (patch) | |
tree | ab4724fe33cdae2e6c3f5083eb5a37ddea4f824d /lib/gitlab/saml/user.rb | |
parent | 67136007933425414293602bc75d2ba4822f2a93 (diff) |
Prepare SAML for group retrieval
Diffstat (limited to 'lib/gitlab/saml/user.rb')
-rw-r--r-- | lib/gitlab/saml/user.rb | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index b1e30110ef5..14eda337d9a 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -7,6 +7,11 @@ module Gitlab module Saml class User < Gitlab::OAuth::User + def initialize(auth_hash) + super + update_user_attributes + end + def save super('SAML') end @@ -18,7 +23,7 @@ module Gitlab @user ||= find_or_create_ldap_user end - if auto_link_saml_enabled? + if auto_link_saml_user? @user ||= find_by_email end @@ -37,11 +42,45 @@ module Gitlab end end + def changed? + gl_user.changed? || gl_user.identities.any?(&:changed?) + end + protected - def auto_link_saml_enabled? + def build_new_user + user = super + if external_users_enabled? + unless (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + user.external = true + end + end + user + end + + def auto_link_saml_user? Gitlab.config.omniauth.auto_link_saml_user end + + def external_users_enabled? + !Gitlab::Saml::Config.external_groups.nil? + end + + def auth_hash=(auth_hash) + @auth_hash = Gitlab::Saml::AuthHash.new(auth_hash) + end + + def update_user_attributes + if persisted? + if external_users_enabled? + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + gl_user.external = false + else + gl_user.external = true + end + end + end + end end end end |