Update groups only by own provider

parent 55526227
......@@ -6,6 +6,8 @@ class LdapGroupLink < ActiveRecord::Base
validates :cn, uniqueness: { scope: [:group_id, :provider] }
validates :group_access, inclusion: { in: Gitlab::Access.all_values }
scope :with_provider, ->(provider) { where(provider: provider) }
def access_field
group_access
end
......
......@@ -133,7 +133,8 @@ module Gitlab
end
def ldap_groups
@ldap_groups ||= ::LdapGroupLink.distinct(:cn).pluck(:cn).map do |cn|
@ldap_groups ||= ::LdapGroupLink.with_provider(provider)
distinct(:cn).pluck(:cn).map do |cn|
Gitlab::LDAP::Group.find_by_cn(cn, adapter)
end.compact
end
......@@ -164,7 +165,8 @@ module Gitlab
private
def gitlab_groups_with_ldap_link
::Group.includes(:ldap_group_links).references(:ldap_group_links).
where.not(ldap_group_links: { id: nil })
where.not(ldap_group_links: { id: nil }).
where(ldap_group_links: { provider: provider })
end
# Get the group_access for a give user.
......
module Gitlab
module LDAP
class Group
def self.find_by_cn(cn, adapter=nil)
adapter ||= Gitlab::LDAP::Adapter.new
def self.find_by_cn(cn, adapter)
adapter.group(cn)
end
......@@ -66,10 +65,6 @@ module Gitlab
def entry
@entry
end
def adapter
@adapter ||= Gitlab::LDAP::Adapter.new
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