Merge pull request #287 from AyuntamientoMadrid/admin-improvements

Admin improvements
This commit is contained in:
Raimond Garcia
2015-08-29 16:59:53 +02:00
17 changed files with 187 additions and 32 deletions

View File

@@ -2,13 +2,17 @@ class Admin::OrganizationsController < Admin::BaseController
before_filter :set_valid_filters, only: :index before_filter :set_valid_filters, only: :index
before_filter :parse_filter, only: :index before_filter :parse_filter, only: :index
load_and_authorize_resource load_and_authorize_resource except: :search
def index def index
@organizations = @organizations.send(@filter) @organizations = @organizations.send(@filter)
@organizations = @organizations.includes(:user).order(:name, 'users.email').page(params[:page]) @organizations = @organizations.includes(:user).order(:name, 'users.email').page(params[:page])
end end
def search
@organizations = Organization.search(params[:term]).page(params[:page])
end
def verify def verify
@organization.verify @organization.verify
redirect_to request.query_parameters.merge(action: :index) redirect_to request.query_parameters.merge(action: :index)

View File

@@ -28,4 +28,8 @@ class Organization < ActiveRecord::Base
(verified_at.blank? || verified_at < rejected_at) (verified_at.blank? || verified_at < rejected_at)
end end
def self.search(text)
text.present? ? joins(:user).where("users.email = ? OR users.phone_number = ? OR organizations.name ILIKE ?", text, text, "%#{text}%") : none
end
end end

View File

@@ -1,13 +1,13 @@
<h2><%= t("admin.organizations.index.title") %></h2> <h2><%= t("admin.organizations.index.title") %></h2>
<!-- Search organizations --> <!-- 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="row">
<div class="small-12 medium-6 column"> <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>
<div class="form-inline small-12 medium-6 column"> <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>
</div> </div>
<% end %> <% end %>
@@ -34,14 +34,6 @@
<td><%= organization.name %></td> <td><%= organization.name %></td>
<td><%= organization.email %></td> <td><%= organization.email %></td>
<td><%= organization.phone_number %></td> <td><%= organization.phone_number %></td>
<!-- Badge collective name, "collective" by default -->
<td>Colectivo</td>
<!-- /. Badge collective name, "collective" by default -->
<td>
<!-- Edit collective bagde, "collective" by default -->
<%= link_to t("admin.organizations.index.edit"), "", class: "button radius tiny" %>
<!-- /. Edit collective bagde, "collective" by default -->
</td>
<% if organization.verified? %> <% if organization.verified? %>
<td class="verified"> <td class="verified">
<i class="icon-check"></i> <i class="icon-check"></i>

View 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 %>

View File

@@ -7,7 +7,7 @@
<%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %> <%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
<%= f.text_field :value, label: false, id: dom_id(setting) %> <%= f.text_field :value, label: false, id: dom_id(setting) %>
<%= f.submit(class: "button radius tiny success") %> <%= f.submit(t('admin.settings.index.update_setting'), class: "button radius tiny success") %>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>

View File

@@ -16,7 +16,7 @@
</div> </div>
</div> </div>
<%= f.submit(class: "button radius success") %> <%= f.submit(t("admin.tags.create"), class: "button radius success") %>
<% end %> <% end %>
@@ -39,7 +39,7 @@
<% end %> <% end %>
</span> </span>
<%= f.submit(class: "button radius tiny success") %> <%= f.submit(t("admin.tags.update"), class: "button radius tiny success") %>
<%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: "delete" %> <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: "delete" %>
<% end %> <% end %>

View File

