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 @@ ...@@ -13,6 +13,7 @@
# non_public: boolean # non_public: boolean
# starred: boolean # starred: boolean
# sort: string # sort: string
# skip_sorting: boolean
# visibility_level: int # visibility_level: int
# tag: string[] - deprecated, use 'topic' instead # tag: string[] - deprecated, use 'topic' instead
# topic: string[] # topic: string[]
...@@ -55,7 +56,9 @@ class ProjectsFinder < UnionFinder ...@@ -55,7 +56,9 @@ class ProjectsFinder < UnionFinder
collection = Project.wrap_with_cte(collection) if use_cte collection = Project.wrap_with_cte(collection) if use_cte
collection = filter_projects(collection) 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]) collection.sorted_by_similarity_desc(params[:search])
else else
sort(collection) sort(collection)
......
...@@ -46,14 +46,15 @@ module EE ...@@ -46,14 +46,15 @@ module EE
def finder_params_for_removed def finder_params_for_removed
finder_params = { aimed_for_deletion: true } finder_params = { aimed_for_deletion: true }
finder_params[:skip_sorting] = true
unless current_user.can_admin_all_resources? unless current_user.can_admin_all_resources?
# only list projects with at least owner access if the user is not an admin # only list projects with at least owner access if the user is not an admin
finder_params[:min_access_level] = ::Gitlab::Access::OWNER finder_params[:min_access_level] = ::Gitlab::Access::OWNER
if ::Gitlab::CurrentSettings.should_check_namespace_plan? if ::Gitlab::CurrentSettings.should_check_namespace_plan?
# only list projects that belongs to a group with premium or above plan # only list projects that have delayed deletion feature available
finder_params[:plans_or_public] = (::Plan::PAID_HOSTED_PLANS - [::Plan::BRONZE]) finder_params[:feature_available] = :adjourned_deletion_for_projects_and_groups
end end
end end
......
...@@ -17,7 +17,7 @@ module EE ...@@ -17,7 +17,7 @@ module EE
def filter_projects(collection) def filter_projects(collection)
collection = super(collection) collection = super(collection)
collection = by_plans(collection) collection = by_plans(collection)
collection = by_plans_or_public(collection) collection = by_feature_available(collection)
by_aimed_for_deletion(collection) by_aimed_for_deletion(collection)
end end
...@@ -29,9 +29,9 @@ module EE ...@@ -29,9 +29,9 @@ module EE
end end
end end
def by_plans_or_public(collection) def by_feature_available(collection)
if names = params[:plans_or_public].presence if feature = params[:feature_available].presence
collection.with_paid_features(names) collection.with_feature(feature)
else else
collection collection
end end
......
...@@ -11,6 +11,7 @@ module EE ...@@ -11,6 +11,7 @@ module EE
extend ::Gitlab::Cache::RequestCache extend ::Gitlab::Cache::RequestCache
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
include ::Admin::RepoSizeLimitHelper include ::Admin::RepoSizeLimitHelper
include FromUnion
GIT_LFS_DOWNLOAD_OPERATION = 'download' GIT_LFS_DOWNLOAD_OPERATION = 'download'
PUBLIC_COST_FACTOR_RELEASE_DAY = Date.new(2021, 7, 17).freeze PUBLIC_COST_FACTOR_RELEASE_DAY = Date.new(2021, 7, 17).freeze
...@@ -134,13 +135,10 @@ module EE ...@@ -134,13 +135,10 @@ module EE
scope :verification_failed_repos, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_repos) } 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 :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 :for_plan_name, -> (name) { joins(namespace: { gitlab_subscription: :hosted_plan }).where(plans: { name: name }) }
scope :left_joins_namespace_for_plan_name, -> (name) do scope :with_feature, -> (name) do
left_joins(namespace: { gitlab_subscription: :hosted_plan }) projects_with_feature_available_in_plan = ::Project.for_group(::Group.with_feature_available_in_plan(name))
.where(plans: { name: name }) public_projects_in_public_groups = ::Project.public_only.for_group(::Group.public_only)
end from_union([projects_with_feature_available_in_plan, public_projects_in_public_groups])
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 end
scope :requiring_code_owner_approval, scope :requiring_code_owner_approval,
-> { joins(:protected_branches).where(protected_branches: { code_owner_approval_required: true }) } -> { 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