Commit d2cc536d authored by Robert Speicher's avatar Robert Speicher

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
parents fb81210b 8e52f56d
...@@ -49,6 +49,7 @@ class ProjectsFinder < UnionFinder ...@@ -49,6 +49,7 @@ class ProjectsFinder < UnionFinder
collection = by_search(collection) collection = by_search(collection)
collection = by_archived(collection) collection = by_archived(collection)
collection = by_custom_attributes(collection) collection = by_custom_attributes(collection)
collection = by_deleted_status(collection)
sort(collection) sort(collection)
end end
...@@ -131,6 +132,10 @@ class ProjectsFinder < UnionFinder ...@@ -131,6 +132,10 @@ class ProjectsFinder < UnionFinder
params[:search].present? ? items.search(params[:search]) : items params[:search].present? ? items.search(params[:search]) : items
end end
def by_deleted_status(items)
params[:without_deleted].present? ? items.without_deleted : items
end
def sort(items) def sort(items)
params[:sort].present? ? items.sort_by_attribute(params[:sort]) : items.order_id_desc params[:sort].present? ? items.sort_by_attribute(params[:sort]) : items.order_id_desc
end end
......
---
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 ...@@ -103,10 +103,12 @@ module API
end end
def find_project(id) def find_project(id)
projects = Project.without_deleted
if id.is_a?(Integer) || id =~ /^\d+$/ if id.is_a?(Integer) || id =~ /^\d+$/
Project.find_by(id: id) projects.find_by(id: id)
elsif id.include?("/") elsif id.include?("/")
Project.find_by_full_path(id) projects.find_by_full_path(id)
end end
end end
...@@ -386,7 +388,7 @@ module API ...@@ -386,7 +388,7 @@ module API
end end
def project_finder_params def project_finder_params
finder_params = {} finder_params = { without_deleted: true }
finder_params[:owned] = true if params[:owned].present? finder_params[:owned] = true if params[:owned].present?
finder_params[:non_public] = true if params[:membership].present? finder_params[:non_public] = true if params[:membership].present?
finder_params[:starred] = true if params[:starred].present? finder_params[:starred] = true if params[:starred].present?
......
...@@ -174,6 +174,13 @@ describe ProjectsFinder do ...@@ -174,6 +174,13 @@ describe ProjectsFinder do
end end
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 describe 'sorting' do
let(:params) { { sort: 'name_asc' } } let(:params) { { sort: 'name_asc' } }
......
...@@ -148,6 +148,16 @@ describe API::Projects do ...@@ -148,6 +148,16 @@ describe API::Projects do
expect(json_response.first.keys).to include('open_issues_count') expect(json_response.first.keys).to include('open_issues_count')
end 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 it 'does not include open_issues_count if issues are disabled' do
project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED) project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
...@@ -1012,6 +1022,15 @@ describe API::Projects do ...@@ -1012,6 +1022,15 @@ describe API::Projects do
expect(json_response).not_to include("import_error") expect(json_response).not_to include("import_error")
end 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 context 'links exposure' do
it 'exposes related resources full URIs' do it 'exposes related resources full URIs' do
get api("/projects/#{project.id}", user) get api("/projects/#{project.id}", user)
......
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