diff --git a/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 b/app/assets/javascripts/admin/controllers/admin-users-list.js.es6
index 34ac64c2bf2..91d0d8acd4e 100644
--- a/app/assets/javascripts/admin/controllers/admin-users-list.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-users-list.js.es6
@@ -18,6 +18,11 @@ export default Ember.ArrayController.extend(Discourse.Presence, {
queryPending: Em.computed.equal('query', 'pending'),
queryHasApproval: Em.computed.or('queryNew', 'queryPending'),
+ searchHint: function() {
+ var searchHintKey = Discourse.User.currentProp("admin") ? "search_hint_admin" : "search_hint";
+ return I18n.t(searchHintKey);
+ }.property(),
+
/**
Triggered when the selectAll property is changed
diff --git a/app/assets/javascripts/admin/templates/users_list.hbs b/app/assets/javascripts/admin/templates/users_list.hbs
index d3cc12b2ad7..aca1ba0f2ee 100644
--- a/app/assets/javascripts/admin/templates/users_list.hbs
+++ b/app/assets/javascripts/admin/templates/users_list.hbs
@@ -13,7 +13,7 @@
- {{text-field value=username placeholderKey="search_hint"}}
+ {{text-field value=username placeholder=searchHint}}
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 94665f59294..3b324413339 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -25,6 +25,7 @@ class Admin::UsersController < Admin::AdminController
:revoke_api_key]
def index
+ params.merge!({ admin: current_user.admin? })
query = ::AdminUserIndexQuery.new(params)
render_serialized(query.find_users, AdminUserSerializer)
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index acc5cc2524c..ea7d1b93281 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -579,6 +579,7 @@ en:
created_lowercase: 'created'
trust_level: 'Trust Level'
search_hint: 'username'
+ search_hint_admin: 'username or email'
create_account:
title: "Create New Account"
diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb
index a8c3b3e1f96..fa468c96028 100644
--- a/lib/admin_user_index_query.rb
+++ b/lib/admin_user_index_query.rb
@@ -36,13 +36,17 @@ class AdminUserIndexQuery
def filter_by_search
if params[:filter].present?
- @query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%")
+ if params[:admin] == true
+ @query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%")
+ else
+ @query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%")
+ end
end
end
def filter_by_ip
if params[:ip].present?
- @query.where('ip_address = :ip or registration_ip_address = :ip', ip: params[:ip])
+ @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip])
end
end
diff --git a/spec/components/admin_user_index_query_spec.rb b/spec/components/admin_user_index_query_spec.rb
index 56f116fbe60..0947f2a5e7f 100644
--- a/spec/components/admin_user_index_query_spec.rb
+++ b/spec/components/admin_user_index_query_spec.rb
@@ -96,6 +96,34 @@ describe AdminUserIndexQuery do
describe "filtering" do
+ context "by email fragment" do
+ before(:each) { Fabricate(:user, email: "test1@example.com") }
+
+ context "when authenticated as a non-admin user" do
+
+ it "doesn't match the email" do
+ query = ::AdminUserIndexQuery.new({ filter: "test1@example.com" })
+ expect(query.find_users.count()).to eq(0)
+ end
+
+ end
+
+ context "when authenticated as an admin user" do
+
+ it "matches the email" do
+ query = ::AdminUserIndexQuery.new({ filter: "est1", admin: true })
+ expect(query.find_users.count()).to eq(1)
+ end
+
+ it "matches the email using any case" do
+ query = ::AdminUserIndexQuery.new({ filter: "Test1", admin: true })
+ expect(query.find_users.count()).to eq(1)
+ end
+
+ end
+
+ end
+
context "by username fragment" do
before(:each) { Fabricate(:user, username: "test_user_1") }