From 6e053942a40052553c5eefbd6218dc85132c5851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 29 Oct 2014 22:08:41 +0100 Subject: [PATCH] FIX: moderators should be able to search users by email --- .../admin/controllers/admin-users-list.js.es6 | 5 +--- .../admin/templates/users_list.hbs | 1 + app/controllers/admin/users_controller.rb | 1 - config/locales/client.en.yml | 3 +- lib/admin_user_index_query.rb | 14 ++------- .../components/admin_user_index_query_spec.rb | 30 +++++++------------ 6 files changed, 16 insertions(+), 38 deletions(-) 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 91d0d8acd4e..00940ddfb94 100644 --- a/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-users-list.js.es6 @@ -18,10 +18,7 @@ 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(), + searchHint: function() { return I18n.t("search_hint"); }.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 dfdbe3c7f54..285182aebf4 100644 --- a/app/assets/javascripts/admin/templates/users_list.hbs +++ b/app/assets/javascripts/admin/templates/users_list.hbs @@ -29,6 +29,7 @@ {{/if}}

{{title}}

+
{{#if loading}} diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index ac6e50afadc..81a449ee061 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -25,7 +25,6 @@ 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 4fb708a275d..2a74b7e102d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -576,8 +576,7 @@ en: created: 'Created' created_lowercase: 'created' trust_level: 'Trust Level' - search_hint: 'username or IP address' - search_hint_admin: 'username, email or IP address' + search_hint: 'username, email or IP address' create_account: title: "Create New Account" diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index ac402772fcb..6376640e0ad 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -36,18 +36,10 @@ class AdminUserIndexQuery def filter_by_search if params[:filter].present? - if params[:admin] == true - if params[:filter] =~ Resolv::IPv4::Regex || params[:filter] =~ Resolv::IPv6::Regex - @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:filter]) - else - @query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%") - end + if params[:filter] =~ Resolv::IPv4::Regex || params[:filter] =~ Resolv::IPv6::Regex + @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:filter]) else - if params[:filter] =~ Resolv::IPv4::Regex || params[:filter] =~ Resolv::IPv6::Regex - @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:filter]) - else - @query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%") - end + @query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%") end end end diff --git a/spec/components/admin_user_index_query_spec.rb b/spec/components/admin_user_index_query_spec.rb index 58bc92a74ee..f07f59c5edb 100644 --- a/spec/components/admin_user_index_query_spec.rb +++ b/spec/components/admin_user_index_query_spec.rb @@ -96,34 +96,23 @@ 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 - + it "matches the email" do + query = ::AdminUserIndexQuery.new({ filter: "est1" }) + expect(query.find_users.count()).to eq(1) 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 - + it "matches the email using any case" do + query = ::AdminUserIndexQuery.new({ filter: "Test1" }) + expect(query.find_users.count()).to eq(1) end end context "by username fragment" do + before(:each) { Fabricate(:user, username: "test_user_1") } it "matches the username" do @@ -138,7 +127,8 @@ describe AdminUserIndexQuery do end context "by ip address fragment" do - before(:each) { Fabricate(:user, ip_address: "117.207.94.9") } + + let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") } it "matches the ip address" do query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" })