Commit afbb93f7 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '32301-filter-archive-project-on-param-present' into 'master'

Filter archived project in API only if param present

Closes #32301

See merge request !12245
parents 2b2c973f eda30f31
---
title: Filter archived project in API v3 only if param present
merge_request: 12245
author: Ivan Chernov
...@@ -38,7 +38,10 @@ module API ...@@ -38,7 +38,10 @@ module API
projects = projects.where(visibility_level: Gitlab::VisibilityLevel.level_value(params[:visibility])) projects = projects.where(visibility_level: Gitlab::VisibilityLevel.level_value(params[:visibility]))
end end
projects = projects.where(archived: params[:archived]) unless params[:archived].nil?
projects = projects.where(archived: to_boolean(params[:archived]))
end
projects.reorder(params[:order_by] => params[:sort]) projects.reorder(params[:order_by] => params[:sort])
end end
end end
......
...@@ -69,7 +69,7 @@ module API ...@@ -69,7 +69,7 @@ module API
end end
params :filter_params do params :filter_params do
optional :archived, type: Boolean, default: false, desc: 'Limit by archived status' optional :archived, type: Boolean, default: nil, desc: 'Limit by archived status'
optional :visibility, type: String, values: %w[public internal private], optional :visibility, type: String, values: %w[public internal private],
desc: 'Limit by visibility' desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
......
...@@ -124,6 +124,36 @@ describe API::V3::Projects do ...@@ -124,6 +124,36 @@ describe API::V3::Projects do
end end
end end
context 'and using archived' do
let!(:archived_project) { create(:empty_project, creator_id: user.id, namespace: user.namespace, archived: true) }
it 'returns archived project' do
get v3_api('/projects?archived=true', user)
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['id']).to eq(archived_project.id)
end
it 'returns non-archived project' do
get v3_api('/projects?archived=false', user)
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['id']).to eq(project.id)
end
it 'returns all project' do
get v3_api('/projects', user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(2)
end
end
context 'and using sorting' do context 'and using sorting' do
before do before do
project2 project2
......
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