Commit 6d87541f authored by huzaifaiftikhar1's avatar huzaifaiftikhar1

Update the query to fetch projects pending deletion for non-admins

update scopes to use union with feature_available instead of plans and
skip sort for "pending_deletion" projects tab.
parent a0f6b738
......@@ -13,6 +13,7 @@
# non_public: boolean
# starred: boolean
# sort: string
# skip_sorting: boolean
# visibility_level: int
# tag: string[] - deprecated, use 'topic' instead
# topic: string[]
......@@ -55,7 +56,9 @@ class ProjectsFinder < UnionFinder
collection = Project.wrap_with_cte(collection) if use_cte
collection = filter_projects(collection)
if params[:sort] == 'similarity' && params[:search]
if params[:skip_sorting]
collection
elsif params[:sort] == 'similarity' && params[:search]
collection.sorted_by_similarity_desc(params[:search])
else
sort(collection)
......
......@@ -46,14 +46,15 @@ module EE
def finder_params_for_removed
finder_params = { aimed_for_deletion: true }
finder_params[:skip_sorting] = true
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
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])
# only list projects that have delayed deletion feature available
finder_params[:feature_available] = :adjourned_deletion_for_projects_and_groups
end
end
......
......@@ -17,7 +17,7 @@ module EE
def filter_projects(collection)
collection = super(collection)
collection = by_plans(collection)
collection = by_plans_or_public(collection)
collection = by_feature_available(collection)
by_aimed_for_deletion(collection)
end
......@@ -29,9 +29,9 @@ module EE
end
end
def by_plans_or_public(collection)
if names = params[:plans_or_public].presence
collection.with_paid_features(names)
def by_feature_available(collection)
if feature = params[:feature_available].presence
collection.with_feature(feature)
else
collection
end
......
......@@ -11,6 +11,7 @@ module EE
extend ::Gitlab::Cache::RequestCache
include ::Gitlab::Utils::StrongMemoize
include ::Admin::RepoSizeLimitHelper
include FromUnion
GIT_LFS_DOWNLOAD_OPERATION = 'download'
PUBLIC_COST_FACTOR_RELEASE_DAY = Date.new(2021, 7, 17).freeze
......@@ -134,13 +135,10 @@ 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)))
scope :with_feature, -> (name) do
projects_with_feature_available_in_plan = ::Project.for_group(::Group.with_feature_available_in_plan(name))
public_projects_in_public_groups = ::Project.public_only.for_group(::Group.public_only)
from_union([projects_with_feature_available_in_plan, public_projects_in_public_groups])
end
scope :requiring_code_owner_approval,
-> { joins(:protected_branches).where(protected_branches: { code_owner_approval_required: true }) }
......
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