Merge pull request #412 from AyuntamientoMadrid/moderation-user-block
Moderation user block
This commit is contained in:
@@ -1,15 +1,28 @@
|
|||||||
class Moderation::UsersController < Moderation::BaseController
|
class Moderation::UsersController < Moderation::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
|
||||||
|
end
|
||||||
|
|
||||||
|
def hide_in_moderation_screen
|
||||||
|
hide_user
|
||||||
|
redirect_to request.query_parameters.merge(action: :index), notice: I18n.t('moderation.users.notice_hide')
|
||||||
|
end
|
||||||
|
|
||||||
def hide
|
def hide
|
||||||
user = User.find(params[:id])
|
hide_user
|
||||||
debates_ids = Debate.where(author_id: user.id).pluck(:id)
|
|
||||||
comments_ids = Comment.where(user_id: user.id).pluck(:id)
|
|
||||||
|
|
||||||
user.hide
|
|
||||||
Debate.hide_all debates_ids
|
|
||||||
Comment.hide_all comments_ids
|
|
||||||
|
|
||||||
redirect_to debates_path
|
redirect_to debates_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def hide_user
|
||||||
|
user = User.find(params[:id])
|
||||||
|
debates_ids = Debate.where(author_id: user.id).pluck(:id)
|
||||||
|
comments_ids = Comment.where(user_id: user.id).pluck(:id)
|
||||||
|
|
||||||
|
user.hide
|
||||||
|
Debate.hide_all debates_ids
|
||||||
|
Comment.hide_all comments_ids
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -17,5 +17,12 @@
|
|||||||
<%= t("moderation.menu.flagged_comments") %>
|
<%= t("moderation.menu.flagged_comments") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "users" %>>
|
||||||
|
<%= link_to moderation_users_path do %>
|
||||||
|
<i class="icon-user"></i>
|
||||||
|
<%= t("moderation.menu.users") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
32
app/views/moderation/users/index.html.erb
Normal file
32
app/views/moderation/users/index.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<h2><%= t("moderation.users.index.title") %></h2>
|
||||||
|
|
||||||
|
<%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= text_field_tag :name_or_email, "", placeholder: t("moderation.users.index.search_placeholder") %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= f.submit t("moderation.users.index.search"), class: "button radius success" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @users.present? %>
|
||||||
|
<h3><%= page_entries_info @users %></h3>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<ul class="admin-list">
|
||||||
|
<% @users.each do |user| %>
|
||||||
|
<li>
|
||||||
|
<%= user.name %>
|
||||||
|
<span class="bullet"> • </span>
|
||||||
|
<% if user.hidden? %>
|
||||||
|
<%= t("moderation.users.index.hidden") %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("moderation.users.index.hide"), hide_in_moderation_screen_moderation_user_path(user, request.query_parameters), method: :put, class: "delete" %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<%= paginate @users %>
|
||||||
@@ -3,6 +3,7 @@ en:
|
|||||||
menu:
|
menu:
|
||||||
flagged_debates: Debates
|
flagged_debates: Debates
|
||||||
flagged_comments: Comments
|
flagged_comments: Comments
|
||||||
|
users: Ban users
|
||||||
dashboard:
|
dashboard:
|
||||||
index:
|
index:
|
||||||
title: Moderation
|
title: Moderation
|
||||||
@@ -40,3 +41,11 @@ en:
|
|||||||
all: All
|
all: All
|
||||||
pending_flag_review: Pending
|
pending_flag_review: Pending
|
||||||
with_ignored_flag: Ignored
|
with_ignored_flag: Ignored
|
||||||
|
users:
|
||||||
|
notice_hide: User banned.
|
||||||
|
index:
|
||||||
|
title: User search and banning
|
||||||
|
search_placeholder: email or username
|
||||||
|
search: Search
|
||||||
|
hide: Ban
|
||||||
|
hidden: Banned
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ es:
|
|||||||
menu:
|
menu:
|
||||||
flagged_debates: Debates
|
flagged_debates: Debates
|
||||||
flagged_comments: Comentarios
|
flagged_comments: Comentarios
|
||||||
|
users: Bloquear usuarios
|
||||||
dashboard:
|
dashboard:
|
||||||
index:
|
index:
|
||||||
title: Moderación
|
title: Moderación
|
||||||
@@ -40,3 +41,11 @@ es:
|
|||||||
all: Todos
|
all: Todos
|
||||||
pending_flag_review: Pendientes
|
pending_flag_review: Pendientes
|
||||||
with_ignored_flag: Ignorados
|
with_ignored_flag: Ignorados
|
||||||
|
users:
|
||||||
|
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
|
||||||
|
index:
|
||||||
|
title: Bloquear usuarios
|
||||||
|
search_placeholder: email o nombre de usuario
|
||||||
|
search: Buscar
|
||||||
|
hide: Bloquear
|
||||||
|
hidden: Bloqueado
|
||||||
|
|||||||
@@ -97,8 +97,11 @@ Rails.application.routes.draw do
|
|||||||
namespace :moderation do
|
namespace :moderation do
|
||||||
root to: "dashboard#index"
|
root to: "dashboard#index"
|
||||||
|
|
||||||
resources :users, only: [] do
|
resources :users, only: :index do
|
||||||
member { put :hide }
|
member do
|
||||||
|
put :hide
|
||||||
|
put :hide_in_moderation_screen
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :debates, only: :index do
|
resources :debates, only: :index do
|
||||||
|
|||||||
@@ -48,4 +48,28 @@ feature 'Moderate users' do
|
|||||||
expect(current_path).to eq(new_user_session_path)
|
expect(current_path).to eq(new_user_session_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Search and ban users' do
|
||||||
|
citizen = create(:user, username: 'Wanda Maximoff')
|
||||||
|
moderator = create(:moderator)
|
||||||
|
|
||||||
|
login_as(moderator.user)
|
||||||
|
|
||||||
|
visit moderation_users_path
|
||||||
|
|
||||||
|
expect(page).not_to have_content citizen.name
|
||||||
|
fill_in 'name_or_email', with: 'Wanda'
|
||||||
|
click_button 'Search'
|
||||||
|
|
||||||
|
within(".admin-list") do
|
||||||
|
expect(page).to have_content citizen.name
|
||||||
|
expect(page).not_to have_content "Banned"
|
||||||
|
click_link 'Ban'
|
||||||
|
end
|
||||||
|
|
||||||
|
within(".admin-list") do
|
||||||
|
expect(page).to have_content citizen.name
|
||||||
|
expect(page).to have_content "Banned"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user