Commit 518ec6b2 authored by Patricio Cano's avatar Patricio Cano

Changed config syntax and improved how chaanges in group memberships are...

Changed config syntax and  improved how chaanges in group memberships are handled when external groups is set up
parent e99855bf
......@@ -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
......
......@@ -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
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