From 4bc945028b1730cadba62e4183c930002ba87630 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 3 Feb 2023 15:50:33 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=B1=E8=B4=A5=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index ec1dcda3c..e1c03a75c 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -11,7 +11,7 @@ class Projects::ListQuery < ApplicationQuery end def call - collection = Project.all + collection = main_collection collection = filter_projects(collection) sort = params[:sort_by] || "updated_on" @@ -26,15 +26,24 @@ class Projects::ListQuery < ApplicationQuery def filter_projects(collection) collection = by_pinned(collection) - collection = by_search(collection) + collection = by_search(collection) if params[:search].present? collection = by_project_type(collection) collection = by_project_category(collection) collection = by_project_language(collection) collection end + def main_collection + collection = Project.visible + # 增加私有组织中项目过滤 + collection = collection.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id") + .where("organization_extensions.visibility is null or organization_extensions.visibility in (0,1)") + .where("projects.user_id > 0") + collection + end + def by_search(items) - items.visible.by_name_or_identifier(params[:search]) + items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) end def by_project_type(items) @@ -67,5 +76,14 @@ class Projects::ListQuery < ApplicationQuery relations end end - + + def by_recommend(items) + params[:recommend].to_s == "true" ? items.where(recommend: true) : items + end + + def exclude_fork(items) + return items if params[:exclude_forked].blank? + params[:exclude_forked].to_s == "true" ? items.where("forked_from_project_id is null") : items.where("forked_from_project_id is not null") + end + end