Update groups only by own provider

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