修改分类数量显示bug

This commit is contained in:
sylor_huang@126.com 2020-03-26 10:19:04 +08:00
parent 73ad4b8a96
commit b30510bf3d
4 changed files with 9 additions and 3 deletions

View File

@ -8,7 +8,7 @@ class ProjectCategoriesController < ApplicationController
if is_admin
projects = Project.all
elsif current_user&.logged?
projects = Project.joins(:members).where.not("projects.is_public = ? and (projects.user_id != ? or members.user_id != ?)", false, current_user.id,current_user.id ).distinct
projects = Project.list_user_projects(current_user.id)
else
projects = Project.visible
end

View File

@ -42,7 +42,8 @@ class ProjectsController < ApplicationController
if is_admin
projects = Project.all
elsif current_user&.logged?
projects = Project.joins(:members).where.not("projects.is_public = ? and (projects.user_id != ? or members.user_id != ?)", false, current_user.id,current_user.id ).distinct
projects = Project.list_user_projects(current_user.id)
else
projects = Project.visible
end

View File

@ -101,4 +101,9 @@ class Project < ApplicationRecord
str
end
def self.list_user_projects(user_id)
user_not_show = Project.joins(:members).where("projects.is_public = ? and (projects.user_id != ? or members.user_id != ?)", false, user_id,user_id).pluck(:id).uniq
Project.where.not(id: user_not_show)
end
end

View File

@ -13,7 +13,7 @@ class Projects::ListQuery < ApplicationQuery
if params[:is_admin]
projects = Project.all
elsif params[:user_id].to_i != 2
projects = Project.joins(:members).where.not("projects.is_public = ? and (projects.user_id != ? or members.user_id != ?)", false, params[:user_id].to_i,params[:user_id].to_i ).distinct
projects = Project.list_user_projects(params[:user_id])
else
projects = Project.visible
end