@@ -2,7 +2,7 @@
<div class="small-12 medium-8 column small-centered"> <div class="small-12 medium-8 column small-centered">
<div class="panel"> <div class="panel">
<h2><%= t("devise_views.organizations.registrations.success.title") %></h2> <h2><%= t("devise_views.organizations.registrations.success.title") %></h2>
<p><%= t("devise_views.organizations.registrations.success.thank_you") %></p> <p><%= t("devise_views.organizations.registrations.success.thank_you_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p> <p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p> <p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p> <p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p>

View File

@@ -14,3 +14,7 @@
# ActiveSupport::Inflector.inflections(:en) do |inflect| # ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful' # inflect.acronym 'RESTful'
# end # end
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular 'organización', 'organizaciones'
end

View File

@@ -3,6 +3,7 @@ en:
settings: settings:
index: index:
title: Global settings title: Global settings
update_setting: Update
flash: flash:
updated: 'Setting updated!' updated: 'Setting updated!'
dashboard: dashboard:
@@ -21,17 +22,20 @@ en:
organizations: organizations:
index: index:
title: Organizations title: Organizations
search_placeholder: "Name, email or phone"
search: Search
verify: Verify verify: Verify
reject: Reject reject: Reject
verified: Verified verified: Verified
rejected: Rejected rejected: Rejected
filter: Filter filter: Filter
edit: Edit
filters: filters:
all: All all: All
pending: Pending pending: Pending
verified: Verified verified: Verified
rejected: Rejected rejected: Rejected
search:
title: "Search Organizations"
actions: actions:
hide: Hide hide: Hide
hide_author: Ban author hide_author: Ban author
@@ -45,7 +49,9 @@ en:
mark_as_featured: 'Propose topic to create debate' mark_as_featured: 'Propose topic to create debate'
name: name:
placeholder: 'Write a topic' placeholder: 'Write a topic'
destroy: Delete Tag create: Create Topic
update: Update Topic
destroy: Delete Topic
comments: comments:
index: index:
title: Hidden comments title: Hidden comments

View File

@@ -3,6 +3,7 @@ es:
settings: settings:
index: index:
title: Configuración global title: Configuración global
update_setting: Actualizar
flash: flash:
updated: 'Valor actualizado' updated: 'Valor actualizado'
dashboard: dashboard:
@@ -21,17 +22,20 @@ es:
organizations: organizations:
index: index:
title: Organizaciones title: Organizaciones
search_placeholder: "Nombre, email o teléfono"
search: Buscar
verify: Verificar verify: Verificar
reject: Rechazar reject: Rechazar
verified: Verificada verified: Verificada
rejected: Rechazada rejected: Rechazada
filter: Filtro filter: Filtro
edit: Editar
filters: filters:
all: Todas all: Todas
pending: Pendientes pending: Pendientes
verified: Verificadas verified: Verificadas
rejected: Rechazadas rejected: Rechazadas
search:
title: "Buscar Organizaciones"
actions: actions:
hide: Ocultar hide: Ocultar
hide_author: Bloquear al autor hide_author: Bloquear al autor
@@ -45,11 +49,13 @@ es:
mark_as_featured: 'Proponer tema al crear debate' mark_as_featured: 'Proponer tema al crear debate'
name: name:
placeholder: 'Escribe el nombre del tema' placeholder: 'Escribe el nombre del tema'
destroy: Elimina la etiqueta create: Crear Tema
update: Actualizar Tema
destroy: Eliminar Tema
comments: comments:
index: index:
title: Comentarios ocultos title: Comentarios ocultos
filter: Firar filter: Filtro
filters: filters:
all: Todos all: Todos
with_confirmed_hide: Confirmados with_confirmed_hide: Confirmados
@@ -63,7 +69,7 @@ es:
users: users:
index: index:
title: Usuarios bloqueados title: Usuarios bloqueados
filter: Filro filter: Filtro
filters: filters:
all: Todos all: Todos
with_confirmed_hide: Confirmados with_confirmed_hide: Confirmados

View File

@@ -71,7 +71,7 @@ en:
submit: "Sign up" submit: "Sign up"
success: success:
title: "Registration of organization / collective" title: "Registration of organization / collective"
thank_you: "Thank you for registering your organization or collective in the website. Now is <b>pending verification</b>." thank_you_html: "Thank you for registering your organization or collective in the website. Now is <b>pending verification</b>."
instructions_1_html: "We will <b>contact you soon</b> in order to verify that you represent your collective." instructions_1_html: "We will <b>contact you soon</b> in order to verify that you represent your collective."
instructions_2_html: "Meanwhile, <b>review your email</b>. We have sent you a <b>confirmation link to activate your account</b>." instructions_2_html: "Meanwhile, <b>review your email</b>. We have sent you a <b>confirmation link to activate your account</b>."
instructions_3_html: "When you confirm your account will then be able to participate as a non-verified organization." instructions_3_html: "When you confirm your account will then be able to participate as a non-verified organization."

View File

@@ -71,7 +71,7 @@ es:
submit: "Registrarse" submit: "Registrarse"
success: success:
title: "Registro de organización / colectivo" title: "Registro de organización / colectivo"
thank_you: "Gracias por registrar tu colectivo en la web. Ahora está <b>pendiente de verificación</b>." thank_you_html: "Gracias por registrar tu colectivo en la web. Ahora está <b>pendiente de verificación</b>."
instructions_1_html: "En breve <b>nos pondremos en contacto contigo</b> para verificar que realmente representas a este colectivo." instructions_1_html: "En breve <b>nos pondremos en contacto contigo</b> para verificar que realmente representas a este colectivo."
instructions_2_html: "Mientras <b>revisa tu correo electrónico</b>, te hemos enviado un <b>enlace para confirmar tu cuenta</b>." instructions_2_html: "Mientras <b>revisa tu correo electrónico</b>, te hemos enviado un <b>enlace para confirmar tu cuenta</b>."
instructions_3_html: "Una vez confirmado, podrás empezar a participar como colectivo no verificado." instructions_3_html: "Una vez confirmado, podrás empezar a participar como colectivo no verificado."

View File

@@ -54,6 +54,7 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
root to: "dashboard#index" root to: "dashboard#index"
resources :organizations, only: :index do resources :organizations, only: :index do
collection { get :search }
member do member do
put :verify put :verify
put :reject put :reject

View File

@@ -2,7 +2,6 @@ require 'rails_helper'
feature 'Admin::Organizations' do feature 'Admin::Organizations' do
background do background do
administrator = create(:user) administrator = create(:user)
create(:administrator, user: administrator) create(:administrator, user: administrator)
@@ -10,7 +9,64 @@ feature 'Admin::Organizations' do
login_as(administrator) login_as(administrator)
end 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) organization = create(:organization)
visit admin_organizations_path visit admin_organizations_path
@@ -24,7 +80,7 @@ feature 'Admin::Organizations' do
expect(organization.reload.verified?).to eq(true) expect(organization.reload.verified?).to eq(true)
end end
scenario "verified organizations have link to reject" do scenario "Verified organizations have link to reject" do
organization = create(:organization, :verified) organization = create(:organization, :verified)
visit admin_organizations_path visit admin_organizations_path
@@ -39,7 +95,7 @@ feature 'Admin::Organizations' do
expect(organization.reload.rejected?).to eq(true) expect(organization.reload.rejected?).to eq(true)
end end
scenario "rejected organizations have link to verify" do scenario "Rejected organizations have link to verify" do
organization = create(:organization, :rejected) organization = create(:organization, :rejected)
visit admin_organizations_path visit admin_organizations_path

