implements organizations search for admins
This commit is contained in:
@@ -2,13 +2,17 @@ class Admin::OrganizationsController < Admin::BaseController
|
||||
before_filter :set_valid_filters, only: :index
|
||||
before_filter :parse_filter, only: :index
|
||||
|
||||
load_and_authorize_resource
|
||||
load_and_authorize_resource except: :search
|
||||
|
||||
def index
|
||||
@organizations = @organizations.send(@filter)
|
||||
@organizations = @organizations.includes(:user).order(:name, 'users.email').page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
@organizations = Organization.search(params[:term]).page(params[:page])
|
||||
end
|
||||
|
||||
def verify
|
||||
@organization.verify
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<h2><%= t("admin.organizations.index.title") %></h2>
|
||||
|
||||
<!-- Search organizations -->
|
||||
<%= form_for(User.new, url: search_admin_officials_path, as: :user, method: :get) do |f| %>
|
||||
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :email, "", placeholder: t("admin.officials.index.search_email_placeholder") %>
|
||||
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
</div>
|
||||
<div class="form-inline small-12 medium-6 column">
|
||||
<%= f.submit t("admin.officials.index.search"), class: "button radius success" %>
|
||||
<%= f.submit t("admin.organizations.index.search"), class: "button radius success" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
55
app/views/admin/organizations/search.html.erb
Normal file
55
app/views/admin/organizations/search.html.erb
Normal file
@@ -0,0 +1,55 @@
|
||||
<h2><%= t("admin.organizations.search.title") %></h2>
|
||||
|
||||
<!-- Search organizations -->
|
||||
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
|
||||
</div>
|
||||
<div class="form-inline small-12 medium-6 column">
|
||||
<%= f.submit t("admin.organizations.index.search"), class: "button radius success" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<!-- /. Search organizations -->
|
||||
|
||||
<h3><%= page_entries_info @organizations %></h3>
|
||||
|
||||
<table id="search-results">
|
||||
<% @organizations.each do |organization| %>
|
||||
<tr>
|
||||
<td><%= organization.name %></td>
|
||||
<td><%= organization.email %></td>
|
||||
<td><%= organization.phone_number %></td>
|
||||
<% if organization.verified? %>
|
||||
<td class="verified">
|
||||
<i class="icon-check"></i>
|
||||
<%= t("admin.organizations.index.verified") %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if can? :verify, organization %>
|
||||
<td>
|
||||
<%= link_to t("admin.organizations.index.verify"),
|
||||
verify_admin_organization_path(organization, request.query_parameters),
|
||||
method: :put, class: "button radius tiny success"
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if organization.rejected? %>
|
||||
<td class="rejected">
|
||||
<i class="icon-x"></i>
|
||||
<%= t("admin.organizations.index.rejected") %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if can? :reject, organization %>
|
||||
<td><%= link_to t("admin.organizations.index.reject"),
|
||||
reject_admin_organization_path(organization, request.query_parameters),
|
||||
method: :put, class: "button radius tiny alert"
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @organizations %>
|
||||
@@ -22,6 +22,8 @@ en:
|
||||
organizations:
|
||||
index:
|
||||
title: Organizations
|
||||
search_placeholder: "Name, email or phone"
|
||||
search: Search
|
||||
verify: Verify
|
||||
reject: Reject
|
||||
verified: Verified
|
||||
@@ -32,6 +34,8 @@ en:
|
||||
pending: Pending
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
search:
|
||||
title: "Search Organizations"
|
||||
actions:
|
||||
hide: Hide
|
||||
hide_author: Ban author
|
||||
|
||||
@@ -22,6 +22,8 @@ es:
|
||||
organizations:
|
||||
index:
|
||||
title: Organizaciones
|
||||
search_placeholder: "Nombre, email o teléfono"
|
||||
search: Buscar
|
||||
verify: Verificar
|
||||
reject: Rechazar
|
||||
verified: Verificada
|
||||
@@ -32,6 +34,8 @@ es:
|
||||
pending: Pendientes
|
||||
verified: Verificadas
|
||||
rejected: Rechazadas
|
||||
search:
|
||||
title: "Buscar Organizaciones"
|
||||
actions:
|
||||
hide: Ocultar
|
||||
hide_author: Bloquear al autor
|
||||
|
||||
@@ -54,6 +54,7 @@ Rails.application.routes.draw do
|
||||
namespace :admin do
|
||||
root to: "dashboard#index"
|
||||
resources :organizations, only: :index do
|
||||
collection { get :search }
|
||||
member do
|
||||
put :verify
|
||||
put :reject
|
||||
|
||||
@@ -2,7 +2,6 @@ require 'rails_helper'
|
||||
|
||||
feature 'Admin::Organizations' do
|
||||
|
||||
|
||||
background do
|
||||
administrator = create(:user)
|
||||
create(:administrator, user: administrator)
|
||||
@@ -10,7 +9,64 @@ feature 'Admin::Organizations' do
|
||||
login_as(administrator)
|
||||
end
|
||||
|
||||
scenario "pending organizations have links to verify and reject" do
|
||||
context "Search" do
|
||||
|
||||
background do
|
||||
@user = create(:user, email: "marley@humanrights.com", phone_number: "6764440002")
|
||||
organization = create(:organization, user: @user, name: "Get up, Stand up")
|
||||
end
|
||||
|
||||
scenario "returns no results if search term is empty" do
|
||||
visit admin_organizations_path
|
||||
expect(page).to have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: " "
|
||||
click_button "Search"
|
||||
|
||||
expect(current_path).to eq(search_admin_organizations_path)
|
||||
within("#search-results") do
|
||||
expect(page).to_not have_content("Get up, Stand up")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "finds by name" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).to_not have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: "Up, sta"
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
expect(page).to have_content("Get up, Stand up")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "finds by users email" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).to_not have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: @user.email
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
expect(page).to have_content("Get up, Stand up")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "finds by users phone number" do
|
||||
visit search_admin_organizations_path
|
||||
expect(page).to_not have_content("Get up, Stand up")
|
||||
|
||||
fill_in "term", with: @user.phone_number
|
||||
click_button "Search"
|
||||
|
||||
within("#search-results") do
|
||||
expect(page).to have_content("Get up, Stand up")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Pending organizations have links to verify and reject" do
|
||||
organization = create(:organization)
|
||||
|
||||
visit admin_organizations_path
|
||||
@@ -24,7 +80,7 @@ feature 'Admin::Organizations' do
|
||||
expect(organization.reload.verified?).to eq(true)
|
||||
end
|
||||
|
||||
scenario "verified organizations have link to reject" do
|
||||
scenario "Verified organizations have link to reject" do
|
||||
organization = create(:organization, :verified)
|
||||
|
||||
visit admin_organizations_path
|
||||
@@ -39,7 +95,7 @@ feature 'Admin::Organizations' do
|
||||
expect(organization.reload.rejected?).to eq(true)
|
||||
end
|
||||
|
||||
scenario "rejected organizations have link to verify" do
|
||||
scenario "Rejected organizations have link to verify" do
|
||||
organization = create(:organization, :rejected)
|
||||
|
||||
visit admin_organizations_path
|
||||
|
||||
Reference in New Issue
Block a user