Commit 2ec2a906 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Add group projects API options for including shared and subgroups

parent 08ddb655
...@@ -60,7 +60,17 @@ module API ...@@ -60,7 +60,17 @@ module API
def find_group_projects(params) def find_group_projects(params)
group = find_group!(params[:id]) group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group: group, current_user: current_user, params: project_finder_params).execute options = {
only_owned: !params[:include_shared],
include_subgroups: params[:include_subgroups]
}
projects = GroupProjectsFinder.new(
group: group,
current_user: current_user,
params: project_finder_params,
options: options
).execute
projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled] projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled] projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
projects = reorder_projects(projects) projects = reorder_projects(projects)
...@@ -201,6 +211,8 @@ module API ...@@ -201,6 +211,8 @@ module API
optional :starred, type: Boolean, default: false, desc: 'Limit by starred status' optional :starred, type: Boolean, default: false, desc: 'Limit by starred status'
optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature' optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature'
optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature' optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature'
optional :include_subgroups, type: Boolean, default: false, desc: 'Includes projects in subgroups of this group'
optional :include_shared, type: Boolean, default: true, desc: 'Include projects shared to this group'
use :pagination use :pagination
use :with_custom_attributes use :with_custom_attributes
......
...@@ -502,6 +502,32 @@ describe API::Groups do ...@@ -502,6 +502,32 @@ describe API::Groups do
expect(json_response.first['name']).to eq(public_project.name) expect(json_response.first['name']).to eq(public_project.name)
end end
it 'returns projects excluding shared' do
create(:project_group_link, project: create(:project), group: group1)
create(:project_group_link, project: create(:project), group: group1)
create(:project_group_link, project: create(:project), group: group1)
get api("/groups/#{group1.id}/projects", user1), include_shared: false
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(2)
end
it 'returns projects including those in subgroups' do
subgroup = create(:group, parent: group1)
create(:project, group: subgroup)
create(:project, group: subgroup)
get api("/groups/#{group1.id}/projects", user1), include_subgroups: true
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(4)
end
it "does not return a non existing group" do it "does not return a non existing group" do
get api("/groups/1328/projects", user1) get api("/groups/1328/projects", user1)
......
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