add: organization users insist team nickname search
This commit is contained in:
parent
1dd3fbc69a
commit
5cb2e55f74
|
@ -5,7 +5,11 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
|||
def index
|
||||
@organization_users = @organization.organization_users.includes(:user)
|
||||
search = params[:search].to_s.downcase
|
||||
@organization_users = @organization_users.joins(:user).merge(User.like(search))
|
||||
user_condition_users = User.like(search).to_sql
|
||||
team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql
|
||||
users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users")
|
||||
|
||||
@organization_users = @organization_users.where(user_id: users).distinct
|
||||
|
||||
@organization_users = kaminari_paginate(@organization_users)
|
||||
end
|
||||
|
|
|
@ -29,6 +29,11 @@ class Team < ApplicationRecord
|
|||
has_many :team_units, dependent: :destroy
|
||||
has_many :team_users, dependent: :destroy
|
||||
|
||||
scope :like, lambda { |keywords|
|
||||
sql = "teams.nickname LIKE :search OR teams.name LIKE :search"
|
||||
where(sql, :search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||
}
|
||||
|
||||
validates :name, uniqueness: {scope: :organization_id}
|
||||
|
||||
enum authorize: {read: 1, write: 2, admin: 3, owner: 4}
|
||||
|
|
|
@ -3,5 +3,5 @@ json.user do
|
|||
json.partial! "organizations/user_detail", user: org_user.user
|
||||
end
|
||||
|
||||
json.team_names org_user.teams.pluck(:name)
|
||||
json.team_names org_user.teams.pluck(:nickname)
|
||||
json.created_at org_user.created_at.strftime("%Y-%m-%d")
|
||||
|
|
Loading…
Reference in New Issue