mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:53:41 +08:00
FIX: moderators should be able to search users by email
This commit is contained in:
parent
250bee6a91
commit
6e053942a4
|
@ -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
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
{{/if}}
|
||||
|
||||
<h2>{{title}}</h2>
|
||||
|
||||
<br/>
|
||||
|
||||
{{#if loading}}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" })
|
||||
|
|
Loading…
Reference in New Issue
Block a user