BigW Consortium Gitlab

Commit eda30f31 by vanadium23

Filter archived project in API v3 only if param present

parent 043f8c26
---
title: Filter archived project in API v3 only if param present
merge_request: 12245
author: Ivan Chernov
......@@ -38,7 +38,10 @@ module API
projects = projects.where(visibility_level: Gitlab::VisibilityLevel.level_value(params[:visibility]))
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])
end
end
......
......@@ -69,7 +69,7 @@ module API
end
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],
desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
......
......@@ -124,6 +124,36 @@ describe API::V3::Projects do
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
before do
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