diff --git a/app/controllers/admin/managers_controller.rb b/app/controllers/admin/managers_controller.rb
new file mode 100644
index 000000000..5023a1380
--- /dev/null
+++ b/app/controllers/admin/managers_controller.rb
@@ -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
diff --git a/app/controllers/admin/moderators_controller.rb b/app/controllers/admin/moderators_controller.rb
index e15e9273f..2566c0c02 100644
--- a/app/controllers/admin/moderators_controller.rb
+++ b/app/controllers/admin/moderators_controller.rb
@@ -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
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index 587b4954b..6b77c130d 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -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
diff --git a/app/views/admin/managers/_manager.html.erb b/app/views/admin/managers/_manager.html.erb
new file mode 100644
index 000000000..24dd1565c
--- /dev/null
+++ b/app/views/admin/managers/_manager.html.erb
@@ -0,0 +1,13 @@
+<%= manager.name %>
+ •
+<%= manager.email %>
+<% 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 %>
diff --git a/app/views/admin/managers/index.html.erb b/app/views/admin/managers/index.html.erb
new file mode 100644
index 000000000..3113907a4
--- /dev/null
+++ b/app/views/admin/managers/index.html.erb
@@ -0,0 +1,24 @@
+
<%= t("admin.managers.index.title") %>
+
+
+ <%= form_tag search_admin_managers_path, method: :get, remote: true do %>
+
+ <%= text_field_tag :email, '', placeholder: t('admin.managers.search.email_placeholder') %>
+
+
+ <%= submit_tag t('admin.managers.search.search'), class: 'button' %>
+
+ <% end %>
+
+
+
+<%= page_entries_info @managers %>
+
+ <% @managers.each do |manager| %>
+ -
+ <%= render 'manager', manager: manager %>
+
+ <% end %>
+
+
+<%= paginate @managers %>
diff --git a/app/views/admin/managers/search.js.erb b/app/views/admin/managers/search.js.erb
new file mode 100644
index 000000000..0f0fd09cd
--- /dev/null
+++ b/app/views/admin/managers/search.js.erb
@@ -0,0 +1 @@
+$("#search-result").html("<%= j render 'manager', manager: @manager %>
");
diff --git a/app/views/admin/managers/user_not_found.js.erb b/app/views/admin/managers/user_not_found.js.erb
new file mode 100644
index 000000000..0116de21d
--- /dev/null
+++ b/app/views/admin/managers/user_not_found.js.erb
@@ -0,0 +1 @@
+$("#search-result").html("<%= j t('admin.managers.search.user_not_found') %>
");
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 15b3870d8..282e72d27 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -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
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 803073b2d..66b419d26 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 1c7af6800..a2035a0b7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/features/admin/managers_spec.rb b/spec/features/admin/managers_spec.rb
new file mode 100644
index 000000000..100781446
--- /dev/null
+++ b/spec/features/admin/managers_spec.rb
@@ -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
+
diff --git a/spec/features/admin_spec.rb b/spec/features/admin_spec.rb
index 87c60355b..1561a60a8 100644
--- a/spec/features/admin_spec.rb
+++ b/spec/features/admin_spec.rb
@@ -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
diff --git a/spec/features/moderation_spec.rb b/spec/features/moderation_spec.rb
index 12eb07358..6607ec48a 100644
--- a/spec/features/moderation_spec.rb
+++ b/spec/features/moderation_spec.rb
@@ -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)
diff --git a/spec/features/valuation_spec.rb b/spec/features/valuation_spec.rb
index 571a4323f..fab16027a 100644
--- a/spec/features/valuation_spec.rb
+++ b/spec/features/valuation_spec.rb
@@ -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)