diff options
-rw-r--r-- | app/finders/projects_finder.rb | 5 | ||||
-rw-r--r-- | changelogs/unreleased/50678-ignores-project-pending-delete.yml | 5 | ||||
-rw-r--r-- | lib/api/helpers.rb | 8 | ||||
-rw-r--r-- | spec/finders/projects_finder_spec.rb | 7 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 19 |
5 files changed, 41 insertions, 3 deletions
diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index cac6643eff3..0398ccce93b 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -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 diff --git a/changelogs/unreleased/50678-ignores-project-pending-delete.yml b/changelogs/unreleased/50678-ignores-project-pending-delete.yml new file mode 100644 index 00000000000..e4594abba99 --- /dev/null +++ b/changelogs/unreleased/50678-ignores-project-pending-delete.yml @@ -0,0 +1,5 @@ +--- +title: Excludes project marked from deletion to projects API +merge_request: 21542 +author: Jacopo Beschi @jacopo-beschi +type: changed diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 5505d7a7b08..c7ecddeccf0 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -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? diff --git a/spec/finders/projects_finder_spec.rb b/spec/finders/projects_finder_spec.rb index 7931ad9b9f0..590e838f13e 100644 --- a/spec/finders/projects_finder_spec.rb +++ b/spec/finders/projects_finder_spec.rb @@ -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' } } diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 65cd423f0bb..c8e98e6024c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -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) |