View File

@@ -22,7 +22,7 @@ feature 'Admin settings' do
within("#edit_setting_#{@setting2.id}") do within("#edit_setting_#{@setting2.id}") do
fill_in "setting_#{@setting2.id}", with: 'Super Users of level 2' fill_in "setting_#{@setting2.id}", with: 'Super Users of level 2'
click_button 'Update Setting' click_button 'Update'
end end
expect(page).to have_content 'Setting updated!' expect(page).to have_content 'Setting updated!'

View File

@@ -85,7 +85,7 @@ feature 'Admin' do
fill_in 'tag_name', with: 'Papeleras' fill_in 'tag_name', with: 'Papeleras'
click_on 'Create Tag' click_on 'Create Topic'
expect(page).to have_content 'Papeleras' expect(page).to have_content 'Papeleras'
end end
@@ -97,7 +97,7 @@ feature 'Admin' do
expect(page).to have_content 'Mi barrio' expect(page).to have_content 'Mi barrio'
click_link 'Delete Tag' click_link 'Delete Topic'
expect(page).not_to have_content 'Mi barrio' expect(page).not_to have_content 'Mi barrio'
end end
@@ -110,7 +110,7 @@ feature 'Admin' do
expect(page).to have_content 'Mi barrio' expect(page).to have_content 'Mi barrio'
check "tag_featured_#{unfeatured_tag.id}" check "tag_featured_#{unfeatured_tag.id}"
click_button 'Update Tag' click_button 'Update Topic'
expect(page).to have_checked_field("tag_featured_#{unfeatured_tag.id}") expect(page).to have_checked_field("tag_featured_#{unfeatured_tag.id}")
end end

View File

@@ -43,4 +43,31 @@ describe Organization do
expect(subject.rejected?).to be false expect(subject.rejected?).to be false
end end
end end
describe "self.search" do
before(:all) {@organization = create(:organization, name: "Watershed", user: create(:user, phone_number: "333"))}
it "returns no results if search term is empty" do
expect(Organization.search(" ").size).to eq(0)
end
it "finds fuzzily by name" do
expect(Organization.search("Greenpeace").size).to eq 0
search = Organization.search("Tershe")
expect(search.size).to eq 1
expect(search.first).to eq @organization
end
scenario "finds by users email" do
search = Organization.search(@organization.user.email)
expect(search.size).to eq 1
expect(search.first).to eq @organization
end
scenario "finds by users phone number" do
search = Organization.search(@organization.user.phone_number)
expect(search.size).to eq 1
expect(search.first).to eq @organization
end
end
end end