diff --git a/app/controllers/project_categories_controller.rb b/app/controllers/project_categories_controller.rb index bdcec088..8649db38 100644 --- a/app/controllers/project_categories_controller.rb +++ b/app/controllers/project_categories_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f53a8906..abb97109 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index c600f864..f3bf6181 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index b5facb3a..8bbbc5d9 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -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