adds organization controller, with views and tests
This commit is contained in:
25
app/controllers/moderation/organizations_controller.rb
Normal file
25
app/controllers/moderation/organizations_controller.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class Moderation::OrganizationsController < Moderation::BaseController
|
||||
|
||||
before_filter :load_organizations, only: :index
|
||||
load_and_authorize_resource class: 'User'
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def verify_organization
|
||||
@organization.update(organization_verified_at: Time.now)
|
||||
redirect_to action: :index
|
||||
end
|
||||
|
||||
def reject_organization
|
||||
@organization.update(organization_rejected_at: Time.now)
|
||||
redirect_to action: :index
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_organizations
|
||||
@organizations = User.organizations.order(:organization_name, :email)
|
||||
end
|
||||
|
||||
end
|
||||
31
app/views/moderation/organizations/index.html.erb
Normal file
31
app/views/moderation/organizations/index.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<h1><%= t('moderation.organizations.index.title') %></h1>
|
||||
|
||||
<table>
|
||||
<% @organizations.each do |organization| %>
|
||||
<tr>
|
||||
<td><%= organization.organization_name %></td>
|
||||
<td><%= organization.email %></td>
|
||||
<td><%= organization.phone_number %></td>
|
||||
<% if organization.verified_organization? %>
|
||||
<td><%= t('moderation.organizations.index.verified') %></td>
|
||||
<% end %>
|
||||
<% if can? :verify_organization, organization %>
|
||||
<td><%= link_to t('moderation.organizations.index.verify'),
|
||||
verify_organization_moderation_organization_path(organization),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if organization.rejected_organization? %>
|
||||
<td><%= t('moderation.organizations.index.rejected') %></td>
|
||||
<% end %>
|
||||
<% if can? :reject_organization, organization %>
|
||||
<td><%= link_to t('moderation.organizations.index.reject'),
|
||||
reject_organization_moderation_organization_path(organization),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
@@ -2,4 +2,11 @@ en:
|
||||
moderation:
|
||||
dashboard:
|
||||
index:
|
||||
title: Moderation
|
||||
title: Moderation
|
||||
organizations:
|
||||
index:
|
||||
title: Organizations
|
||||
verify: Verify
|
||||
reject: Reject
|
||||
verified: Verified
|
||||
rejected: Rejected
|
||||
|
||||
@@ -2,4 +2,12 @@ es:
|
||||
moderation:
|
||||
dashboard:
|
||||
index:
|
||||
title: Moderación
|
||||
title: Moderación
|
||||
organizations:
|
||||
index:
|
||||
title: Organizaciones
|
||||
verify: Verificar
|
||||
reject: Rechazar
|
||||
verified: Verificado
|
||||
rejected: Rechazado
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :moderation do
|
||||
root to: "dashboard#index"
|
||||
resources :organizations, only: :index do
|
||||
member do
|
||||
put :verify_organization
|
||||
put :reject_organization
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Example of regular route:
|
||||
|
||||
57
spec/features/moderation/organizations_spec.rb
Normal file
57
spec/features/moderation/organizations_spec.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Moderations::Organizations' do
|
||||
|
||||
|
||||
background do
|
||||
moderator = create(:user)
|
||||
create(:moderator, user: moderator)
|
||||
|
||||
login_as(moderator)
|
||||
end
|
||||
|
||||
scenario "pending organizations have links to verify and reject" do
|
||||
organization = create(:organization)
|
||||
|
||||
visit moderation_organizations_path
|
||||
expect(page).to have_selector(:link_or_button, 'Verify')
|
||||
expect(page).to have_selector(:link_or_button, 'Reject')
|
||||
|
||||
click_on 'Verify'
|
||||
expect(current_path).to eq(moderation_organizations_path)
|
||||
expect(page).to have_content ('Verified')
|
||||
|
||||
expect(organization.reload.verified_organization?).to eq(true)
|
||||
end
|
||||
|
||||
scenario "verified organizations have link to reject" do
|
||||
organization = create(:organization, organization_verified_at: Time.now)
|
||||
|
||||
visit moderation_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')
|
||||
|
||||
click_on 'Reject'
|
||||
expect(current_path).to eq(moderation_organizations_path)
|
||||
expect(page).to have_content ('Rejected')
|
||||
|
||||
expect(organization.reload.rejected_organization?).to eq(true)
|
||||
end
|
||||
|
||||
scenario "rejected organizations have link to verify" do
|
||||
organization = create(:organization, organization_rejected_at: Time.now)
|
||||
|
||||
visit moderation_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')
|
||||
|
||||
click_on 'Verify'
|
||||
expect(current_path).to eq(moderation_organizations_path)
|
||||
expect(page).to have_content ('Verified')
|
||||
|
||||
expect(organization.reload.verified_organization?).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user