From d993df7df4de5472827eb57599bd91011b6cc6c5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:07:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8=E6=83=85=E5=AD=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/owner.rb | 2 ++ app/models/user.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/owner.rb b/app/models/owner.rb index 2763dc80f..d348970f0 100644 --- a/app/models/owner.rb +++ b/app/models/owner.rb @@ -69,6 +69,8 @@ class Owner < ApplicationRecord has_many :applied_transfer_projects, dependent: :destroy scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search " where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } diff --git a/app/models/user.rb b/app/models/user.rb index 193e6c68f..5e21212ab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -185,6 +185,8 @@ class User < Owner # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search" where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } From 6f7b40ec244b436952deea79cd2b7341f5b79d9f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:22:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=A1=B9=E7=9B=AE=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8?= =?UTF-8?q?=E6=83=85=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 9 ++++++--- app/models/project.rb | 2 ++ app/queries/projects/list_my_query.rb | 6 ++++-- app/queries/projects/list_query.rb | 4 +++- app/services/api/v1/users/projects/list_service.rb | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index b36a76125..ab5c9ef5d 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -8,14 +8,17 @@ class Organizations::ProjectsController < Organizations::BaseController .joins(team_projects: {team: :team_users}) .where(team_users: {user_id: current_user.id}).to_sql @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") - - @projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present? + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) end def search tip_exception("请输入搜索关键词") if params[:search].nil? + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') public_projects_sql = @organization.projects.where(is_public: true).to_sql private_projects_sql = @organization.projects .where(is_public: false) @@ -23,7 +26,7 @@ class Organizations::ProjectsController < Organizations::BaseController .where(team_users: {user_id: current_user.id}).to_sql @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") - @projects = @projects.ransack(name_or_identifier_cont: params[:search]).result + @projects = @projects.ransack(name_or_identifier_cont: keywords).result @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") end diff --git a/app/models/project.rb b/app/models/project.rb index 68a8d071d..54d6ac520 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -240,6 +240,8 @@ class Project < ApplicationRecord end def self.search_project(search) + # 表情处理 + search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') ransack(name_or_identifier_cont: search) end # 创建者 diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 6c7f38d9c..bc0cda1a2 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -52,8 +52,10 @@ class Projects::ListMyQuery < ApplicationQuery elsif params[:project_type].to_s === "sync_mirror" projects = projects.sync_mirror end - - q = projects.ransack(name_or_identifier_cont: params[:search]) + + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + q = projects.ransack(name_or_identifier_cont: keywords) scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 6b0843540..2b048bd87 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -51,7 +51,9 @@ class Projects::ListQuery < ApplicationQuery # items = items.where(id: @ids).by_name_or_identifier(params[:search]) items = items.where(id: @ids) else - items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + items = items.by_name_or_identifier(keywords).or(main_collection.where(user_id: Owner.like(keywords).pluck(:id))) end items end diff --git a/app/services/api/v1/users/projects/list_service.rb b/app/services/api/v1/users/projects/list_service.rb index 8b3bffef0..47457c58c 100644 --- a/app/services/api/v1/users/projects/list_service.rb +++ b/app/services/api/v1/users/projects/list_service.rb @@ -73,8 +73,10 @@ class Api::V1::Users::Projects::ListService < ApplicationService end - projects = projects.with_project_type(project_type) + projects = projects.with_project_type(project_type) + # 表情处理 + search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') q = projects.ransack(name_or_identifier_cont: search) scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)