adds filters to admin/organizations
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
class Admin::OrganizationsController < Admin::BaseController
|
||||
before_filter :set_valid_filters
|
||||
before_filter :parse_filter
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@organizations = @organizations.send(@filter)
|
||||
@organizations = @organizations.includes(:user).order(:name, 'users.email')
|
||||
end
|
||||
|
||||
def verify
|
||||
@organization.verify
|
||||
redirect_to action: :index
|
||||
redirect_to action: :index, filter: @filter
|
||||
end
|
||||
|
||||
def reject
|
||||
@organization.reject
|
||||
redirect_to action: :index
|
||||
redirect_to action: :index, filter: @filter
|
||||
end
|
||||
|
||||
private
|
||||
def set_valid_filters
|
||||
@valid_filters = %w{all pending verified rejected}
|
||||
end
|
||||
|
||||
def parse_filter
|
||||
@filter = params[:filter]
|
||||
@filter = 'all' unless @valid_filters.include?(@filter)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,9 +3,14 @@ class Organization < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
validates :name, presence: true
|
||||
validates :user_id, presence: true
|
||||
|
||||
delegate :email, :phone_number, to: :user
|
||||
|
||||
scope :pending, -> { where(verified_at: nil, rejected_at: nil) }
|
||||
scope :verified, -> { where("verified_at is not null and (rejected_at is null or rejected_at < verified_at)") }
|
||||
scope :rejected, -> { where("rejected_at is not null and (verified_at is null or verified_at < rejected_at)") }
|
||||
|
||||
def verify
|
||||
update(verified_at: Time.now)
|
||||
end
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
|
||||
<h1><%= t('admin.organizations.index.title') %></h1>
|
||||
|
||||
<p>
|
||||
<%= t('admin.organizations.index.filter') %>:
|
||||
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @filter == filter %>
|
||||
<%= t("admin.organizations.index.filters.#{filter}") %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.organizations.index.filters.#{filter}"),
|
||||
admin_organizations_path(filter: filter) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<% @organizations.each do |organization| %>
|
||||
<tr>
|
||||
@@ -13,7 +26,7 @@
|
||||
<% end %>
|
||||
<% if can? :verify, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.verify'),
|
||||
verify_admin_organization_path(organization),
|
||||
verify_admin_organization_path(organization, filter: @filter),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
@@ -23,7 +36,7 @@
|
||||
<% end %>
|
||||
<% if can? :reject, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.reject'),
|
||||
reject_admin_organization_path(organization),
|
||||
reject_admin_organization_path(organization, filter: @filter),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
@@ -31,4 +44,5 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -94,6 +94,7 @@ ignore_missing:
|
||||
## Consider these keys used:
|
||||
ignore_unused:
|
||||
- 'activerecord.*'
|
||||
- 'admin.organizations.index.filter.*'
|
||||
# - '{devise,kaminari,will_paginate}.*'
|
||||
# - 'simple_form.{yes,no}'
|
||||
# - 'simple_form.{placeholders,hints,labels}.*'
|
||||
|
||||
@@ -6,6 +6,19 @@ en:
|
||||
dashboard:
|
||||
index:
|
||||
title: Administration
|
||||
organizations:
|
||||
index:
|
||||
title: Organizations
|
||||
verify: Verify
|
||||
reject: Reject
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
filter: Filtro
|
||||
filters:
|
||||
all: All
|
||||
pending: Pending
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
tags:
|
||||
index:
|
||||
title: 'Debate topics'
|
||||
@@ -14,10 +27,4 @@ en:
|
||||
name:
|
||||
placeholder: 'Write a topic'
|
||||
destroy: Delete Tag
|
||||
organizations:
|
||||
index:
|
||||
title: Organizations
|
||||
verify: Verify
|
||||
reject: Reject
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
|
||||
|
||||
@@ -14,9 +14,11 @@ es:
|
||||
verified: Verificado
|
||||
rejected: Rechazado
|
||||
filter: Filtro
|
||||
filter_all: Todas
|
||||
filter_verified: Verificadas
|
||||
filter_rejected: Rechazadas
|
||||
filters:
|
||||
all: Todas
|
||||
pending: Pendientes
|
||||
verified: Verificadas
|
||||
rejected: Rechazadas
|
||||
tags:
|
||||
index:
|
||||
title: 'Temas de debate'
|
||||
|
||||
@@ -14,8 +14,8 @@ feature 'Moderations::Organizations' do
|
||||
organization = create(:organization)
|
||||
|
||||
visit admin_organizations_path
|
||||
expect(page).to have_selector(:link_or_button, 'Verify')
|
||||
expect(page).to have_selector(:link_or_button, 'Reject')
|
||||
expect(page).to have_link('Verify')
|
||||
expect(page).to have_link('Reject')
|
||||
|
||||
click_on 'Verify'
|
||||
expect(current_path).to eq(admin_organizations_path)
|
||||
@@ -29,8 +29,8 @@ feature 'Moderations::Organizations' do
|
||||
|
||||
visit admin_organizations_path
|
||||
expect(page).to have_content ('Verified')
|
||||
expect(page).to_not have_selector(:link_or_button, 'Verify')
|
||||
expect(page).to have_selector(:link_or_button, 'Reject')
|
||||
expect(page).to_not have_link('Verify')
|
||||
expect(page).to have_link('Reject')
|
||||
|
||||
click_on 'Reject'
|
||||
expect(current_path).to eq(admin_organizations_path)
|
||||
@@ -43,9 +43,8 @@ feature 'Moderations::Organizations' do
|
||||
organization = create(:rejected_organization)
|
||||
|
||||
visit admin_organizations_path
|
||||
expect(page).to have_content ('Rejected')
|
||||
expect(page).to have_selector(:link_or_button, 'Verify')
|
||||
expect(page).to_not have_selector(:link_or_button, 'Reject')
|
||||
expect(page).to have_link('Verify')
|
||||
expect(page).to_not have_link('Reject', exact: true)
|
||||
|
||||
click_on 'Verify'
|
||||
expect(current_path).to eq(admin_organizations_path)
|
||||
@@ -54,4 +53,62 @@ feature 'Moderations::Organizations' do
|
||||
expect(organization.reload.verified?).to eq(true)
|
||||
end
|
||||
|
||||
scenario "Current filter is properly highlighted" do
|
||||
visit admin_organizations_path
|
||||
expect(page).to_not have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to have_link('Verified')
|
||||
expect(page).to have_link('Rejected')
|
||||
|
||||
visit admin_organizations_path(filter: 'all')
|
||||
expect(page).to_not have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to have_link('Verified')
|
||||
expect(page).to have_link('Rejected')
|
||||
|
||||
visit admin_organizations_path(filter: 'pending')
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to_not have_link('Pending')
|
||||
expect(page).to have_link('Verified')
|
||||
expect(page).to have_link('Rejected')
|
||||
|
||||
visit admin_organizations_path(filter: 'verified')
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to_not have_link('Verified')
|
||||
expect(page).to have_link('Rejected')
|
||||
|
||||
visit admin_organizations_path(filter: 'rejected')
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to have_link('Pending')
|
||||
expect(page).to have_link('Verified')
|
||||
expect(page).to_not have_link('Rejected')
|
||||
end
|
||||
|
||||
scenario "Filtering organizations" do
|
||||
create(:organization, name: "Pending Organization")
|
||||
create(:rejected_organization, name: "Rejected Organization")
|
||||
create(:verified_organization, name: "Verified Organization")
|
||||
|
||||
visit admin_organizations_path(filter: 'all')
|
||||
expect(page).to have_content('Pending Organization')
|
||||
expect(page).to have_content('Rejected Organization')
|
||||
expect(page).to have_content('Verified Organization')
|
||||
|
||||
visit admin_organizations_path(filter: 'pending')
|
||||
expect(page).to have_content('Pending Organization')
|
||||
expect(page).to_not have_content('Rejected Organization')
|
||||
expect(page).to_not have_content('Verified Organization')
|
||||
|
||||
visit admin_organizations_path(filter: 'verified')
|
||||
expect(page).to_not have_content('Pending Organization')
|
||||
expect(page).to_not have_content('Rejected Organization')
|
||||
expect(page).to have_content('Verified Organization')
|
||||
|
||||
visit admin_organizations_path(filter: 'rejected')
|
||||
expect(page).to_not have_content('Pending Organization')
|
||||
expect(page).to have_content('Rejected Organization')
|
||||
expect(page).to_not have_content('Verified Organization')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user