Extend user list to allow searching by name or email
This commit is contained in:
parent
d82a3df97a
commit
837924027a
4 changed files with 47 additions and 4 deletions
|
@ -13,10 +13,11 @@ module Users
|
||||||
##
|
##
|
||||||
# display a list of users matching specified criteria
|
# display a list of users matching specified criteria
|
||||||
def show
|
def show
|
||||||
@params = params.permit(:status, :ip, :before, :after)
|
@params = params.permit(:status, :username, :ip, :before, :after)
|
||||||
|
|
||||||
users = User.all
|
users = User.all
|
||||||
users = users.where(:status => @params[:status]) if @params[:status].present?
|
users = users.where(:status => @params[:status]) if @params[:status].present?
|
||||||
|
users = users.where("LOWER(email) = LOWER(?) OR LOWER(NORMALIZE(display_name, NFKC)) = LOWER(NORMALIZE(?, NFKC))", @params[:username], @params[:username]) if @params[:username].present?
|
||||||
users = users.where("creation_address <<= ?", @params[:ip]) if @params[:ip].present?
|
users = users.where("creation_address <<= ?", @params[:ip]) if @params[:ip].present?
|
||||||
|
|
||||||
@users_count = users.limit(501).count
|
@users_count = users.limit(501).count
|
||||||
|
|
|
@ -17,6 +17,13 @@
|
||||||
:data => { :behavior => "category_dropdown" },
|
:data => { :behavior => "category_dropdown" },
|
||||||
:class => "form-select" %>
|
:class => "form-select" %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3 col-md">
|
||||||
|
<%= text_field_tag :username,
|
||||||
|
params[:username],
|
||||||
|
:placeholder => t(".name_or_email"),
|
||||||
|
:autocomplete => "on",
|
||||||
|
:class => "form-control" %>
|
||||||
|
</div>
|
||||||
<div class="mb-3 col-md">
|
<div class="mb-3 col-md">
|
||||||
<%= text_field_tag :ip,
|
<%= text_field_tag :ip,
|
||||||
params[:ip],
|
params[:ip],
|
||||||
|
|
|
@ -2897,6 +2897,7 @@ en:
|
||||||
confirmed: Confirmed
|
confirmed: Confirmed
|
||||||
suspended: Suspended
|
suspended: Suspended
|
||||||
deleted: Deleted
|
deleted: Deleted
|
||||||
|
name_or_email: Name or Email
|
||||||
ip_address: IP Address
|
ip_address: IP Address
|
||||||
search: Search
|
search: Search
|
||||||
page:
|
page:
|
||||||
|
|
|
@ -28,11 +28,13 @@ module Users
|
||||||
moderator_user = create(:moderator_user)
|
moderator_user = create(:moderator_user)
|
||||||
administrator_user = create(:administrator_user)
|
administrator_user = create(:administrator_user)
|
||||||
suspended_user = create(:user, :suspended)
|
suspended_user = create(:user, :suspended)
|
||||||
|
name_user = create(:user, :display_name => "Test User")
|
||||||
|
email_user = create(:user, :email => "test@example.com")
|
||||||
ip_user = create(:user, :creation_address => "1.2.3.4")
|
ip_user = create(:user, :creation_address => "1.2.3.4")
|
||||||
|
|
||||||
# There are now 7 users - the five above, plus two extra "granters" for the
|
# There are now 9 users - the 7 above, plus two extra "granters" for the
|
||||||
# moderator_user and administrator_user
|
# moderator_user and administrator_user
|
||||||
assert_equal 7, User.count
|
assert_equal 9, User.count
|
||||||
|
|
||||||
# Shouldn't work when not logged in
|
# Shouldn't work when not logged in
|
||||||
get users_list_path
|
get users_list_path
|
||||||
|
@ -57,7 +59,7 @@ module Users
|
||||||
get users_list_path
|
get users_list_path
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template :show
|
assert_template :show
|
||||||
assert_select "table#user_list tbody tr", :count => 7
|
assert_select "table#user_list tbody tr", :count => 9
|
||||||
|
|
||||||
# Should be able to limit by status
|
# Should be able to limit by status
|
||||||
get users_list_path, :params => { :status => "suspended" }
|
get users_list_path, :params => { :status => "suspended" }
|
||||||
|
@ -67,6 +69,38 @@ module Users
|
||||||
assert_select "a[href='#{user_path(suspended_user)}']", :count => 1
|
assert_select "a[href='#{user_path(suspended_user)}']", :count => 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Should be able to limit by name
|
||||||
|
get users_list_path, :params => { :username => "Test User" }
|
||||||
|
assert_response :success
|
||||||
|
assert_template :show
|
||||||
|
assert_select "table#user_list tbody tr", :count => 1 do
|
||||||
|
assert_select "a[href='#{user_path(name_user)}']", :count => 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Should be able to limit by name ignoring case
|
||||||
|
get users_list_path, :params => { :username => "test user" }
|
||||||
|
assert_response :success
|
||||||
|
assert_template :show
|
||||||
|
assert_select "table#user_list tbody tr", :count => 1 do
|
||||||
|
assert_select "a[href='#{user_path(name_user)}']", :count => 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Should be able to limit by email
|
||||||
|
get users_list_path, :params => { :username => "test@example.com" }
|
||||||
|
assert_response :success
|
||||||
|
assert_template :show
|
||||||
|
assert_select "table#user_list tbody tr", :count => 1 do
|
||||||
|
assert_select "a[href='#{user_path(email_user)}']", :count => 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Should be able to limit by email ignoring case
|
||||||
|
get users_list_path, :params => { :username => "TEST@example.com" }
|
||||||
|
assert_response :success
|
||||||
|
assert_template :show
|
||||||
|
assert_select "table#user_list tbody tr", :count => 1 do
|
||||||
|
assert_select "a[href='#{user_path(email_user)}']", :count => 1
|
||||||
|
end
|
||||||
|
|
||||||
# Should be able to limit by IP address
|
# Should be able to limit by IP address
|
||||||
get users_list_path, :params => { :ip => "1.2.3.4" }
|
get users_list_path, :params => { :ip => "1.2.3.4" }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue