Browse Source

修改分类数量显示bug

tags/v1
sylor_huang@126.com 6 years ago
parent
commit
b30510bf3d
4 changed files with 9 additions and 3 deletions
  1. +1
    -1
      app/controllers/project_categories_controller.rb
  2. +2
    -1
      app/controllers/projects_controller.rb
  3. +5
    -0
      app/models/project.rb
  4. +1
    -1
      app/queries/projects/list_query.rb

+ 1
- 1
app/controllers/project_categories_controller.rb 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


+ 2
- 1
app/controllers/projects_controller.rb 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


+ 5
- 0
app/models/project.rb 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

+ 1
- 1
app/queries/projects/list_query.rb 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


Loading…
Cancel
Save