diff --git a/Gemfile.lock b/Gemfile.lock
index deed6bc4f..db469b072 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -377,6 +377,3 @@ DEPENDENCIES
uglifier (>= 1.3.0)
unicorn
web-console (~> 2.0)
-
-BUNDLED WITH
- 1.10.6
diff --git a/app/controllers/admin/moderators_controller.rb b/app/controllers/admin/moderators_controller.rb
new file mode 100644
index 000000000..350b4949c
--- /dev/null
+++ b/app/controllers/admin/moderators_controller.rb
@@ -0,0 +1,18 @@
+class Admin::ModeratorsController < Admin::BaseController
+ def index
+ @moderators = User.joins(:moderator).page(params[:page])
+ end
+ def search
+ @email = params[:email]
+ @user = User.find_by(email: @email)
+
+ respond_to do |format|
+ format.js
+ end
+ end
+ def toggle
+ @user = User.find(params[:id])
+ @user.toggle_moderator
+ redirect_to admin_moderators_path
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 544142c2f..179686725 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -67,4 +67,8 @@ class User < ActiveRecord::Base
e.present? ? where(email: e) : none
end
+ def toggle_moderator
+ moderator? ? self.moderator.destroy : create_moderator
+ end
+
end
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index a76ecfe0f..80744f635 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -46,7 +46,14 @@
<% end %>
-
>
+ >
+ <%= link_to admin_moderators_path do %>
+
+ <%= t('admin.menu.moderators') %>
+ <% end %>
+
+
+ >
<%= link_to admin_settings_path do %>
<%= t("admin.menu.settings") %>
diff --git a/app/views/admin/moderators/_moderator.html.erb b/app/views/admin/moderators/_moderator.html.erb
new file mode 100644
index 000000000..de351c160
--- /dev/null
+++ b/app/views/admin/moderators/_moderator.html.erb
@@ -0,0 +1,18 @@
+<% if moderator %>
+ <%= moderator.name %>
+ •
+ <%= moderator.email %>
+ <% if moderator.moderator? %>
+ <%= link_to t('admin.moderators.moderator.delete'),
+ toggle_admin_moderator_path(moderator),
+ method: :post,
+ class: "button tiny radius alert right" %>
+ <% else %>
+ <%= link_to t('admin.moderators.moderator.add'),
+ toggle_admin_moderator_path(moderator),
+ method: :post,
+ class: "button tiny radius success right" %>
+ <% end %>
+<% else%>
+ <%= t('admin.moderators.search.user_not_found') %>
+<% end %>
diff --git a/app/views/admin/moderators/index.html.erb b/app/views/admin/moderators/index.html.erb
new file mode 100644
index 000000000..8a1f8e40d
--- /dev/null
+++ b/app/views/admin/moderators/index.html.erb
@@ -0,0 +1,25 @@
+<%= t("admin.moderators.index.title") %>
+
+
+ <%= form_tag search_admin_moderators_path, method: :get, remote: true do %>
+
+ <%= text_field_tag :email, '', placeholder: t('admin.moderators.search.email_placeholder') %>
+
+
+ <%= submit_tag t('admin.moderators.search.search'), class: 'button radius' %>
+
+ <% end %>
+
+
+
+
+<%= page_entries_info @moderators %>
+
+ <% @moderators.each do |moderator| %>
+ -
+ <%= render 'moderator', moderator: moderator %>
+
+ <% end %>
+
+
+<%= paginate @moderators %>
diff --git a/app/views/admin/moderators/search.js.erb b/app/views/admin/moderators/search.js.erb
new file mode 100644
index 000000000..30d9f8a5d
--- /dev/null
+++ b/app/views/admin/moderators/search.js.erb
@@ -0,0 +1 @@
+$("#search-result").html("<%= j render 'moderator', moderator: @user %>
");
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 971699c0b..9b6024fa1 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -16,6 +16,7 @@ en:
hidden_users: Hidden users
organizations: Organizations
officials: Officials
+ moderators: Moderators
stats: Statistics
organizations:
index:
@@ -104,3 +105,14 @@ en:
flash:
official_updated: 'Official position saved!'
official_destroyed: 'User is not an official anymore'
+ moderators:
+ index:
+ title: Moderators
+ search:
+ email_placeholder: 'Search user by email'
+ search: Search
+ user_not_found: 'User not found'
+ moderator:
+ delete: Delete
+ add: Add
+
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 3c264447f..cf97eb7dc 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -16,6 +16,7 @@ es:
hidden_users: Usuarios ocultos
organizations: Organizaciones
officials: Cargos públicos
+ moderators: Moderadores
stats: Estadísticas
organizations:
index:
@@ -104,3 +105,13 @@ es:
flash:
official_updated: 'Datos del cargo público guardados'
official_destroyed: 'Datos guardados: el usuario ya no es cargo público'
+ moderators:
+ index:
+ title: Moderadores
+ search:
+ email_placeholder: 'Buscar usuario por email'
+ search: Buscar
+ user_not_found: 'Usuario no encontrado'
+ moderator:
+ delete: Borrar
+ add: Añadir
diff --git a/config/routes.rb b/config/routes.rb
index f224609b9..212ab2808 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -62,6 +62,10 @@ Rails.application.routes.draw do
end
resources :settings, only: [:index, :update]
+ resources :moderators, only: [:index] do
+ member { post :toggle }
+ collection { get :search }
+ end
end
namespace :moderation do
diff --git a/spec/features/admin/moderators_spec.rb b/spec/features/admin/moderators_spec.rb
new file mode 100644
index 000000000..c94373e93
--- /dev/null
+++ b/spec/features/admin/moderators_spec.rb
@@ -0,0 +1,36 @@
+require 'rails_helper'
+
+feature 'Admin moderators' do
+ background do
+ @user = create(:user, first_name: 'Jose Luis', last_name: 'Balbin' )
+ @moderator = create(:moderator)
+ @admin = create(:administrator)
+ login_as(@admin.user)
+ end
+
+ scenario 'Index' do
+ visit admin_moderators_path
+ expect(page).to have_content @moderator.name
+ expect(page).to have_content @moderator.email
+ expect(page).to_not have_content @user.name
+ end
+
+ scenario 'Create Moderator', :js do
+ visit admin_moderators_path
+ fill_in 'email', with: @user.email
+ click_button 'Search'
+
+ expect(page).to have_content @user.name
+ click_link 'Add'
+
+ expect(page).to have_content @user.name
+ end
+
+ scenario 'Delete Moderator' do
+ visit admin_moderators_path
+ click_link 'Delete'
+
+ expect(page).to_not have_content @moderator.name
+ end
+end
+