Commit a0f6b738 authored by huzaifaiftikhar1's avatar huzaifaiftikhar1

Create scopes to be used for "Pending deletion" projects tab

List projects projects belonging to groups on a plan greater
than equal to premium or public projects in the pending deletion tab.
parent 4dbcba60
......@@ -50,8 +50,11 @@ module EE
unless current_user.can_admin_all_resources?
# only list projects with at least owner access if the user is not an admin
finder_params[:min_access_level] = ::Gitlab::Access::OWNER
# only list projects that belongs to a group with premium or above plan
finder_params[:plans] = (::Plan::PAID_HOSTED_PLANS - [::Plan::BRONZE])
if ::Gitlab::CurrentSettings.should_check_namespace_plan?
# only list projects that belongs to a group with premium or above plan
finder_params[:plans_or_public] = (::Plan::PAID_HOSTED_PLANS - [::Plan::BRONZE])
end
end
finder_params
......
......@@ -17,6 +17,7 @@ module EE
def filter_projects(collection)
collection = super(collection)
collection = by_plans(collection)
collection = by_plans_or_public(collection)
by_aimed_for_deletion(collection)
end
......@@ -28,6 +29,14 @@ module EE
end
end
def by_plans_or_public(collection)
if names = params[:plans_or_public].presence
collection.with_paid_features(names)
else
collection
end
end
def by_aimed_for_deletion(items)
if ::Gitlab::Utils.to_boolean(params[:aimed_for_deletion])
items.aimed_for_deletion(Date.current)
......
......@@ -134,6 +134,14 @@ module EE
scope :verification_failed_repos, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_repos) }
scope :verification_failed_wikis, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_wikis) }
scope :for_plan_name, -> (name) { joins(namespace: { gitlab_subscription: :hosted_plan }).where(plans: { name: name }) }
scope :left_joins_namespace_for_plan_name, -> (name) do
left_joins(namespace: { gitlab_subscription: :hosted_plan })
.where(plans: { name: name })
end
scope :with_group_namespace_visibility_level, -> (level) { ::Namespace.where(type: 'Group', visibility_level: level) }
scope :with_paid_features, -> (plan_name) do
left_joins_namespace_for_plan_name(plan_name).or(search_by_visibility('public').and(with_group_namespace_visibility_level(20)))
end
scope :requiring_code_owner_approval,
-> { joins(:protected_branches).where(protected_branches: { code_owner_approval_required: true }) }
scope :github_imported, -> { where(import_type: 'github') }
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Dashboard::ProjectsController do
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
describe '#removed' do
......@@ -79,10 +81,23 @@ RSpec.describe Dashboard::ProjectsController do
expect(assigns(:projects).count).to eq(1)
end
it 'accounts total removable projects owned by the user on premium or above plan' do
subject
context 'for should_check_namespace_plan' do
where(:should_check_namespace_plan, :removed_projects_count) do
false | 3
true | 2
end
expect(assigns(:removed_projects_count).count).to eq(2)
with_them do
before do
stub_ee_application_setting(should_check_namespace_plan: should_check_namespace_plan)
end
it 'accounts total removable projects' do
subject
expect(assigns(:removed_projects_count).count).to eq(removed_projects_count)
end
end
end
end
end
......
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