diff options
author | Yar <mrrezaque@gmail.com> | 2016-10-25 20:14:58 +0300 |
---|---|---|
committer | Yar <YarTheGreat@gmail.com> | 2016-11-01 17:58:03 +0300 |
commit | f8530580100f56fe3bef5f3a73d3e543b038f98f (patch) | |
tree | 63b63eb3fc037cd92a6c04fa0aa328066da305e7 /app | |
parent | 6893bccd06320c22162037047ab90fc90cfa0246 (diff) | |
download | gitlab-ce-f8530580100f56fe3bef5f3a73d3e543b038f98f.tar.gz |
Allow to search for user by secondary email address in the admin interface
It is not possible to search for a user by his secondary email address in
the Users search bar in the admin interface(/admin/users). A use-case could
be that an admin wants to remove a specific secondary email address of an
user, because it interferes with another user. Issue #23761
This commit adds ability to search not only by main email, but also
by any secondary email in the admin interface.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/users_controller.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 57efa899694..bb912ed10cc 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -3,7 +3,7 @@ class Admin::UsersController < Admin::ApplicationController def index @users = User.order_name_asc.filter(params[:filter]) - @users = @users.search(params[:search_query]) if params[:search_query].present? + @users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present? @users = @users.sort(@sort = params[:sort]) @users = @users.page(params[:page]) end diff --git a/app/models/user.rb b/app/models/user.rb index e2a97c3a757..af3c0b7dc02 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -258,6 +258,24 @@ class User < ActiveRecord::Base ) end + # searches user by given pattern + # it compares name, email, username fields and user's secondary emails with given pattern + # This method uses ILIKE on PostgreSQL and LIKE on MySQL. + + def search_with_secondary_emails(query) + table = arel_table + email_table = Email.arel_table + pattern = "%#{query}%" + matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern)) + + where( + table[:name].matches(pattern). + or(table[:email].matches(pattern)). + or(table[:username].matches(pattern)). + or(table[:id].in(matched_by_emails_user_ids)) + ) + end + def by_login(login) return nil unless login |