adds hiding users by moderators

This commit is contained in:
Juanjo Bazán
2015-08-20 13:04:31 +02:00
parent 259aa29de7
commit b340d7741a
13 changed files with 101 additions and 12 deletions

View File

@@ -4,4 +4,5 @@ class Moderation::DebatesController < Moderation::BaseController
@debate = Debate.find(params[:id])
@debate.hide
end
end

View 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

View File

@@ -9,7 +9,7 @@ class Comment < ActiveRecord::Base
validates :user, presence: true
belongs_to :commentable, polymorphic: true
belongs_to :user
belongs_to :user, -> { with_deleted }
default_scope { includes(:user) }
scope :recent, -> { order(id: :desc) }
@@ -36,6 +36,10 @@ class Comment < ActiveRecord::Base
votes_for.size
end
def not_visible?
hidden? || user.hidden?
end
# 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
# and reset counters using

View File

@@ -11,7 +11,7 @@ class Debate < ActiveRecord::Base
acts_as_taggable
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 :description, presence: true

View File

@@ -1,5 +1,10 @@
<span id="moderator-comment-actions">
&nbsp;|&nbsp;
<%= 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? %>
&nbsp;|&nbsp;
<%= 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>

View File

@@ -1,21 +1,21 @@
<div class="row">
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
<% if comment.hidden? %>
<% if comment.not_visible? %>
<%= t("debates.comment.deleted") %>
<% else %>
<%= avatar_image(comment.user, size: 32, class: 'left') %>
<!-- if comment.user.hidden?
<% if comment.user.hidden? %>
<i class="icon-deleted user-deleted"></i>
end -->
<% end %>
<div class="comment-body">
<div class="comment-info">
<!-- if comment.user.hidden?
<% if comment.user.hidden? %>
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
else -->
<% else %>
<span class="user-name"><%= comment.user.name %></span>
<% if comment.user.official? %>
&nbsp;&bullet;&nbsp;
@@ -23,7 +23,7 @@
<%= comment.user.official_position %>
</span>
<% end %>
<!-- end -->
<% end %>
<% if comment.user.verified_organization? %>
&nbsp;&bullet;&nbsp;
<span class="label round is-association">

View File

@@ -1,2 +1,8 @@
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_debate_path(debate),
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
<% unless debate.author.hidden? %>
&nbsp;|&nbsp;
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(debate.author_id),
method: :put, data: { confirm: t('admin.actions.confirm') } %>
<% end %>

View File

@@ -14,12 +14,12 @@
<div class="debate-info">
<%= avatar_image(@debate.author, size: 32, class: 'author-photo') %>
<!-- if @debate.author.hidden? %>
<% if @debate.author.hidden? %>
<i class="icon-deleted author-deleted"></i>
<span class="author">
<%= t("debates.show.author_deleted") %>
</span>
else -->
<% else %>
<span class="author">
<%= @debate.author.name %>
</span>
@@ -29,7 +29,7 @@
<%= @debate.author.official_position %>
</span>
<% end %>
<!-- end -->
<% end %>
<% if @debate.author.verified_organization? %>
&nbsp;&bullet;&nbsp;
<span class="label round is-association">