Add backwards compatibility for creating groups with a LDAP connection

parent 0929fbca
...@@ -44,12 +44,19 @@ module API ...@@ -44,12 +44,19 @@ module API
authenticated_as_admin! authenticated_as_admin!
required_attributes! [:name, :path] required_attributes! [:name, :path]
# TODO: Refactor to support multi-ldap group_attrs = attributes_for_keys [:name, :path]
attrs = attributes_for_keys [:name, :path, :ldap_cn, :ldap_access] @group = Group.new(group_attrs)
@group = Group.new(attrs)
@group.owner = current_user @group.owner = current_user
if @group.save if @group.save
# NOTE: add backwards compatibility for single ldap link
ldap_attrs = attributes_for_keys [:ldap_cn, :ldap_access]
if ldap_attrs.present?
@group.ldap_group_links.create({
cn: ldap_attrs[:ldap_cn],
group_access: ldap_attrs[:ldap_access]
})
end
present @group, with: Entities::Group present @group, with: Entities::Group
else else
not_found! not_found!
......
...@@ -110,6 +110,13 @@ describe API::API, api: true do ...@@ -110,6 +110,13 @@ describe API::API, api: true do
post api("/groups", admin), { name: 'test' } post api("/groups", admin), { name: 'test' }
response.status.should == 400 response.status.should == 400
end end
it "creates an ldap_group_link if ldap_cn and ldap_access are supplied" do
group_attributes = attributes_for(:group, ldap_cn: 'ldap-group', ldap_access: Gitlab::Access::DEVELOPER)
expect {
post api("/groups", admin), group_attributes
}.to change{ LdapGroupLink.count }.by(1)
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