FIX: allow admins to search users by email
This commit is contained in:
parent
e8563c7d57
commit
c46b9c0ac3
|
@ -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
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
<div class='username controls'>
|
||||
{{text-field value=username placeholderKey="search_hint"}}
|
||||
{{text-field value=username placeholder=searchHint}}
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<button {{action "exportUsers"}} class="btn" title="{{i18n admin.export_csv.users.title}}"><i class="fa fa-download"></i>{{i18n admin.export_csv.users.text}}</button>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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") }
|
||||
|
||||
|
|
Loading…
Reference in New Issue