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/models/organization.rb b/app/models/organization.rb index 20c74d31c..a4561ba7f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -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 diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index e605e8298..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 %> @@ -34,14 +34,6 @@ <%= organization.name %> <%= organization.email %> <%= organization.phone_number %> - - Colectivo - - - - <%= link_to t("admin.organizations.index.edit"), "", class: "button radius tiny" %> - - <% if organization.verified? %> 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| %> + + + + + <% if organization.verified? %> + + <% end %> + <% if can? :verify, organization %> + + <% end %> + <% if organization.rejected? %> + + <% end %> + <% if can? :reject, organization %> + + <% end %> + +<% end %> +
<%= organization.name %><%= organization.email %><%= organization.phone_number %> + + <%= t("admin.organizations.index.verified") %> + + <%= link_to t("admin.organizations.index.verify"), + verify_admin_organization_path(organization, request.query_parameters), + method: :put, class: "button radius tiny success" + %> + + + <%= t("admin.organizations.index.rejected") %> + <%= link_to t("admin.organizations.index.reject"), + reject_admin_organization_path(organization, request.query_parameters), + method: :put, class: "button radius tiny alert" + %> +
+ +<%= paginate @organizations %> \ No newline at end of file diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index c18c13b8a..15ae47b8e 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -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 %> <% end %> diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index 3752421e1..576dd4ce6 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -16,7 +16,7 @@ - <%= f.submit(class: "button radius success") %> + <%= f.submit(t("admin.tags.create"), class: "button radius success") %> <% end %> @@ -39,7 +39,7 @@ <% end %> - <%= 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 %> diff --git a/app/views/organizations/registrations/success.html.erb b/app/views/organizations/registrations/success.html.erb index e246365f5..89f5c75cc 100644 --- a/app/views/organizations/registrations/success.html.erb +++ b/app/views/organizations/registrations/success.html.erb @@ -2,7 +2,7 @@

<%= t("devise_views.organizations.registrations.success.title") %>

-

<%= t("devise_views.organizations.registrations.success.thank_you") %>

+

<%= t("devise_views.organizations.registrations.success.thank_you_html") %>

<%= t("devise_views.organizations.registrations.success.instructions_1_html") %>

<%= t("devise_views.organizations.registrations.success.instructions_2_html") %>

<%= t("devise_views.organizations.registrations.success.instructions_3_html") %>

diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9d..ff6938b70 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -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 diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 2f1606719..129802760 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -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 diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 923b87925..5ddfa9498 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -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 diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 79676f2ee..c4ec2501c 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -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 pending verification." + thank_you_html: "Thank you for registering your organization or collective in the website. Now is pending verification." instructions_1_html: "We will contact you soon in order to verify that you represent your collective." instructions_2_html: "Meanwhile, review your email. We have sent you a confirmation link to activate your account." instructions_3_html: "When you confirm your account will then be able to participate as a non-verified organization." diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index a1ab6dcd3..f1a4b368f 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -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á pendiente de verificación." + thank_you_html: "Gracias por registrar tu colectivo en la web. Ahora está pendiente de verificación." instructions_1_html: "En breve nos pondremos en contacto contigo para verificar que realmente representas a este colectivo." instructions_2_html: "Mientras revisa tu correo electrónico, te hemos enviado un enlace para confirmar tu cuenta." instructions_3_html: "Una vez confirmado, podrás empezar a participar como colectivo no verificado." 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 diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index a64e48a6a..e9a9bf13d 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -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!' diff --git a/spec/features/admin_spec.rb b/spec/features/admin_spec.rb index 6c19b03f7..a096b2b83 100644 --- a/spec/features/admin_spec.rb +++ b/spec/features/admin_spec.rb @@ -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 diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 6fad93d5b..c755413c1 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -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