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
This commit is contained in:
commit
7e9a8bb760
2 changed files with 21 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
module API
|
||||
class Groups < Grape::API
|
||||
include PaginationParams
|
||||
|
||||
|
||||
before { authenticate! }
|
||||
|
||||
helpers do
|
||||
|
@ -117,11 +117,20 @@ module API
|
|||
success Entities::Project
|
||||
end
|
||||
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
|
||||
end
|
||||
get ":id/projects" do
|
||||
group = find_group!(params[:id])
|
||||
projects = GroupProjectsFinder.new(group).execute(current_user)
|
||||
projects = filter_projects(projects)
|
||||
present paginate(projects), with: Entities::Project, user: current_user
|
||||
end
|
||||
|
||||
|
|
|
@ -245,6 +245,17 @@ describe API::Groups, api: true do
|
|||
expect(project_names).to match_array([project1.name, project3.name])
|
||||
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
|
||||
get api("/groups/1328/projects", user1)
|
||||
expect(response).to have_http_status(404)
|
||||
|
|
Loading…
Reference in a new issue