adds managers section to admin
This commit is contained in:
32
app/controllers/admin/managers_controller.rb
Normal file
32
app/controllers/admin/managers_controller.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class Admin::ManagersController < Admin::BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@managers = @managers.page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
@manager = Manager.find_or_initialize_by(user: @user)
|
||||
format.js
|
||||
else
|
||||
format.js { render "user_not_found" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@manager.user_id = params[:user_id]
|
||||
@manager.save
|
||||
|
||||
redirect_to admin_managers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@manager.destroy
|
||||
redirect_to admin_managers_path
|
||||
end
|
||||
end
|
||||
@@ -18,15 +18,15 @@ class Admin::ModeratorsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@moderator.destroy
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
|
||||
def create
|
||||
@moderator.user_id = params[:user_id]
|
||||
@moderator.save
|
||||
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@moderator.destroy
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,7 @@ module Abilities
|
||||
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :create, :index, :summary], ::Valuator
|
||||
can [:search, :create, :index, :destroy], ::Manager
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
|
||||
13
app/views/admin/managers/_manager.html.erb
Normal file
13
app/views/admin/managers/_manager.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<span><%= manager.name %></span>
|
||||
<span class="bullet"> • </span>
|
||||
<span><%= manager.email %></span>
|
||||
<% if manager.persisted? %>
|
||||
<%= link_to t('admin.managers.manager.delete'),
|
||||
admin_manager_path(manager),
|
||||
method: :delete,
|
||||
class: "button small alert float-right"
|
||||
%>
|
||||
<% else %>
|
||||
<%= link_to t('admin.managers.manager.add'),{ controller: "admin/managers", action: :create, user_id: manager.user_id },
|
||||
method: :post, class: "button small success float-right" %>
|
||||
<% end %>
|
||||
24
app/views/admin/managers/index.html.erb
Normal file
24
app/views/admin/managers/index.html.erb
Normal file
@@ -0,0 +1,24 @@
|
||||
<h2><%= t("admin.managers.index.title") %></h2>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<%= form_tag search_admin_managers_path, method: :get, remote: true do %>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :email, '', placeholder: t('admin.managers.search.email_placeholder') %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t('admin.managers.search.search'), class: 'button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="search-result" class="row small"></div>
|
||||
<h3><%= page_entries_info @managers %></h3>
|
||||
<ul id="managers" class="admin-list">
|
||||
<% @managers.each do |manager| %>
|
||||
<li>
|
||||
<%= render 'manager', manager: manager %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @managers %>
|
||||
1
app/views/admin/managers/search.js.erb
Normal file
1
app/views/admin/managers/search.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<div class=\"panel column\"><%= j render 'manager', manager: @manager %></div>");
|
||||
1
app/views/admin/managers/user_not_found.js.erb
Normal file
1
app/views/admin/managers/user_not_found.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-result").html("<div class=\"panel column\"><%= j t('admin.managers.search.user_not_found') %></div>");
|
||||
@@ -47,6 +47,16 @@ en:
|
||||
with_confirmed_hide: Confirmed
|
||||
without_confirmed_hide: Pending
|
||||
title: Hidden debates
|
||||
managers:
|
||||
index:
|
||||
title: Managers
|
||||
manager:
|
||||
add: Add
|
||||
delete: Delete
|
||||
search:
|
||||
email_placeholder: Search user by email
|
||||
search: Search
|
||||
user_not_found: User not found
|
||||
menu:
|
||||
activity: Moderator activity
|
||||
debate_topics: Debate topics
|
||||
@@ -55,6 +65,7 @@ en:
|
||||
hidden_proposals: Hidden proposals
|
||||
hidden_users: Hidden users
|
||||
incomplete_verifications: Incomplete verifications
|
||||
managers: Managers
|
||||
moderators: Moderators
|
||||
valuators: Valuators
|
||||
officials: Officials
|
||||
|
||||
@@ -47,6 +47,16 @@ es:
|
||||
with_confirmed_hide: Confirmados
|
||||
without_confirmed_hide: Pendientes
|
||||
title: Debates ocultos
|
||||
managers:
|
||||
index:
|
||||
title: Gestores
|
||||
manager:
|
||||
add: Añadir como Gestor
|
||||
delete: Borrar
|
||||
search:
|
||||
email_placeholder: Buscar usuario por email
|
||||
search: Buscar
|
||||
user_not_found: Usuario no encontrado
|
||||
menu:
|
||||
activity: Actividad de moderadores
|
||||
debate_topics: Temas de debate
|
||||
@@ -55,6 +65,7 @@ es:
|
||||
hidden_proposals: Propuestas ocultas
|
||||
hidden_users: Usuarios bloqueados
|
||||
incomplete_verifications: Verificaciones incompletas
|
||||
managers: Gestores
|
||||
moderators: Moderadores
|
||||
valuators: Evaluadores
|
||||
officials: Cargos públicos
|
||||
@@ -66,7 +77,7 @@ es:
|
||||
index:
|
||||
title: Moderadores
|
||||
moderator:
|
||||
add: Añadir
|
||||
add: Añadir como Moderador
|
||||
delete: Borrar
|
||||
search:
|
||||
email_placeholder: Buscar usuario por email
|
||||
|
||||
@@ -165,6 +165,10 @@ Rails.application.routes.draw do
|
||||
get :summary, on: :collection
|
||||
end
|
||||
|
||||
resources :managers, only: [:index, :create, :destroy] do
|
||||
get :search, on: :collection
|
||||
end
|
||||
|
||||
resources :verifications, controller: :verifications, only: :index do
|
||||
get :search, on: :collection
|
||||
end
|
||||
|
||||
37
spec/features/admin/managers_spec.rb
Normal file
37
spec/features/admin/managers_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin managers' do
|
||||
background do
|
||||
@admin = create(:administrator)
|
||||
@user = create(:user)
|
||||
@manager = create(:manager)
|
||||
login_as(@admin.user)
|
||||
visit admin_managers_path
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
expect(page).to have_content @manager.name
|
||||
expect(page).to have_content @manager.email
|
||||
expect(page).to_not have_content @user.name
|
||||
end
|
||||
|
||||
scenario 'Create Manager', :js do
|
||||
fill_in 'email', with: @user.email
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content @user.name
|
||||
click_link 'Add'
|
||||
within("#managers") do
|
||||
expect(page).to have_content @user.name
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Delete Manager' do
|
||||
click_link 'Delete'
|
||||
|
||||
within("#managers") do
|
||||
expect(page).to_not have_content @manager.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,6 +36,16 @@ feature 'Admin' do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as a manager is not authorized' do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
visit admin_root_path
|
||||
|
||||
expect(current_path).not_to eq(admin_root_path)
|
||||
expect(current_path).to eq(proposals_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as an administrator is authorized' do
|
||||
login_as(administrator)
|
||||
visit admin_root_path
|
||||
@@ -51,6 +61,7 @@ feature 'Admin' do
|
||||
expect(page).to have_link('Administration')
|
||||
expect(page).to have_link('Moderation')
|
||||
expect(page).to have_link('Valuation')
|
||||
expect(page).to have_link('Management')
|
||||
end
|
||||
|
||||
scenario 'Admin dashboard' do
|
||||
|
||||
@@ -29,6 +29,20 @@ feature 'Moderation' do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as manager is not authorized' do
|
||||
create(:manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to_not have_link("Moderation")
|
||||
visit moderation_root_path
|
||||
|
||||
expect(current_path).not_to eq(moderation_root_path)
|
||||
expect(current_path).to eq(proposals_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as a moderator is authorized' do
|
||||
create(:moderator, user: user)
|
||||
|
||||
|
||||
@@ -28,6 +28,19 @@ feature 'Valuation' do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as manager is not authorized' do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to_not have_link("Valuation")
|
||||
visit valuation_root_path
|
||||
|
||||
expect(current_path).not_to eq(valuation_root_path)
|
||||
expect(current_path).to eq(proposals_path)
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario 'Access as a valuator is authorized' do
|
||||
create(:valuator, user: user)
|
||||
login_as(user)
|
||||
|
||||
Reference in New Issue
Block a user