Merge pull request #287 from AyuntamientoMadrid/admin-improvements
Admin improvements
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)
|
||||
|
||||
@@ -28,4 +28,8 @@ class Organization < ActiveRecord::Base
|
||||
(verified_at.blank? || verified_at < rejected_at)
|
||||
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
|
||||
|
||||
@@ -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 %>
|
||||
@@ -34,14 +34,6 @@
|
||||
<td><%= organization.name %></td>
|
||||
<td><%= organization.email %></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? %>
|
||||
<td class="verified">
|
||||
<i class="icon-check"></i>
|
||||
|
||||
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 %>
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<%= 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.submit(class: "button radius tiny success") %>
|
||||
<%= f.submit(t('admin.settings.index.update_setting'), class: "button radius tiny success") %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= f.submit(class: "button radius success") %>
|
||||
<%= f.submit(t("admin.tags.create"), class: "button radius success") %>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<% end %>
|
||||
</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" %>
|
||||
<% end %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="small-12 medium-8 column small-centered">
|
||||
<div class="panel">
|
||||
<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_2_html") %></p>
|
||||
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p>
|
||||
|
||||
@@ -14,3 +14,7 @@
|
||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
# inflect.acronym 'RESTful'
|
||||
# end
|
||||
|
||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
inflect.irregular 'organización', 'organizaciones'
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ en:
|
||||
settings:
|
||||
index:
|
||||
title: Global settings
|
||||
update_setting: Update
|
||||
flash:
|
||||
updated: 'Setting updated!'
|
||||
dashboard:
|
||||
@@ -21,17 +22,20 @@ en:
|
||||
organizations:
|
||||
index:
|
||||
title: Organizations
|
||||
search_placeholder: "Name, email or phone"
|
||||
search: Search
|
||||
verify: Verify
|
||||
reject: Reject
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
filter: Filter
|
||||
edit: Edit
|
||||
filters:
|
||||
all: All
|
||||
pending: Pending
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
search:
|
||||
title: "Search Organizations"
|
||||
actions:
|
||||
hide: Hide
|
||||
hide_author: Ban author
|
||||
@@ -45,7 +49,9 @@ en:
|
||||
mark_as_featured: 'Propose topic to create debate'
|
||||
name:
|
||||
placeholder: 'Write a topic'
|
||||
destroy: Delete Tag
|
||||
create: Create Topic
|
||||
update: Update Topic
|
||||
destroy: Delete Topic
|
||||
comments:
|
||||
index:
|
||||
title: Hidden comments
|
||||
|
||||
@@ -3,6 +3,7 @@ es:
|
||||
settings:
|
||||
index:
|
||||
title: Configuración global
|
||||
update_setting: Actualizar
|
||||
flash:
|
||||
updated: 'Valor actualizado'
|
||||
dashboard:
|
||||
@@ -21,17 +22,20 @@ es:
|
||||
organizations:
|
||||
index:
|
||||
title: Organizaciones
|
||||
search_placeholder: "Nombre, email o teléfono"
|
||||
search: Buscar
|
||||
verify: Verificar
|
||||
reject: Rechazar
|
||||
verified: Verificada
|
||||
rejected: Rechazada
|
||||
filter: Filtro
|
||||
edit: Editar
|
||||
filters:
|
||||
all: Todas
|
||||
pending: Pendientes
|
||||
verified: Verificadas
|
||||
rejected: Rechazadas
|
||||
search:
|
||||
title: "Buscar Organizaciones"
|
||||
actions:
|
||||
hide: Ocultar
|
||||
hide_author: Bloquear al autor
|
||||
@@ -45,11 +49,13 @@ es:
|
||||
mark_as_featured: 'Proponer tema al crear debate'
|
||||
name:
|
||||
placeholder: 'Escribe el nombre del tema'
|
||||
destroy: Elimina la etiqueta
|
||||
create: Crear Tema
|
||||
update: Actualizar Tema
|
||||
destroy: Eliminar Tema
|
||||
comments:
|
||||
index:
|
||||
title: Comentarios ocultos
|
||||
filter: Firar
|
||||
filter: Filtro
|
||||
filters:
|
||||
all: Todos
|
||||
with_confirmed_hide: Confirmados
|
||||
@@ -63,7 +69,7 @@ es:
|
||||
users:
|
||||
index:
|
||||
title: Usuarios bloqueados
|
||||
filter: Filro
|
||||
filter: Filtro
|
||||
filters:
|
||||
all: Todos
|
||||
with_confirmed_hide: Confirmados
|
||||
|
||||
@@ -71,7 +71,7 @@ en:
|
||||
submit: "Sign up"
|
||||
success:
|
||||
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_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."
|
||||
|
||||
@@ -71,7 +71,7 @@ es:
|
||||
submit: "Registrarse"
|
||||
success:
|
||||
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_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."
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,7 +22,7 @@ feature 'Admin settings' do
|
||||
|
||||
within("#edit_setting_#{@setting2.id}") do
|
||||
fill_in "setting_#{@setting2.id}", with: 'Super Users of level 2'
|
||||
click_button 'Update Setting'
|
||||
click_button 'Update'
|
||||
end
|
||||
|
||||
expect(page).to have_content 'Setting updated!'
|
||||
|
||||
@@ -85,7 +85,7 @@ feature 'Admin' do
|
||||
|
||||
fill_in 'tag_name', with: 'Papeleras'
|
||||
|
||||
click_on 'Create Tag'
|
||||
click_on 'Create Topic'
|
||||
|
||||
expect(page).to have_content 'Papeleras'
|
||||
end
|
||||
@@ -97,7 +97,7 @@ feature 'Admin' do
|
||||
|
||||
expect(page).to have_content 'Mi barrio'
|
||||
|
||||
click_link 'Delete Tag'
|
||||
click_link 'Delete Topic'
|
||||
|
||||
expect(page).not_to have_content 'Mi barrio'
|
||||
end
|
||||
@@ -110,7 +110,7 @@ feature 'Admin' do
|
||||
expect(page).to have_content 'Mi barrio'
|
||||
|
||||
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}")
|
||||
end
|
||||
|
||||
@@ -43,4 +43,31 @@ describe Organization do
|
||||
expect(subject.rejected?).to be false
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user