diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb
index de99bbc44..bb623702a 100644
--- a/app/controllers/admin/organizations_controller.rb
+++ b/app/controllers/admin/organizations_controller.rb
@@ -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)
diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb
index 409aa166c..524d65a68 100644
--- a/app/views/admin/organizations/index.html.erb
+++ b/app/views/admin/organizations/index.html.erb
@@ -1,13 +1,13 @@
<%= t("admin.organizations.index.title") %>
-<%= 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| %>
- <%= text_field_tag :email, "", placeholder: t("admin.officials.index.search_email_placeholder") %>
+ <%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
- <%= f.submit t("admin.officials.index.search"), class: "button radius success" %>
+ <%= f.submit t("admin.organizations.index.search"), class: "button radius success" %>
<% end %>
diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb
new file mode 100644
index 000000000..3bc8ccedc
--- /dev/null
+++ b/app/views/admin/organizations/search.html.erb
@@ -0,0 +1,55 @@
+<%= t("admin.organizations.search.title") %>
+
+
+<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
+
+
+ <%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
+
+
+ <%= f.submit t("admin.organizations.index.search"), class: "button radius success" %>
+
+
+<% end %>
+
+
+<%= page_entries_info @organizations %>
+
+
+ <% @organizations.each do |organization| %>
+
+ | <%= organization.name %> |
+ <%= organization.email %> |
+ <%= organization.phone_number %> |
+ <% if organization.verified? %>
+
+
+ <%= t("admin.organizations.index.verified") %>
+ |
+ <% end %>
+ <% if can? :verify, organization %>
+
+ <%= link_to t("admin.organizations.index.verify"),
+ verify_admin_organization_path(organization, request.query_parameters),
+ method: :put, class: "button radius tiny success"
+ %>
+ |
+ <% end %>
+ <% if organization.rejected? %>
+
+
+ <%= t("admin.organizations.index.rejected") %>
+ |
+ <% end %>
+ <% if can? :reject, organization %>
+ <%= link_to t("admin.organizations.index.reject"),
+ reject_admin_organization_path(organization, request.query_parameters),
+ method: :put, class: "button radius tiny alert"
+ %>
+ |
+ <% end %>
+
+<% end %>
+
+
+<%= paginate @organizations %>
\ No newline at end of file
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 976988cda..129802760 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -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
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 924c1bd5f..8d7c481ad 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 0cb6c8438..2435e57e4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/features/admin/organizations_spec.rb b/spec/features/admin/organizations_spec.rb
index 7c1756603..adf014e67 100644
--- a/spec/features/admin/organizations_spec.rb
+++ b/spec/features/admin/organizations_spec.rb
@@ -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