Merge branch 'develop' of http://git.trustie.net/jasder/forgeplus into develop

This commit is contained in:
Jasder 2020-03-25 21:29:18 +08:00
commit b709949e79
3 changed files with 29 additions and 4 deletions

View File

@ -4,8 +4,16 @@ class ProjectCategoriesController < ApplicationController
end
def group_list
is_admin = current_user && current_user&.admin?
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
else
projects = Project.visible
end
@category_group_list =
Project.visible.joins(:project_category).group(:project_category_id)
projects.joins(:project_category).group(:project_category_id)
.select("project_category_id, count(*) AS projects_count, project_categories.name")
end
end

View File

@ -6,7 +6,9 @@ class ProjectsController < ApplicationController
before_action :authorizate_user_can_edit_project!, only: %i[update]
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
@projects = paginate(scope)
end
@ -36,7 +38,15 @@ class ProjectsController < ApplicationController
end
def group_type_list
@project_group_list = Project.visible.group(:project_type).select('project_type, count(project_type) AS projects_count').having("count(project_type) > ?", 0)
is_admin = current_user && current_user&.admin?
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
else
projects = Project.visible
end
@project_group_list = projects.group(:project_type).select('project_type, count(project_type) AS projects_count').having("count(project_type) > ?", 0)
end
def update

View File

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