adds hiding users by moderators
This commit is contained in:
@@ -4,4 +4,5 @@ class Moderation::DebatesController < Moderation::BaseController
|
|||||||
@debate = Debate.find(params[:id])
|
@debate = Debate.find(params[:id])
|
||||||
@debate.hide
|
@debate.hide
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
15
app/controllers/moderation/users_controller.rb
Normal file
15
app/controllers/moderation/users_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class Moderation::UsersController < Moderation::BaseController
|
||||||
|
|
||||||
|
def hide
|
||||||
|
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
|
||||||
|
|
||||||
|
redirect_to debates_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -9,7 +9,7 @@ class Comment < ActiveRecord::Base
|
|||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
|
|
||||||
belongs_to :commentable, polymorphic: true
|
belongs_to :commentable, polymorphic: true
|
||||||
belongs_to :user
|
belongs_to :user, -> { with_deleted }
|
||||||
|
|
||||||
default_scope { includes(:user) }
|
default_scope { includes(:user) }
|
||||||
scope :recent, -> { order(id: :desc) }
|
scope :recent, -> { order(id: :desc) }
|
||||||
@@ -36,6 +36,10 @@ class Comment < ActiveRecord::Base
|
|||||||
votes_for.size
|
votes_for.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_visible?
|
||||||
|
hidden? || user.hidden?
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache
|
# TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache
|
||||||
# Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed
|
# Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed
|
||||||
# and reset counters using
|
# and reset counters using
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Debate < ActiveRecord::Base
|
|||||||
acts_as_taggable
|
acts_as_taggable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|
||||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> {with_deleted}, class_name: 'User', foreign_key: 'author_id'
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
|
|||||||
@@ -2,4 +2,9 @@
|
|||||||
|
|
|
|
||||||
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment),
|
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment),
|
||||||
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
|
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
|
||||||
|
<% unless comment.user.hidden? %>
|
||||||
|
|
|
||||||
|
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(comment.user_id, debate_id: @debate.id),
|
||||||
|
method: :put, data: { confirm: t('admin.actions.confirm') } %>
|
||||||
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||||
|
|
||||||
<% if comment.hidden? %>
|
<% if comment.not_visible? %>
|
||||||
<%= t("debates.comment.deleted") %>
|
<%= t("debates.comment.deleted") %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
||||||
<%= avatar_image(comment.user, size: 32, class: 'left') %>
|
<%= avatar_image(comment.user, size: 32, class: 'left') %>
|
||||||
<!-- if comment.user.hidden?
|
<% if comment.user.hidden? %>
|
||||||
<i class="icon-deleted user-deleted"></i>
|
<i class="icon-deleted user-deleted"></i>
|
||||||
end -->
|
<% end %>
|
||||||
|
|
||||||
<div class="comment-body">
|
<div class="comment-body">
|
||||||
<div class="comment-info">
|
<div class="comment-info">
|
||||||
|
|
||||||
<!-- if comment.user.hidden?
|
<% if comment.user.hidden? %>
|
||||||
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
|
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
|
||||||
else -->
|
<% else %>
|
||||||
<span class="user-name"><%= comment.user.name %></span>
|
<span class="user-name"><%= comment.user.name %></span>
|
||||||
<% if comment.user.official? %>
|
<% if comment.user.official? %>
|
||||||
•
|
•
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<%= comment.user.official_position %>
|
<%= comment.user.official_position %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<!-- end -->
|
<% end %>
|
||||||
<% if comment.user.verified_organization? %>
|
<% if comment.user.verified_organization? %>
|
||||||
•
|
•
|
||||||
<span class="label round is-association">
|
<span class="label round is-association">
|
||||||
|
|||||||
@@ -1,2 +1,8 @@
|
|||||||
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_debate_path(debate),
|
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_debate_path(debate),
|
||||||
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
|
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
|
||||||
|
|
||||||
|
<% unless debate.author.hidden? %>
|
||||||
|
|
|
||||||
|
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id),
|
||||||
|
method: :put, data: { confirm: t('admin.actions.confirm') } %>
|
||||||
|
<% end %>
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
<div class="debate-info">
|
<div class="debate-info">
|
||||||
<%= avatar_image(@debate.author, size: 32, class: 'author-photo') %>
|
<%= avatar_image(@debate.author, size: 32, class: 'author-photo') %>
|
||||||
<!-- if @debate.author.hidden? %>
|
<% if @debate.author.hidden? %>
|
||||||
<i class="icon-deleted author-deleted"></i>
|
<i class="icon-deleted author-deleted"></i>
|
||||||
<span class="author">
|
<span class="author">
|
||||||
<%= t("debates.show.author_deleted") %>
|
<%= t("debates.show.author_deleted") %>
|
||||||
</span>
|
</span>
|
||||||
else -->
|
<% else %>
|
||||||
<span class="author">
|
<span class="author">
|
||||||
<%= @debate.author.name %>
|
<%= @debate.author.name %>
|
||||||
</span>
|
</span>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<%= @debate.author.official_position %>
|
<%= @debate.author.official_position %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<!-- end -->
|
<% end %>
|
||||||
<% if @debate.author.verified_organization? %>
|
<% if @debate.author.verified_organization? %>
|
||||||
•
|
•
|
||||||
<span class="label round is-association">
|
<span class="label round is-association">
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ en:
|
|||||||
rejected: Rejected
|
rejected: Rejected
|
||||||
actions:
|
actions:
|
||||||
hide: Hide
|
hide: Hide
|
||||||
|
hide_author: Ban author
|
||||||
restore: Restore
|
restore: Restore
|
||||||
confirm: 'Are you sure?'
|
confirm: 'Are you sure?'
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ es:
|
|||||||
rejected: Rechazadas
|
rejected: Rechazadas
|
||||||
actions:
|
actions:
|
||||||
hide: Ocultar
|
hide: Ocultar
|
||||||
|
hide_author: Bloquear al autor
|
||||||
restore: Permitir
|
restore: Permitir
|
||||||
confirm: '¿Estás seguro?'
|
confirm: '¿Estás seguro?'
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ Rails.application.routes.draw do
|
|||||||
namespace :moderation do
|
namespace :moderation do
|
||||||
root to: "dashboard#index"
|
root to: "dashboard#index"
|
||||||
|
|
||||||
|
resources :users, only: [] do
|
||||||
|
member { put :hide }
|
||||||
|
end
|
||||||
|
|
||||||
resources :debates, only: [] do
|
resources :debates, only: [] do
|
||||||
member { put :hide }
|
member { put :hide }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,6 +20,16 @@ module ActsAsParanoidAliases
|
|||||||
def only_hidden
|
def only_hidden
|
||||||
only_deleted
|
only_deleted
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide_all(ids)
|
||||||
|
return if ids.blank?
|
||||||
|
where(id: ids).update_all(hidden_at: Time.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
def restore_all(ids)
|
||||||
|
return if ids.blank?
|
||||||
|
only_hidden.where(id: ids).update_all(hidden_at: nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
42
spec/features/moderation/users_spec.rb
Normal file
42
spec/features/moderation/users_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Moderate users' do
|
||||||
|
|
||||||
|
scenario 'Hide', :js do
|
||||||
|
citizen = create(:user)
|
||||||
|
moderator = create(:moderator)
|
||||||
|
|
||||||
|
debate1 = create(:debate, author: citizen)
|
||||||
|
comment1 = create(:comment, user: citizen, commentable: debate1, body: 'SPAM')
|
||||||
|
debate2 = create(:debate, author: citizen)
|
||||||
|
comment2 = create(:comment, user: citizen, commentable: debate2, body: 'Hello')
|
||||||
|
|
||||||
|
login_as(moderator.user)
|
||||||
|
|
||||||
|
visit debates_path
|
||||||
|
|
||||||
|
expect(page).to have_content(debate1.title)
|
||||||
|
expect(page).to have_content(debate2.title)
|
||||||
|
|
||||||
|
visit debate_path(debate1)
|
||||||
|
|
||||||
|
within("#debate_#{debate1.id}") do
|
||||||
|
click_link 'Ban author'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(current_path).to eq(debates_path)
|
||||||
|
expect(page).to_not have_content(debate1.title)
|
||||||
|
expect(page).to_not have_content(debate2.title)
|
||||||
|
|
||||||
|
click_link("Logout")
|
||||||
|
|
||||||
|
click_link 'Log in'
|
||||||
|
fill_in 'user_email', with: citizen.email
|
||||||
|
fill_in 'user_password', with: citizen.password
|
||||||
|
click_button 'Log in'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Invalid email or password'
|
||||||
|
expect(current_path).to eq(new_user_session_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user