summaryrefslogtreecommitdiff
path: root/lib/gitlab/saml
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-04-05 19:20:18 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-04-05 19:20:18 -0500
commit518ec6b2660c55beba2833ce71b93774ed0a6c2a (patch)
treed178d7af31fc5e23d0999bc082c07bc908b5b8ef /lib/gitlab/saml
parente99855bfe4b4741d33d5575fdf1f0bc2edd85844 (diff)
downloadgitlab-ce-518ec6b2660c55beba2833ce71b93774ed0a6c2a.tar.gz
Changed config syntax and improved how chaanges in group memberships are handled when external groups is set up
Diffstat (limited to 'lib/gitlab/saml')
-rw-r--r--lib/gitlab/saml/config.rb4
-rw-r--r--lib/gitlab/saml/user.rb39
2 files changed, 14 insertions, 29 deletions
diff --git a/lib/gitlab/saml/config.rb b/lib/gitlab/saml/config.rb
index dade4c0fa6a..2b3cf840f61 100644
--- a/lib/gitlab/saml/config.rb
+++ b/lib/gitlab/saml/config.rb
@@ -9,11 +9,11 @@ module Gitlab
end
def groups
- options['groups_attribute']
+ options[:groups_attribute]
end
def external_groups
- options['external_groups']
+ options[:external_groups]
end
end
diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb
index 14eda337d9a..6ab165cf518 100644
--- a/lib/gitlab/saml/user.rb
+++ b/lib/gitlab/saml/user.rb
@@ -7,11 +7,6 @@ module Gitlab
module Saml
class User < Gitlab::OAuth::User
- def initialize(auth_hash)
- super
- update_user_attributes
- end
-
def save
super('SAML')
end
@@ -31,6 +26,18 @@ module Gitlab
@user ||= build_new_user
end
+ if external_users_enabled?
+ # Check if there is overlap between the user's groups and the external groups
+ # setting and set user as external or internal.
+ if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
+ # Avoid an unnecessary change of values and the subsequent save
+ @user.external = false if @user.external
+ else
+ # Avoid an unnecessary change of values and the subsequent save
+ @user.external = true unless @user.external
+ end
+ end
+
@user
end
@@ -48,16 +55,6 @@ module Gitlab
protected
- 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
@@ -69,18 +66,6 @@ module Gitlab
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