Commit c06b854a authored by Allison Browne's avatar Allison Browne Committed by Gabriel Mazetto

Hide pending_delete projects from project index

Add tests to project finder and used the without_deleted
param on the project index page
parent a0efb830
......@@ -63,10 +63,11 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
def load_projects(finder_params)
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute
@total_starred_projects_count = ProjectsFinder.new(params: { starred: 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, without_deleted: true }, current_user: current_user).execute
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
......@@ -89,7 +90,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
def load_events
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
@events = EventCollection
......
......@@ -24,6 +24,7 @@
# last_activity_after: datetime
# last_activity_before: datetime
# repository_storage: string
# without_deleted: boolean
#
class ProjectsFinder < UnionFinder
include CustomAttributesFilter
......
---
title: Hide projects that are pending delete from the project index
merge_request: 40035
author:
type: changed
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Dashboard::ProjectsController do
RSpec.describe Dashboard::ProjectsController, :aggregate_failures do
include ExternalAuthorizationServiceHelpers
let_it_be(:user) { create(:user) }
......@@ -15,6 +15,7 @@ RSpec.describe Dashboard::ProjectsController do
context 'user logged in' do
let_it_be(:project) { create(:project) }
let_it_be(:project2) { create(:project) }
let(:projects) { [project, project2] }
before_all do
project.add_developer(user)
......@@ -41,7 +42,7 @@ RSpec.describe Dashboard::ProjectsController do
get :index
expect(assigns(:projects)).to eq([project, project2])
expect(assigns(:projects)).to eq(projects)
end
context 'project sorting' do
......@@ -66,6 +67,20 @@ RSpec.describe Dashboard::ProjectsController do
it_behaves_like 'search and sort parameters', sort
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
......@@ -153,7 +168,7 @@ RSpec.describe Dashboard::ProjectsController do
project.add_developer(user)
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
expect(assigns(:events)).to include(design_event, wiki_page_event, issue_event)
......@@ -165,6 +180,21 @@ RSpec.describe Dashboard::ProjectsController do
"closed issue #{issue.to_reference}"
)
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
......
......@@ -234,10 +234,40 @@ RSpec.describe ProjectsFinder, :do_not_mock_admin_mode do
end
describe 'filter by without_deleted' do
let(:params) { { without_deleted: true } }
let!(:pending_delete_project) { create(:project, :public, pending_delete: true) }
let_it_be(: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
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