diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
new file mode 100644
index 000000000..9b23b7927
--- /dev/null
+++ b/app/controllers/admin/users_controller.rb
@@ -0,0 +1,25 @@
+class Admin::UsersController < Admin::BaseController
+
+ def index
+ @users = User.only_hidden.page(params[:page])
+ end
+
+ def show
+ @user = User.with_hidden.find(params[:id])
+ @debates = Debate.where(author_id: @user.id).with_hidden.page(params[:page])
+ @comments = Comment.where(user_id: @user.id).with_hidden.page(params[:page])
+ end
+
+ def restore
+ user = User.with_hidden.find(params[:id])
+ if hidden_at = user.hidden_at
+ debates_ids = Debate.only_hidden.where(author_id: user.id).where("debates.hidden_at > ?", hidden_at).pluck(:id)
+ comments_ids = Comment.only_hidden.where(user_id: user.id).where("comments.hidden_at > ?", hidden_at).pluck(:id)
+
+ user.restore
+ Debate.restore_all debates_ids
+ Comment.restore_all comments_ids
+ end
+ redirect_to admin_users_path, notice: t('admin.users.restore.success')
+ end
+end
\ No newline at end of file
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 06cdac5ca..bc2d459e2 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -25,6 +25,13 @@
<% end %>
+
>
+ <%= link_to admin_users_path do %>
+
+ <%= t('admin.menu.hidden_users') %>
+ <% end %>
+
+
>
<%= link_to admin_organizations_path do %>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb
new file mode 100644
index 000000000..5c84468f8
--- /dev/null
+++ b/app/views/admin/users/index.html.erb
@@ -0,0 +1,18 @@
+<%= t("admin.users.index.title") %>
+
+<%= page_entries_info @users %>
+
+
+<% @users.each do |user| %>
+ -
+ <%= link_to user.name, admin_user_path(user) %>
+
+ <%= link_to t("admin.users.index.restore"), restore_admin_user_path(user),
+ method: :put, data: { confirm: t('admin.actions.confirm') }, class: "button radius tiny right" %>
+
+<% end %>
+
+
+<%= paginate @users %>
+
+
diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb
new file mode 100644
index 000000000..375d9110e
--- /dev/null
+++ b/app/views/admin/users/show.html.erb
@@ -0,0 +1,43 @@
+<%= t("admin.users.show.title", user: @user.name) %>
+
+
+ <%= t("admin.users.show.email") %> <%= @user.email %> |
+ <%= t("admin.users.show.registered_at") %> <%= @user.confirmed_at %> |
+ <%= t("admin.users.show.hidden_at") %> <%= @user.hidden_at %>
+
+
+ <%= link_to t("admin.users.show.restore"), restore_admin_user_path(@user),
+ method: :put, data: { confirm: t('admin.actions.confirm') }, class: "button radius tiny" %>
+ <%= link_to t("admin.users.show.back"), admin_users_path,
+ class: "button radius tiny secondary" %>
+
+
+<% if @debates.present? %>
+ <%= page_entries_info @debates %>
+<% end %>
+
+
+<% @debates.each do |debate| %>
+ -
+ <%= link_to debate.title, admin_debate_path(debate) %>
+
+<% end %>
+
+
+<% if @comments.present? %>
+ <%= page_entries_info @comments %>
+<% end %>
+
+
+<% @comments.each do |comment| %>
+
+<% end %>
+
+
+<%= paginate [@debates, @comments].sort_by {|x| x.size}.last %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 0848824aa..151a9fc47 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -13,6 +13,7 @@ en:
debate_topics: Debate topics
hidden_debates: Hidden debates
hidden_comments: Hidden comments
+ hidden_users: Hidden users
organizations: Organizations
officials: Officials
stats: Statistics
@@ -54,6 +55,19 @@ en:
back: Back
restore:
success: The debate has been restored
+ users:
+ index:
+ title: Banned users
+ restore: Restore user
+ show:
+ title: "User activity from %{user}"
+ restore: Restore user
+ back: Back
+ email: "Email:"
+ registered_at: "Registered at:"
+ hidden_at: "Hidden at:"
+ restore:
+ success: The user has been restored
officials:
level_0: Level 0
level_1: Level 1
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index d10999291..fbaed7566 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -13,6 +13,7 @@ es:
debate_topics: Temas de debate
hidden_debates: Debates ocultos
hidden_comments: Comentarios ocultos
+ hidden_users: Usuarios ocultos
organizations: Organizaciones
officials: Cargos públicos
stats: Estadísticas
@@ -54,6 +55,19 @@ es:
back: Volver
restore:
success: El debate ha sido permitido
+ users:
+ index:
+ title: Usuarios bloqueados
+ restore: Restaurar usuario
+ show:
+ title: "Actividad del usuario %{user}"
+ restore: Restaurar usuario
+ back: Volver
+ email: "Email:"
+ registered_at: "Fecha de alta:"
+ hidden_at: "Bloqueado:"
+ restore:
+ success: El usuario y sus contenidos han sido restaurados
officials:
level_0: Nivel 0
level_1: Nivel 1
diff --git a/config/routes.rb b/config/routes.rb
index 120470ef0..f2d39a5ac 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -36,6 +36,10 @@ Rails.application.routes.draw do
end
end
+ resources :users, only: [:index, :show] do
+ member { put :restore }
+ end
+
resources :debates, only: [:index, :show] do
member { put :restore }
end
diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb
new file mode 100644
index 000000000..ed5c80f34
--- /dev/null
+++ b/spec/features/admin/users_spec.rb
@@ -0,0 +1,66 @@
+require 'rails_helper'
+
+feature 'Admin users' do
+
+ scenario 'Restore hidden user' do
+ citizen = create(:user)
+ admin = create(:administrator)
+ create(:moderator, user: admin.user)
+
+ debate_previously_hidden = create(:debate, :hidden, author: citizen)
+ debate = create(:debate, author: citizen)
+ comment_previously_hidden = create(:comment, :hidden, user: citizen, commentable: debate, body: "You have the manners of a beggar")
+ comment = create(:comment, user: citizen, commentable: debate, body: 'Not Spam')
+
+ login_as(admin.user)
+ visit debate_path(debate)
+
+ within("#debate_#{debate.id}") do
+ click_link 'Ban author'
+ end
+
+ visit debates_path
+ expect(page).to_not have_content(debate.title)
+ expect(page).to_not have_content(debate_previously_hidden)
+
+ click_link "Administration"
+ click_link "Hidden users"
+ click_link "Restore user"
+
+ visit debates_path
+ expect(page).to have_content(debate.title)
+ expect(page).to_not have_content(debate_previously_hidden)
+
+ visit debate_path(debate)
+ expect(page).to have_content(comment.body)
+ expect(page).to_not have_content(comment_previously_hidden.body)
+ end
+
+ scenario 'Show user activity' do
+ citizen = create(:user)
+ admin = create(:administrator)
+ create(:moderator, user: admin.user)
+
+ debate1 = create(:debate, :hidden, author: citizen)
+ debate2 = create(:debate, author: citizen)
+ comment1 = create(:comment, :hidden, user: citizen, commentable: debate2, body: "You have the manners of a beggar")
+ comment2 = create(:comment, user: citizen, commentable: debate2, body: 'Not Spam')
+
+ login_as(admin.user)
+ visit debate_path(debate2)
+
+ within("#debate_#{debate2.id}") do
+ click_link 'Ban author'
+ end
+
+ click_link "Administration"
+ click_link "Hidden users"
+ click_link citizen.name
+
+ expect(page).to have_content(debate1.title)
+ expect(page).to have_content(debate2.title)
+ expect(page).to have_content(comment1.body)
+ expect(page).to have_content(comment2.body)
+ end
+
+end
\ No newline at end of file