Adds user admin capabilities and missing i18n entries
This commit is contained in:
@@ -19,6 +19,7 @@ class Admin::DebatesController < Admin::BaseController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_debate
|
||||
@debate = Debate.with_hidden.find(params[:id])
|
||||
end
|
||||
|
||||
@@ -1,25 +1,42 @@
|
||||
class Admin::UsersController < Admin::BaseController
|
||||
before_filter :set_valid_filters, only: :index
|
||||
before_filter :parse_filter, only: :index
|
||||
|
||||
before_filter :load_user, only: [:confirm_hide, :restore]
|
||||
|
||||
def index
|
||||
@users = User.only_hidden.page(params[:page])
|
||||
@users = User.only_hidden.send(@filter).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])
|
||||
@debates = @user.debates.with_hidden.page(params[:page])
|
||||
@comments = @user.comments.with_hidden.page(params[:page])
|
||||
end
|
||||
|
||||
def confirm_hide
|
||||
@user.confirm_hide
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
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
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
end
|
||||
|
||||
user.restore
|
||||
Debate.restore_all debates_ids
|
||||
Comment.restore_all comments_ids
|
||||
private
|
||||
|
||||
def load_user
|
||||
@user = User.with_hidden.find(params[:id])
|
||||
end
|
||||
redirect_to admin_users_path, notice: t('admin.users.restore.success')
|
||||
|
||||
def set_valid_filters
|
||||
@valid_filters = %w{all with_confirmed_hide}
|
||||
end
|
||||
|
||||
def parse_filter
|
||||
@filter = params[:filter]
|
||||
@filter = 'all' unless @valid_filters.include?(@filter)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,4 @@
|
||||
class User < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
|
||||
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
|
||||
@@ -10,12 +9,15 @@ class User < ActiveRecord::Base
|
||||
|
||||
acts_as_voter
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
has_one :administrator
|
||||
has_one :moderator
|
||||
has_one :organization
|
||||
has_many :flags
|
||||
has_many :identities, dependent: :destroy
|
||||
has_many :debates, -> { with_hidden }, foreign_key: :author_id
|
||||
has_many :comments, -> { with_hidden }
|
||||
|
||||
validates :username, presence: true, unless: :organization?
|
||||
validates :official_level, inclusion: {in: 0..5}
|
||||
@@ -114,4 +116,5 @@ class User < ActiveRecord::Base
|
||||
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
|
||||
!!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
<h2><%= t("admin.users.index.title") %></h2>
|
||||
|
||||
<dl class="sub-nav">
|
||||
<dt><%= t("admin.users.index.filter") %>:</dt>
|
||||
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @filter == filter %>
|
||||
<dd class="active"><%= t("admin.users.index.filters.#{filter}") %></dd>
|
||||
<% else %>
|
||||
<dd><%= link_to t("admin.users.index.filters.#{filter}"),
|
||||
admin_users_path(filter: filter) %></dd>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</dl>
|
||||
|
||||
<h3><%= page_entries_info @users %></h3>
|
||||
|
||||
<ul class="admin-list">
|
||||
@@ -7,8 +20,16 @@
|
||||
<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" %>
|
||||
<%= link_to t("admin.actions.restore"),
|
||||
restore_admin_user_path(user, request.query_parameters),
|
||||
method: :put,
|
||||
data: { confirm: t("admin.actions.confirm") },
|
||||
class: "button radius tiny success right" %>
|
||||
|
||||
<%= link_to t("admin.actions.confirm_hide"),
|
||||
confirm_hide_admin_user_path(user, request.query_parameters),
|
||||
method: :put,
|
||||
class: "button radius tiny warning right" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
<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>
|
||||
|
||||
@@ -37,7 +37,6 @@ en:
|
||||
restore: Restore
|
||||
confirm: 'Are you sure?'
|
||||
confirm_hide: Confirm
|
||||
archive: Archive
|
||||
tags:
|
||||
index:
|
||||
title: 'Debate topics'
|
||||
@@ -49,14 +48,10 @@ en:
|
||||
comments:
|
||||
index:
|
||||
title: Hidden comments
|
||||
show_debate: Show debate
|
||||
filter: Filter
|
||||
restore:
|
||||
success: The comment has been restored
|
||||
filters:
|
||||
all: All
|
||||
pending: Pending
|
||||
archived: Archived
|
||||
with_confirmed_hide: Confirmed
|
||||
debates:
|
||||
index:
|
||||
title: Hidden debates
|
||||
@@ -67,16 +62,16 @@ en:
|
||||
users:
|
||||
index:
|
||||
title: Banned users
|
||||
restore: Restore user
|
||||
filter: Filter
|
||||
filters:
|
||||
all: All
|
||||
with_confirmed_hide: Confirmed
|
||||
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
|
||||
|
||||
@@ -37,7 +37,6 @@ es:
|
||||
restore: Volver a mostrar
|
||||
confirm: '¿Estás seguro?'
|
||||
confirm_hide: Confirmar
|
||||
archive: Archivar
|
||||
tags:
|
||||
index:
|
||||
title: 'Temas de debate'
|
||||
@@ -49,14 +48,10 @@ es:
|
||||
comments:
|
||||
index:
|
||||
title: Comentarios ocultos
|
||||
show_debate: Ver debate
|
||||
filter: Filtro
|
||||
restore:
|
||||
success: El comentario ha sido permitido
|
||||
filter: Firar
|
||||
filters:
|
||||
all: Todos
|
||||
pending: Pendientes
|
||||
archived: Archivados
|
||||
with_confirmed_hide: Confirmados
|
||||
debates:
|
||||
index:
|
||||
title: Debates ocultos
|
||||
@@ -67,16 +62,16 @@ es:
|
||||
users:
|
||||
index:
|
||||
title: Usuarios bloqueados
|
||||
restore: Restaurar usuario
|
||||
filter: Filro
|
||||
filters:
|
||||
all: Todos
|
||||
with_confirmed_hide: Confirmados
|
||||
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
|
||||
|
||||
@@ -2,60 +2,20 @@ require 'rails_helper'
|
||||
|
||||
feature 'Admin users' do
|
||||
|
||||
scenario 'Restore hidden user' do
|
||||
citizen = create(:user)
|
||||
background do
|
||||
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)
|
||||
user = create(:user, :hidden)
|
||||
|
||||
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')
|
||||
debate1 = create(:debate, :hidden, author: user)
|
||||
debate2 = create(:debate, author: user)
|
||||
comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar")
|
||||
comment2 = create(:comment, user: user, 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
|
||||
visit admin_user_path(user)
|
||||
|
||||
expect(page).to have_content(debate1.title)
|
||||
expect(page).to have_content(debate2.title)
|
||||
@@ -63,4 +23,66 @@ feature 'Admin users' do
|
||||
expect(page).to have_content(comment2.body)
|
||||
end
|
||||
|
||||
scenario 'Restore' do
|
||||
user = create(:user, :hidden)
|
||||
visit admin_users_path
|
||||
|
||||
click_link 'Restore'
|
||||
|
||||
expect(page).to_not have_content(user.username)
|
||||
|
||||
expect(user.reload).to_not be_hidden
|
||||
end
|
||||
|
||||
scenario 'Confirm hide' do
|
||||
user = create(:user, :hidden)
|
||||
visit admin_users_path
|
||||
|
||||
click_link 'Confirm'
|
||||
|
||||
expect(page).to have_content(user.username)
|
||||
expect(page).to have_content('Confirmed')
|
||||
|
||||
expect(user.reload).to be_confirmed_hide
|
||||
end
|
||||
|
||||
scenario "Current filter is properly highlighted" do
|
||||
visit admin_users_path
|
||||
expect(page).to_not have_link('All')
|
||||
expect(page).to have_link('Confirmed')
|
||||
|
||||
visit admin_users_path(filter: 'all')
|
||||
expect(page).to_not have_link('All')
|
||||
expect(page).to have_link('Confirmed')
|
||||
|
||||
visit admin_users_path(filter: 'with_confirmed_hide')
|
||||
expect(page).to have_link('All')
|
||||
expect(page).to_not have_link('Confirmed')
|
||||
end
|
||||
|
||||
scenario "Filtering users" do
|
||||
create(:user, :hidden, username: "Unconfirmed")
|
||||
create(:user, :hidden, :with_confirmed_hide, username: "Confirmed user")
|
||||
|
||||
visit admin_users_path(filter: 'all')
|
||||
expect(page).to have_content('Unconfirmed')
|
||||
expect(page).to have_content('Confirmed user')
|
||||
|
||||
visit admin_users_path(filter: 'with_confirmed_hide')
|
||||
expect(page).to_not have_content('Unconfirmed')
|
||||
expect(page).to have_content('Confirmed user')
|
||||
end
|
||||
|
||||
scenario "Action links remember the pagination setting and the filter" do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:user, :hidden, :with_confirmed_hide) }
|
||||
|
||||
visit admin_users_path(filter: 'with_confirmed_hide', page: 2)
|
||||
|
||||
click_on('Restore', match: :first, exact: true)
|
||||
|
||||
expect(current_url).to include('filter=with_confirmed_hide')
|
||||
expect(current_url).to include('page=2')
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user