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