From f7b7122d607db4056290e04578614d5c390a0f8b Mon Sep 17 00:00:00 2001 From: "vilet.yy" Date: Sun, 21 Feb 2021 15:20:04 +0800 Subject: [PATCH] [FIX]join projects add org projects and update project private bug --- app/controllers/projects_controller.rb | 2 +- app/queries/projects/list_my_query.rb | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2939e7fb8..c8f3027de 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -76,7 +76,7 @@ class ProjectsController < ApplicationController default_branch: params[:default_branch] } if [true, false].include? private - new_project_params = project_params.merge(is_public: !private) + new_project_params = project_params.except(:private).merge(is_public: !private) Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) @project.repository.update_column(:hidden, private) end diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index ba521e906..8ad0d0b0a 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -17,15 +17,12 @@ class Projects::ListMyQuery < ApplicationQuery projects = Project.visible end - if params[:is_public].present? - projects = projects.is_private.members_projects(user.id) if params[:is_public].to_s == "private" - projects = projects.visible.members_projects(user.id) if params[:is_public].to_s == "public" - end - if params[:category].blank? projects = projects.members_projects(user.id) elsif params[:category].to_s == "join" - projects = projects.where.not(user_id: user.id).members_projects(user.id) + normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql + org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql + projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct elsif params[:category].to_s == "manage" projects = projects.where(user_id: user.id) elsif params[:category].to_s == "watched" #我关注的 @@ -39,6 +36,11 @@ class Projects::ListMyQuery < ApplicationQuery # projects = projects.is_private.joins(:members).where(members: { user_id: user.id }) end + if params[:is_public].present? + projects = projects.is_private if params[:is_public].to_s == "private" + projects = projects.visible if params[:is_public].to_s == "public" + end + if params[:project_type].to_s === "common" projects = projects.common elsif params[:project_type].to_s === "mirror"