adds restore user action for administrators
This commit is contained in:
25
app/controllers/admin/users_controller.rb
Normal file
25
app/controllers/admin/users_controller.rb
Normal file
@@ -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
|
||||
@@ -25,6 +25,13 @@
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'users' %>>
|
||||
<%= link_to admin_users_path do %>
|
||||
<i class="icon-user"></i>
|
||||
<%= t('admin.menu.hidden_users') %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'organizations' %>>
|
||||
<%= link_to admin_organizations_path do %>
|
||||
<i class="icon-comment-quotes"></i>
|
||||
|
||||
18
app/views/admin/users/index.html.erb
Normal file
18
app/views/admin/users/index.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<h2><%= t("admin.users.index.title") %></h2>
|
||||
|
||||
<h3><%= page_entries_info @users %></h3>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @users.each do |user| %>
|
||||
<li>
|
||||
<%= 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" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @users %>
|
||||
|
||||
|
||||
43
app/views/admin/users/show.html.erb
Normal file
43
app/views/admin/users/show.html.erb
Normal file
@@ -0,0 +1,43 @@
|
||||
<h2><%= t("admin.users.show.title", user: @user.name) %></h2>
|
||||
|
||||
<p>
|
||||
<strong><%= t("admin.users.show.email") %></strong> <%= @user.email %> |
|
||||
<strong><%= t("admin.users.show.registered_at") %></strong> <%= @user.confirmed_at %> |
|
||||
<strong><%= t("admin.users.show.hidden_at") %></strong> <%= @user.hidden_at %>
|
||||
</p>
|
||||
<p>
|
||||
<%= 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" %>
|
||||
</p>
|
||||
|
||||
<% if @debates.present? %>
|
||||
<h3><%= page_entries_info @debates %></h3>
|
||||
<% end %>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @debates.each do |debate| %>
|
||||
<li>
|
||||
<%= link_to debate.title, admin_debate_path(debate) %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<% if @comments.present? %>
|
||||
<h3><%= page_entries_info @comments %></h3>
|
||||
<% end %>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @comments.each do |comment| %>
|
||||
<li id="<%= dom_id(comment) %>">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-10 column">
|
||||
<%= comment.body %>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate [@debates, @comments].sort_by {|x| x.size}.last %>
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
66
spec/features/admin/users_spec.rb
Normal file
66
spec/features/admin/users_spec.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user