Commit 7e9a8bb7 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'api-fix-group-projects-filter' into 'master'

API: Add the project filter to the groups endpoint.

Related to #22928. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/25420

See merge request !8034
parents b83a9138 81a12c10
...@@ -117,11 +117,20 @@ module API ...@@ -117,11 +117,20 @@ module API
success Entities::Project success Entities::Project
end end
params do params do
optional :archived, type: Boolean, default: false, desc: 'Limit by archived status'
optional :visibility, type: String, values: %w[public internal private],
desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at],
default: 'created_at', desc: 'Return projects ordered by field'
optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return projects sorted in ascending and descending order'
use :pagination use :pagination
end end
get ":id/projects" do get ":id/projects" do
group = find_group!(params[:id]) group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user) projects = GroupProjectsFinder.new(group).execute(current_user)
projects = filter_projects(projects)
present paginate(projects), with: Entities::Project, user: current_user present paginate(projects), with: Entities::Project, user: current_user
end end
......
...@@ -245,6 +245,17 @@ describe API::Groups, api: true do ...@@ -245,6 +245,17 @@ describe API::Groups, api: true do
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
end end
it 'filters the groups projects' do
public_projet = create(:project, :public, path: 'test1', group: group1)
get api("/groups/#{group1.id}/projects", user1), visibility: 'public'
expect(response).to have_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(public_projet.name)
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)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
......
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