Merge branch '50678-ignores-project-pending-delete' into 'master'
Resolve "500 Internal Server Error: Deleting branch of deleted project" Closes #50678 See merge request gitlab-org/gitlab-ce!21542
This commit is contained in:
commit
d2cc536d6a
|
@ -49,6 +49,7 @@ class ProjectsFinder < UnionFinder
|
|||
collection = by_search(collection)
|
||||
collection = by_archived(collection)
|
||||
collection = by_custom_attributes(collection)
|
||||
collection = by_deleted_status(collection)
|
||||
|
||||
sort(collection)
|
||||
end
|
||||
|
@ -131,6 +132,10 @@ class ProjectsFinder < UnionFinder
|
|||
params[:search].present? ? items.search(params[:search]) : items
|
||||
end
|
||||
|
||||
def by_deleted_status(items)
|
||||
params[:without_deleted].present? ? items.without_deleted : items
|
||||
end
|
||||
|
||||
def sort(items)
|
||||
params[:sort].present? ? items.sort_by_attribute(params[:sort]) : items.order_id_desc
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Excludes project marked from deletion to projects API
|
||||
merge_request: 21542
|
||||
author: Jacopo Beschi @jacopo-beschi
|
||||
type: changed
|
|
@ -103,10 +103,12 @@ module API
|
|||
end
|
||||
|
||||
def find_project(id)
|
||||
projects = Project.without_deleted
|
||||
|
||||
if id.is_a?(Integer) || id =~ /^\d+$/
|
||||
Project.find_by(id: id)
|
||||
projects.find_by(id: id)
|
||||
elsif id.include?("/")
|
||||
Project.find_by_full_path(id)
|
||||
projects.find_by_full_path(id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -386,7 +388,7 @@ module API
|
|||
end
|
||||
|
||||
def project_finder_params
|
||||
finder_params = {}
|
||||
finder_params = { without_deleted: true }
|
||||
finder_params[:owned] = true if params[:owned].present?
|
||||
finder_params[:non_public] = true if params[:membership].present?
|
||||
finder_params[:starred] = true if params[:starred].present?
|
||||
|
|
|
@ -174,6 +174,13 @@ describe ProjectsFinder do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'filter by without_deleted' do
|
||||
let(:params) { { without_deleted: true } }
|
||||
let!(:pending_delete_project) { create(:project, :public, pending_delete: true) }
|
||||
|
||||
it { is_expected.to match_array([public_project, internal_project]) }
|
||||
end
|
||||
|
||||
describe 'sorting' do
|
||||
let(:params) { { sort: 'name_asc' } }
|
||||
|
||||
|
|
|
@ -148,6 +148,16 @@ describe API::Projects do
|
|||
expect(json_response.first.keys).to include('open_issues_count')
|
||||
end
|
||||
|
||||
it 'does not include projects marked for deletion' do
|
||||
project.update(pending_delete: true)
|
||||
|
||||
get api('/projects', user)
|
||||
|
||||
expect(response).to have_gitlab_http_status(200)
|
||||
expect(json_response).to be_an Array
|
||||
expect(json_response.map { |p| p['id'] }).not_to include(project.id)
|
||||
end
|
||||
|
||||
it 'does not include open_issues_count if issues are disabled' do
|
||||
project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
|
||||
|
||||
|
@ -1012,6 +1022,15 @@ describe API::Projects do
|
|||
expect(json_response).not_to include("import_error")
|
||||
end
|
||||
|
||||
it 'returns 404 when project is marked for deletion' do
|
||||
project.update(pending_delete: true)
|
||||
|
||||
get api("/projects/#{project.id}", user)
|
||||
|
||||
expect(response).to have_gitlab_http_status(404)
|
||||
expect(json_response['message']).to eq('404 Project Not Found')
|
||||
end
|
||||
|
||||
context 'links exposure' do
|
||||
it 'exposes related resources full URIs' do
|
||||
get api("/projects/#{project.id}", user)
|
||||
|
|
Loading…
Reference in New Issue