Commit 1eba9366 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

New API: share project with group

Share project with group using API.
You must be a master or owner of project in order to do it.

POST /projects/:id/share

Parameters:
  id (required) - The ID of a project
  group_id (required) - The ID of a group
  group_access (required) - Level of permissions for sharing
parent db93bec3
......@@ -140,5 +140,9 @@ module API
class LdapGroup < Grape::Entity
expose :cn
end
class ProjectGroupLink < Grape::Entity
expose :id, :project_id, :group_id, :group_access
end
end
end
......@@ -262,6 +262,29 @@ module API
{message: "Access revoked", id: params[:user_id].to_i}
end
end
# Share project with group
#
# Parameters:
# id (required) - The ID of a project
# group_id (required) - The ID of a group
# group_access (required) - Level of permissions for sharing
#
# Example Request:
# POST /projects/:id/share
post ":id/share" do
authorize! :admin_project, user_project
required_attributes! [:group_id, :group_access]
link = user_project.project_group_links.new
link.group_id = params[:group_id]
link.group_access = params[:group_access]
if link.save
present link, with: Entities::ProjectGroupLink
else
render_api_error!(link.errors.full_messages.first, 409)
end
end
end
end
end
......@@ -692,4 +692,35 @@ describe API::API do
end
end
end
describe "POST /projects/:id/share" do
let(:group) { create(:group) }
it "should share project with group" do
expect {
post api("/projects/#{project.id}/share", user), group_id: group.id,
group_access: Gitlab::Access::DEVELOPER
}.to change { ProjectGroupLink.count }.by(1)
response.status.should == 201
json_response['group_id'].should == group.id
json_response['group_access'].should == Gitlab::Access::DEVELOPER
end
it "should return a 400 error when group id is not given" do
post api("/projects/#{project.id}/share", user), group_access: Gitlab::Access::DEVELOPER
response.status.should == 400
end
it "should return a 400 error when access level is not given" do
post api("/projects/#{project.id}/share", user), group_id: group.id
response.status.should == 400
end
it "should return a 409 error when wrong params passed" do
post api("/projects/#{project.id}/share", user), group_id: group.id, group_access: 1234
response.status.should == 409
json_response['message'].should == 'Group access is not included in the list'
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