Use a generic name for the search parameter
This way we can use it for any model.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<div class="small-12 medium-6">
|
||||
<%= form_tag(url, method: :get) do |f| %>
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %>
|
||||
<%= text_field_tag :search, search_terms.to_s, placeholder: t("admin.shared.user_search.placeholder") %>
|
||||
<div class="input-group-button">
|
||||
<%= submit_tag t("admin.shared.user_search.button"), class: "button" %>
|
||||
</div>
|
||||
|
||||
@@ -4,4 +4,10 @@ class Admin::SearchComponent < ApplicationComponent
|
||||
def initialize(url:)
|
||||
@url = url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def search_terms
|
||||
params[:search]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class Admin::AdministratorsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.search(params[:name_or_email])
|
||||
@users = User.search(params[:search])
|
||||
.includes(:administrator)
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
|
||||
@@ -6,7 +6,7 @@ class Admin::ManagersController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.search(params[:name_or_email])
|
||||
@users = User.search(params[:search])
|
||||
.includes(:manager)
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
|
||||
@@ -6,7 +6,7 @@ class Admin::ModeratorsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.search(params[:name_or_email])
|
||||
@users = User.search(params[:search])
|
||||
.includes(:moderator)
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
|
||||
@@ -4,7 +4,7 @@ class Admin::OfficialsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.search(params[:name_or_email]).page(params[:page]).for_render
|
||||
@users = User.search(params[:search]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
@@ -12,7 +12,7 @@ class Admin::OrganizationsController < Admin::BaseController
|
||||
|
||||
def search
|
||||
@organizations = Organization.includes(:user)
|
||||
.search(params[:term])
|
||||
.search(params[:search])
|
||||
.order("users.created_at", :name, "users.email")
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class Admin::Poll::OfficersController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
@user = User.find_by(email: params[:search])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
|
||||
@@ -10,7 +10,7 @@ class Admin::ValuatorsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.search(params[:name_or_email])
|
||||
@users = User.search(params[:search])
|
||||
.includes(:valuator)
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
|
||||
@@ -4,7 +4,7 @@ class Admin::VerificationsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def search
|
||||
@users = User.incomplete_verification.search(params[:name_or_email])
|
||||
@users = User.incomplete_verification.search(params[:search])
|
||||
.page(params[:page])
|
||||
.for_render
|
||||
render :index
|
||||
|
||||
@@ -21,7 +21,7 @@ class Moderation::UsersController < Moderation::BaseController
|
||||
private
|
||||
|
||||
def load_users
|
||||
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
|
||||
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def block_user
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="small-12 medium-6">
|
||||
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
<%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
|
||||
<div class="input-group-button">
|
||||
<%= f.submit t("admin.organizations.index.search"), class: "button" %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="small-12 medium-6">
|
||||
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
<%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
<div class="input-group-button">
|
||||
<%= f.submit t("admin.organizations.index.search"), class: "button" %>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<%= form_tag search_admin_officers_path, method: :get, remote: true do %>
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :email, "",
|
||||
<%= text_field_tag :search, "",
|
||||
placeholder: t("admin.poll_officers.search.email_placeholder") %>
|
||||
<div class="input-group-button">
|
||||
<%= submit_tag t("admin.poll_officers.search.search"), class: "button" %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :name_or_email, "", placeholder: t("moderation.users.index.search_placeholder") %>
|
||||
<%= text_field_tag :search, "", placeholder: t("moderation.users.index.search_placeholder") %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.submit t("moderation.users.index.search"), class: "button success" %>
|
||||
|
||||
@@ -7,9 +7,9 @@ describe Moderation::UsersController do
|
||||
it "keeps query parameters while using protected redirects" do
|
||||
user = create(:user, email: "user@consul.dev")
|
||||
|
||||
get :hide_in_moderation_screen, params: { id: user, name_or_email: "user@consul.dev", host: "evil.dev" }
|
||||
get :hide_in_moderation_screen, params: { id: user, search: "user@consul.dev", host: "evil.dev" }
|
||||
|
||||
expect(response).to redirect_to "/moderation/users?name_or_email=user%40consul.dev"
|
||||
expect(response).to redirect_to "/moderation/users?search=user%40consul.dev"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -223,7 +223,7 @@ describe "Admin activity" do
|
||||
scenario "Shows moderation activity from moderation screen" do
|
||||
user = create(:user)
|
||||
|
||||
visit moderation_users_path(name_or_email: user.username)
|
||||
visit moderation_users_path(search: user.username)
|
||||
|
||||
within("#moderation_users") do
|
||||
click_link "Block"
|
||||
|
||||
@@ -19,7 +19,7 @@ describe "Admin administrators" do
|
||||
end
|
||||
|
||||
scenario "Create Administrator", :js do
|
||||
fill_in "name_or_email", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content user.name
|
||||
@@ -66,7 +66,7 @@ describe "Admin administrators" do
|
||||
expect(page).to have_content(administrator1.name)
|
||||
expect(page).to have_content(administrator2.name)
|
||||
|
||||
fill_in "name_or_email", with: " "
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Administrators: User search")
|
||||
@@ -79,11 +79,11 @@ describe "Admin administrators" do
|
||||
expect(page).to have_content(administrator1.name)
|
||||
expect(page).to have_content(administrator2.name)
|
||||
|
||||
fill_in "name_or_email", with: "Sumn"
|
||||
fill_in "search", with: "Sumn"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Administrators: User search")
|
||||
expect(page).to have_field "name_or_email", with: "Sumn"
|
||||
expect(page).to have_field "search", with: "Sumn"
|
||||
expect(page).to have_content(administrator1.name)
|
||||
expect(page).not_to have_content(administrator2.name)
|
||||
end
|
||||
@@ -92,11 +92,11 @@ describe "Admin administrators" do
|
||||
expect(page).to have_content(administrator1.email)
|
||||
expect(page).to have_content(administrator2.email)
|
||||
|
||||
fill_in "name_or_email", with: administrator2.email
|
||||
fill_in "search", with: administrator2.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Administrators: User search")
|
||||
expect(page).to have_field "name_or_email", with: administrator2.email
|
||||
expect(page).to have_field "search", with: administrator2.email
|
||||
expect(page).to have_content(administrator2.email)
|
||||
expect(page).not_to have_content(administrator1.email)
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ describe "Admin managers", :admin do
|
||||
end
|
||||
|
||||
scenario "Create Manager", :js do
|
||||
fill_in "name_or_email", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content user.name
|
||||
@@ -47,7 +47,7 @@ describe "Admin managers", :admin do
|
||||
expect(page).to have_content(manager1.name)
|
||||
expect(page).to have_content(manager2.name)
|
||||
|
||||
fill_in "name_or_email", with: " "
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Managers: User search")
|
||||
@@ -60,11 +60,11 @@ describe "Admin managers", :admin do
|
||||
expect(page).to have_content(manager1.name)
|
||||
expect(page).to have_content(manager2.name)
|
||||
|
||||
fill_in "name_or_email", with: "Taylor"
|
||||
fill_in "search", with: "Taylor"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Managers: User search")
|
||||
expect(page).to have_field "name_or_email", with: "Taylor"
|
||||
expect(page).to have_field "search", with: "Taylor"
|
||||
expect(page).to have_content(manager1.name)
|
||||
expect(page).not_to have_content(manager2.name)
|
||||
end
|
||||
@@ -73,11 +73,11 @@ describe "Admin managers", :admin do
|
||||
expect(page).to have_content(manager1.email)
|
||||
expect(page).to have_content(manager2.email)
|
||||
|
||||
fill_in "name_or_email", with: manager2.email
|
||||
fill_in "search", with: manager2.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Managers: User search")
|
||||
expect(page).to have_field "name_or_email", with: manager2.email
|
||||
expect(page).to have_field "search", with: manager2.email
|
||||
expect(page).to have_content(manager2.email)
|
||||
expect(page).not_to have_content(manager1.email)
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ describe "Admin moderators", :admin do
|
||||
end
|
||||
|
||||
scenario "Create Moderator", :js do
|
||||
fill_in "name_or_email", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content user.name
|
||||
@@ -47,7 +47,7 @@ describe "Admin moderators", :admin do
|
||||
expect(page).to have_content(moderator1.name)
|
||||
expect(page).to have_content(moderator2.name)
|
||||
|
||||
fill_in "name_or_email", with: " "
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Moderators: User search")
|
||||
@@ -60,11 +60,11 @@ describe "Admin moderators", :admin do
|
||||
expect(page).to have_content(moderator1.name)
|
||||
expect(page).to have_content(moderator2.name)
|
||||
|
||||
fill_in "name_or_email", with: "Eliz"
|
||||
fill_in "search", with: "Eliz"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Moderators: User search")
|
||||
expect(page).to have_field "name_or_email", with: "Eliz"
|
||||
expect(page).to have_field "search", with: "Eliz"
|
||||
expect(page).to have_content(moderator1.name)
|
||||
expect(page).not_to have_content(moderator2.name)
|
||||
end
|
||||
@@ -73,11 +73,11 @@ describe "Admin moderators", :admin do
|
||||
expect(page).to have_content(moderator1.email)
|
||||
expect(page).to have_content(moderator2.email)
|
||||
|
||||
fill_in "name_or_email", with: moderator2.email
|
||||
fill_in "search", with: moderator2.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Moderators: User search")
|
||||
expect(page).to have_field "name_or_email", with: moderator2.email
|
||||
expect(page).to have_field "search", with: moderator2.email
|
||||
expect(page).to have_content(moderator2.email)
|
||||
expect(page).not_to have_content(moderator1.email)
|
||||
end
|
||||
|
||||
@@ -38,7 +38,7 @@ describe "Admin officials", :admin do
|
||||
|
||||
scenario "Create an official" do
|
||||
visit admin_officials_path
|
||||
fill_in "name_or_email", with: citizen.email
|
||||
fill_in "search", with: citizen.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_current_path(search_admin_officials_path, ignore_query: true)
|
||||
|
||||
@@ -36,7 +36,7 @@ describe "Admin::Organizations" do
|
||||
visit admin_organizations_path
|
||||
expect(page).to have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: " "
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_current_path(search_admin_organizations_path, ignore_query: true)
|
||||
@@ -49,7 +49,7 @@ describe "Admin::Organizations" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).not_to have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: "Up, sta"
|
||||
fill_in "search", with: "Up, sta"
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
@@ -61,7 +61,7 @@ describe "Admin::Organizations" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).not_to have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
@@ -73,7 +73,7 @@ describe "Admin::Organizations" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).not_to have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: user.phone_number
|
||||
fill_in "search", with: user.phone_number
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
|
||||
@@ -15,7 +15,7 @@ describe "Admin poll officers", :admin do
|
||||
end
|
||||
|
||||
scenario "Create", :js do
|
||||
fill_in "email", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content user.name
|
||||
|
||||
@@ -22,7 +22,7 @@ describe "Admin valuators", :admin do
|
||||
end
|
||||
|
||||
scenario "Create", :js do
|
||||
fill_in "name_or_email", with: user.email
|
||||
fill_in "search", with: user.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content(user.name)
|
||||
@@ -72,7 +72,7 @@ describe "Admin valuators", :admin do
|
||||
expect(page).to have_content(valuator1.name)
|
||||
expect(page).to have_content(valuator2.name)
|
||||
|
||||
fill_in "name_or_email", with: " "
|
||||
fill_in "search", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Valuators: User search")
|
||||
@@ -85,11 +85,11 @@ describe "Admin valuators", :admin do
|
||||
expect(page).to have_content(valuator1.name)
|
||||
expect(page).to have_content(valuator2.name)
|
||||
|
||||
fill_in "name_or_email", with: "Foster"
|
||||
fill_in "search", with: "Foster"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Valuators: User search")
|
||||
expect(page).to have_field "name_or_email", with: "Foster"
|
||||
expect(page).to have_field "search", with: "Foster"
|
||||
expect(page).to have_content(valuator1.name)
|
||||
expect(page).not_to have_content(valuator2.name)
|
||||
end
|
||||
@@ -98,11 +98,11 @@ describe "Admin valuators", :admin do
|
||||
expect(page).to have_content(valuator1.email)
|
||||
expect(page).to have_content(valuator2.email)
|
||||
|
||||
fill_in "name_or_email", with: valuator2.email
|
||||
fill_in "search", with: valuator2.email
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Valuators: User search")
|
||||
expect(page).to have_field "name_or_email", with: valuator2.email
|
||||
expect(page).to have_field "search", with: valuator2.email
|
||||
expect(page).to have_content(valuator2.email)
|
||||
expect(page).not_to have_content(valuator1.email)
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ describe "Incomplete verifications", :admin do
|
||||
|
||||
visit admin_verifications_path
|
||||
|
||||
fill_in "name_or_email", with: "juan"
|
||||
fill_in "search", with: "juan"
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content("Juan_anonymous")
|
||||
|
||||
@@ -58,7 +58,7 @@ describe "Moderate users" do
|
||||
visit moderation_users_path
|
||||
|
||||
expect(page).not_to have_content citizen.name
|
||||
fill_in "name_or_email", with: "Wanda"
|
||||
fill_in "search", with: "Wanda"
|
||||
click_button "Search"
|
||||
|
||||
within("#moderation_users") do
|
||||
|
||||
Reference in New Issue
Block a user