Adds user admin capabilities and missing i18n entries
This commit is contained in:
@@ -19,6 +19,7 @@ class Admin::DebatesController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_debate
|
def load_debate
|
||||||
@debate = Debate.with_hidden.find(params[:id])
|
@debate = Debate.with_hidden.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,25 +1,42 @@
|
|||||||
class Admin::UsersController < Admin::BaseController
|
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
|
def index
|
||||||
@users = User.only_hidden.page(params[:page])
|
@users = User.only_hidden.send(@filter).page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = User.with_hidden.find(params[:id])
|
@user = User.with_hidden.find(params[:id])
|
||||||
@debates = Debate.where(author_id: @user.id).with_hidden.page(params[:page])
|
@debates = @user.debates.with_hidden.page(params[:page])
|
||||||
@comments = Comment.where(user_id: @user.id).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
|
end
|
||||||
|
|
||||||
def restore
|
def restore
|
||||||
user = User.with_hidden.find(params[:id])
|
@user.restore
|
||||||
if hidden_at = user.hidden_at
|
redirect_to request.query_parameters.merge(action: :index)
|
||||||
debates_ids = Debate.only_hidden.where(author_id: user.id).where("debates.hidden_at > ?", hidden_at).pluck(:id)
|
end
|
||||||
comments_ids = Comment.only_hidden.where(user_id: user.id).where("comments.hidden_at > ?", hidden_at).pluck(:id)
|
|
||||||
|
|
||||||
user.restore
|
private
|
||||||
Debate.restore_all debates_ids
|
|
||||||
Comment.restore_all comments_ids
|
def load_user
|
||||||
|
@user = User.with_hidden.find(params[:id])
|
||||||
end
|
end
|
||||||
redirect_to admin_users_path, notice: t('admin.users.restore.success')
|
|
||||||
|
def set_valid_filters
|
||||||
|
@valid_filters = %w{all with_confirmed_hide}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_filter
|
||||||
|
@filter = params[:filter]
|
||||||
|
@filter = 'all' unless @valid_filters.include?(@filter)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
include ActsAsParanoidAliases
|
|
||||||
|
|
||||||
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
|
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
|
||||||
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
|
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
|
||||||
@@ -10,12 +9,15 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_voter
|
acts_as_voter
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
has_one :administrator
|
has_one :administrator
|
||||||
has_one :moderator
|
has_one :moderator
|
||||||
has_one :organization
|
has_one :organization
|
||||||
has_many :flags
|
has_many :flags
|
||||||
has_many :identities, dependent: :destroy
|
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 :username, presence: true, unless: :organization?
|
||||||
validates :official_level, inclusion: {in: 0..5}
|
validates :official_level, inclusion: {in: 0..5}
|
||||||
@@ -114,4 +116,5 @@ class User < ActiveRecord::Base
|
|||||||
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
|
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
|
||||||
!!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX)
|
!!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
<h2><%= t("admin.users.index.title") %></h2>
|
<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>
|
<h3><%= page_entries_info @users %></h3>
|
||||||
|
|
||||||
<ul class="admin-list">
|
<ul class="admin-list">
|
||||||
@@ -7,8 +20,16 @@
|
|||||||
<li>
|
<li>
|
||||||
<%= link_to user.name, admin_user_path(user) %>
|
<%= link_to user.name, admin_user_path(user) %>
|
||||||
|
|
||||||
<%= link_to t("admin.users.index.restore"), restore_admin_user_path(user),
|
<%= link_to t("admin.actions.restore"),
|
||||||
method: :put, data: { confirm: t('admin.actions.confirm') }, class: "button radius tiny right" %>
|
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>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
<strong><%= t("admin.users.show.hidden_at") %></strong> <%= @user.hidden_at %>
|
<strong><%= t("admin.users.show.hidden_at") %></strong> <%= @user.hidden_at %>
|
||||||
</p>
|
</p>
|
||||||
<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,
|
<%= link_to t("admin.users.show.back"), admin_users_path,
|
||||||
class: "button radius tiny secondary" %>
|
class: "button radius tiny secondary" %>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ en:
|
|||||||
restore: Restore
|
restore: Restore
|
||||||
confirm: 'Are you sure?'
|
confirm: 'Are you sure?'
|
||||||
confirm_hide: Confirm
|
confirm_hide: Confirm
|
||||||
archive: Archive
|
|
||||||
tags:
|
tags:
|
||||||
index:
|
index:
|
||||||
title: 'Debate topics'
|
title: 'Debate topics'
|
||||||
@@ -49,14 +48,10 @@ en:
|
|||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
title: Hidden comments
|
title: Hidden comments
|
||||||
show_debate: Show debate
|
|
||||||
filter: Filter
|
filter: Filter
|
||||||
restore:
|
|
||||||
success: The comment has been restored
|
|
||||||
filters:
|
filters:
|
||||||
all: All
|
all: All
|
||||||
pending: Pending
|
with_confirmed_hide: Confirmed
|
||||||
archived: Archived
|
|
||||||
debates:
|
debates:
|
||||||
index:
|
index:
|
||||||
title: Hidden debates
|
title: Hidden debates
|
||||||
@@ -67,16 +62,16 @@ en:
|
|||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
title: Banned users
|
title: Banned users
|
||||||
restore: Restore user
|
filter: Filter
|
||||||
|
filters:
|
||||||
|
all: All
|
||||||
|
with_confirmed_hide: Confirmed
|
||||||
show:
|
show:
|
||||||
title: "User activity from %{user}"
|
title: "User activity from %{user}"
|
||||||
restore: Restore user
|
|
||||||
back: Back
|
back: Back
|
||||||
email: "Email:"
|
email: "Email:"
|
||||||
registered_at: "Registered at:"
|
registered_at: "Registered at:"
|
||||||
hidden_at: "Hidden at:"
|
hidden_at: "Hidden at:"
|
||||||
restore:
|
|
||||||
success: The user has been restored
|
|
||||||
officials:
|
officials:
|
||||||
level_0: Level 0
|
level_0: Level 0
|
||||||
level_1: Level 1
|
level_1: Level 1
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ es:
|
|||||||
restore: Volver a mostrar
|
restore: Volver a mostrar
|
||||||
confirm: '¿Estás seguro?'
|
confirm: '¿Estás seguro?'
|
||||||
confirm_hide: Confirmar
|
confirm_hide: Confirmar
|
||||||
archive: Archivar
|
|
||||||
tags:
|
tags:
|
||||||
index:
|
index:
|
||||||
title: 'Temas de debate'
|
title: 'Temas de debate'
|
||||||
@@ -49,14 +48,10 @@ es:
|
|||||||
comments:
|
comments:
|
||||||
index:
|
index:
|
||||||
title: Comentarios ocultos
|
title: Comentarios ocultos
|
||||||
show_debate: Ver debate
|
filter: Firar
|
||||||
filter: Filtro
|
|
||||||
restore:
|
|
||||||
success: El comentario ha sido permitido
|
|
||||||
filters:
|
filters:
|
||||||
all: Todos
|
all: Todos
|
||||||
pending: Pendientes
|
with_confirmed_hide: Confirmados
|
||||||
archived: Archivados
|
|
||||||
debates:
|
debates:
|
||||||
index:
|
index:
|
||||||
title: Debates ocultos
|
title: Debates ocultos
|
||||||
@@ -67,16 +62,16 @@ es:
|
|||||||
users:
|
users:
|
||||||
index:
|
index:
|
||||||
title: Usuarios bloqueados
|
title: Usuarios bloqueados
|
||||||
restore: Restaurar usuario
|
filter: Filro
|
||||||
|
filters:
|
||||||
|
all: Todos
|
||||||
|
with_confirmed_hide: Confirmados
|
||||||
show:
|
show:
|
||||||
title: "Actividad del usuario %{user}"
|
title: "Actividad del usuario %{user}"
|
||||||
restore: Restaurar usuario
|
|
||||||
back: Volver
|
back: Volver
|
||||||
email: "Email:"
|
email: "Email:"
|
||||||
registered_at: "Fecha de alta:"
|
registered_at: "Fecha de alta:"
|
||||||
hidden_at: "Bloqueado:"
|
hidden_at: "Bloqueado:"
|
||||||
restore:
|
|
||||||
success: El usuario y sus contenidos han sido restaurados
|
|
||||||
officials:
|
officials:
|
||||||
level_0: Nivel 0
|
level_0: Nivel 0
|
||||||
level_1: Nivel 1
|
level_1: Nivel 1
|
||||||
|
|||||||
@@ -2,60 +2,20 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Admin users' do
|
feature 'Admin users' do
|
||||||
|
|
||||||
scenario 'Restore hidden user' do
|
background do
|
||||||
citizen = create(:user)
|
|
||||||
admin = create(:administrator)
|
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)
|
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
|
end
|
||||||
|
|
||||||
scenario 'Show user activity' do
|
scenario 'Show user activity' do
|
||||||
citizen = create(:user)
|
user = create(:user, :hidden)
|
||||||
admin = create(:administrator)
|
|
||||||
create(:moderator, user: admin.user)
|
|
||||||
|
|
||||||
debate1 = create(:debate, :hidden, author: citizen)
|
debate1 = create(:debate, :hidden, author: user)
|
||||||
debate2 = create(:debate, author: citizen)
|
debate2 = create(:debate, author: user)
|
||||||
comment1 = create(:comment, :hidden, user: citizen, commentable: debate2, body: "You have the manners of a beggar")
|
comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar")
|
||||||
comment2 = create(:comment, user: citizen, commentable: debate2, body: 'Not Spam')
|
comment2 = create(:comment, user: user, commentable: debate2, body: 'Not Spam')
|
||||||
|
|
||||||
login_as(admin.user)
|
visit admin_user_path(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(debate1.title)
|
||||||
expect(page).to have_content(debate2.title)
|
expect(page).to have_content(debate2.title)
|
||||||
@@ -63,4 +23,66 @@ feature 'Admin users' do
|
|||||||
expect(page).to have_content(comment2.body)
|
expect(page).to have_content(comment2.body)
|
||||||
end
|
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
|
end
|
||||||
Reference in New Issue
Block a user