Introduces User#block method
This commit is contained in:
@@ -1,28 +1,26 @@
|
||||
class Moderation::UsersController < Moderation::BaseController
|
||||
|
||||
before_filter :load_users, only: :index
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
def hide_in_moderation_screen
|
||||
hide_user
|
||||
@user.block
|
||||
redirect_to request.query_parameters.merge(action: :index), notice: I18n.t('moderation.users.notice_hide')
|
||||
end
|
||||
|
||||
def hide
|
||||
hide_user
|
||||
@user.block
|
||||
redirect_to debates_path
|
||||
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
|
||||
def load_users
|
||||
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
|
||||
end
|
||||
|
||||
end
|
||||
@@ -117,6 +117,15 @@ class User < ActiveRecord::Base
|
||||
update official_position: nil, official_level: 0
|
||||
end
|
||||
|
||||
def block
|
||||
debates_ids = Debate.where(author_id: id).pluck(:id)
|
||||
comments_ids = Comment.where(user_id: id).pluck(:id)
|
||||
|
||||
self.hide
|
||||
Debate.hide_all debates_ids
|
||||
Comment.hide_all comments_ids
|
||||
end
|
||||
|
||||
def self.search(term)
|
||||
term.present? ? where("email = ? OR username ILIKE ?", term, "%#{term}%") : none
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user