Commit ce00e36f authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'ab-hide-pending-delete-projects-from-project-index' into 'master'

Hide projects pending_delete from the project index

See merge request gitlab-org/gitlab!40035
parents 16d095e2 c06b854a
...@@ -63,10 +63,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -63,10 +63,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end end
def load_projects(finder_params) def load_projects(finder_params)
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute @total_user_projects_count = ProjectsFinder.new(params: { non_public: true, without_deleted: true }, current_user: current_user).execute
@total_starred_projects_count = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute @total_starred_projects_count = ProjectsFinder.new(params: { starred: true, without_deleted: true }, current_user: current_user).execute
finder_params[:use_cte] = true if use_cte_for_finder? finder_params[:use_cte] = true if use_cte_for_finder?
finder_params[:without_deleted] = true
projects = ProjectsFinder.new(params: finder_params, current_user: current_user).execute projects = ProjectsFinder.new(params: finder_params, current_user: current_user).execute
...@@ -89,7 +90,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -89,7 +90,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
def load_events def load_events
projects = ProjectsFinder projects = ProjectsFinder
.new(params: params.merge(non_public: true), current_user: current_user) .new(params: params.merge(non_public: true, without_deleted: true), current_user: current_user)
.execute .execute
@events = EventCollection @events = EventCollection
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# last_activity_after: datetime # last_activity_after: datetime
# last_activity_before: datetime # last_activity_before: datetime
# repository_storage: string # repository_storage: string
# without_deleted: boolean
# #
class ProjectsFinder < UnionFinder class ProjectsFinder < UnionFinder
include CustomAttributesFilter include CustomAttributesFilter
......
---
title: Hide projects that are pending delete from the project index
merge_request: 40035
author:
type: changed
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Dashboard::ProjectsController do RSpec.describe Dashboard::ProjectsController, :aggregate_failures do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
...@@ -15,6 +15,7 @@ RSpec.describe Dashboard::ProjectsController do ...@@ -15,6 +15,7 @@ RSpec.describe Dashboard::ProjectsController do
context 'user logged in' do context 'user logged in' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:project2) { create(:project) } let_it_be(:project2) { create(:project) }
let(:projects) { [project, project2] }
before_all do before_all do
project.add_developer(user) project.add_developer(user)
...@@ -41,7 +42,7 @@ RSpec.describe Dashboard::ProjectsController do ...@@ -41,7 +42,7 @@ RSpec.describe Dashboard::ProjectsController do
get :index get :index
expect(assigns(:projects)).to eq([project, project2]) expect(assigns(:projects)).to eq(projects)
end end
context 'project sorting' do context 'project sorting' do
...@@ -66,6 +67,20 @@ RSpec.describe Dashboard::ProjectsController do ...@@ -66,6 +67,20 @@ RSpec.describe Dashboard::ProjectsController do
it_behaves_like 'search and sort parameters', sort it_behaves_like 'search and sort parameters', sort
end end
end end
context 'with deleted project' do
let!(:pending_delete_project) do
project.tap { |p| p.update!(pending_delete: true) }
end
it 'does not display deleted project' do
get :index
projects_result = assigns(:projects)
expect(projects_result).not_to include(pending_delete_project)
expect(projects_result).to include(project2)
end
end
end end
end end
...@@ -153,7 +168,7 @@ RSpec.describe Dashboard::ProjectsController do ...@@ -153,7 +168,7 @@ RSpec.describe Dashboard::ProjectsController do
project.add_developer(user) project.add_developer(user)
end end
it 'renders all kinds of event without error', :aggregate_failures do it 'renders all kinds of event without error' do
get :index, format: :atom get :index, format: :atom
expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event) expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event)
...@@ -165,6 +180,21 @@ RSpec.describe Dashboard::ProjectsController do ...@@ -165,6 +180,21 @@ RSpec.describe Dashboard::ProjectsController do
"closed issue #{issue.to_reference}" "closed issue #{issue.to_reference}"
) )
end end
context 'with deleted project' do
let(:pending_deleted_project) { projects.last.tap { |p| p.update!(pending_delete: true) } }
before do
pending_deleted_project.add_developer(user)
end
it 'does not display deleted project' do
get :index, format: :atom
expect(response.body).not_to include(pending_deleted_project.full_name)
expect(response.body).to include(project.full_name)
end
end
end end
end end
end end
......
...@@ -234,10 +234,40 @@ RSpec.describe ProjectsFinder, :do_not_mock_admin_mode do ...@@ -234,10 +234,40 @@ RSpec.describe ProjectsFinder, :do_not_mock_admin_mode do
end end
describe 'filter by without_deleted' do describe 'filter by without_deleted' do
let(:params) { { without_deleted: true } } let_it_be(:pending_delete_project) { create(:project, :public, pending_delete: true) }
let!(:pending_delete_project) { create(:project, :public, pending_delete: true) }
it { is_expected.to match_array([public_project, internal_project]) } let(:params) { { without_deleted: without_deleted } }
shared_examples 'returns all projects' do
it { expect(subject).to include(public_project, internal_project, pending_delete_project) }
end
context 'when without_deleted is true' do
let(:without_deleted) { true }
it 'returns projects that are not pending_delete' do
expect(subject).not_to include(pending_delete_project)
expect(subject).to include(public_project, internal_project)
end
end
context 'when without_deleted is false' do
let(:without_deleted) { false }
it_behaves_like 'returns all projects'
end
context 'when without_deleted is nil' do
let(:without_deleted) { nil }
it_behaves_like 'returns all projects'
end
context 'when without_deleted is not present' do
let(:params) { {} }
it_behaves_like 'returns all projects'
end
end end
describe 'filter by last_activity_after' do describe 'filter by last_activity_after' do
......
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