mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
fixes broken users search method for smart annotation [fixes SCI-1192]
This commit is contained in:
parent
2932052628
commit
9ee971c24b
2 changed files with 25 additions and 34 deletions
|
@ -3,27 +3,10 @@ class AtWhoController < ApplicationController
|
||||||
before_action :check_users_permissions
|
before_action :check_users_permissions
|
||||||
|
|
||||||
def users
|
def users
|
||||||
# Search users
|
|
||||||
res = @team
|
|
||||||
.search_users(@query)
|
|
||||||
.select(:id, :full_name, :email)
|
|
||||||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
||||||
.as_json
|
|
||||||
|
|
||||||
# Add avatars, Base62, convert to JSON
|
|
||||||
res.each do |user_obj|
|
|
||||||
user_obj['full_name'] =
|
|
||||||
user_obj['full_name']
|
|
||||||
.truncate(Constants::NAME_TRUNCATION_LENGTH_DROPDOWN)
|
|
||||||
id = user_obj['id']
|
|
||||||
user_obj['id'] = id.base62_encode
|
|
||||||
user_obj['img_url'] = avatar_path(id, :icon_small)
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: {
|
||||||
users: res,
|
users: generate_users_data,
|
||||||
status: :ok
|
status: :ok
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -105,4 +88,24 @@ class AtWhoController < ApplicationController
|
||||||
def check_users_permissions
|
def check_users_permissions
|
||||||
render_403 unless can_view_team_users(@team)
|
render_403 unless can_view_team_users(@team)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_users_data
|
||||||
|
# Search users
|
||||||
|
res = @team.search_users(@query)
|
||||||
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||||
|
.pluck(:id, :full_name, :email)
|
||||||
|
|
||||||
|
# Add avatars, Base62, convert to JSON
|
||||||
|
data = []
|
||||||
|
res.each do |obj|
|
||||||
|
tmp = {}
|
||||||
|
tmp['id'] = obj[0].base62_encode
|
||||||
|
tmp['full_name'] = obj[1]
|
||||||
|
.truncate(Constants::NAME_TRUNCATION_LENGTH_DROPDOWN)
|
||||||
|
tmp['email'] = obj[2]
|
||||||
|
tmp['img_url'] = avatar_path(obj[0], :icon_small)
|
||||||
|
data << tmp
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,22 +52,10 @@ class Team < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_users(
|
def search_users(query = nil)
|
||||||
query = nil,
|
a_query = "%#{query}%"
|
||||||
attributes = [:full_name, :email]
|
users.where.not(confirmed_at: nil)
|
||||||
)
|
.where('full_name LIKE ? OR email LIKE ?', a_query, a_query)
|
||||||
if query
|
|
||||||
a_query = query
|
|
||||||
.strip
|
|
||||||
.gsub('_', '\\_')
|
|
||||||
.gsub('%', '\\%')
|
|
||||||
else
|
|
||||||
a_query = query
|
|
||||||
end
|
|
||||||
|
|
||||||
users
|
|
||||||
.where.not(confirmed_at: nil)
|
|
||||||
.where_attributes_like(attributes, a_query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Imports samples into db
|
# Imports samples into db
|
||||||
|
|
Loading…
Reference in a new issue