Use provider based ldap config

parent 63132b75
...@@ -42,17 +42,17 @@ module Gitlab ...@@ -42,17 +42,17 @@ module Gitlab
end end
def update_permissions(user) def update_permissions(user)
if Gitlab.config.ldap['sync_ssh_keys'] if ldap_config['sync_ssh_keys']
update_ssh_keys(user) update_ssh_keys(user)
end end
# Skip updating group permissions # Skip updating group permissions
# if instance does not use group_base setting # if instance does not use group_base setting
return true unless Gitlab.config.ldap['group_base'].present? return true unless ldap_config['group_base'].present?
update_ldap_group_links(user) update_ldap_group_links(user)
if Gitlab.config.ldap['admin_group'].present? if ldap_config['admin_group'].present?
update_admin_status(user) update_admin_status(user)
end end
end end
...@@ -71,7 +71,7 @@ module Gitlab ...@@ -71,7 +71,7 @@ module Gitlab
(ldap_user.ssh_keys - user.keys.ldap.pluck(:key)).each do |key| (ldap_user.ssh_keys - user.keys.ldap.pluck(:key)).each do |key|
Rails.logger.info "#{self.class.name}: adding LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})" Rails.logger.info "#{self.class.name}: adding LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})"
new_key = LDAPKey.new(title: "LDAP - #{Gitlab.config.ldap['sync_ssh_keys']}", key: key) new_key = LDAPKey.new(title: "LDAP - #{ldap_config['sync_ssh_keys']}", key: key)
new_key.user = user new_key.user = user
unless new_key.save unless new_key.save
Rails.logger.error "#{self.class.name}: failed to add LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})\n"\ Rails.logger.error "#{self.class.name}: failed to add LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})\n"\
...@@ -100,7 +100,7 @@ module Gitlab ...@@ -100,7 +100,7 @@ module Gitlab
end end
def update_admin_status(user) def update_admin_status(user)
admin_group = Gitlab::LDAP::Group.find_by_cn(Gitlab.config.ldap['admin_group'], adapter) admin_group = Gitlab::LDAP::Group.find_by_cn(ldap_config['admin_group'], adapter)
if admin_group.has_member?(Gitlab::LDAP::Person.find_by_dn(user.extern_uid, adapter)) if admin_group.has_member?(Gitlab::LDAP::Person.find_by_dn(user.extern_uid, adapter))
unless user.admin? unless user.admin?
user.admin = true user.admin = true
...@@ -140,6 +140,10 @@ module Gitlab ...@@ -140,6 +140,10 @@ module Gitlab
end.map(&:cn) end.map(&:cn)
end end
def ldap_config
Gitlab::LDAP::Adapter.config_for(provider)
end
private private
def gitlab_groups_with_ldap_link def gitlab_groups_with_ldap_link
::Group.includes(:ldap_group_links).references(:ldap_group_links). ::Group.includes(:ldap_group_links).references(:ldap_group_links).
......
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