修改项目列表页的显示

This commit is contained in:
sylor_huang@126.com 2020-03-25 18:19:01 +08:00
parent 827ad2f6c5
commit 1cb781ed95
2 changed files with 11 additions and 2 deletions

View File

@ -6,7 +6,9 @@ class ProjectsController < ApplicationController
before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :authorizate_user_can_edit_project!, only: %i[update]
def index def index
scope = Projects::ListQuery.call(params) is_admin = current_user && current_user&.admin?
scope = Projects::ListQuery.call(params.merge(is_admin: is_admin))
@total_count = scope.size @total_count = scope.size
@projects = paginate(scope) @projects = paginate(scope)
end end

View File

@ -10,7 +10,14 @@ class Projects::ListQuery < ApplicationQuery
end end
def call def call
scope = Project.visible.like(params[:search]) 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 )
else
projects = Project.visible
end
scope = projects.like(params[:search])
.with_project_type(params[:project_type]) .with_project_type(params[:project_type])
.with_project_category(params[:category_id]) .with_project_category(params[:category_id])
.with_project_language(params[:language_id]) .with_project_language(params[:language_id])