Files
nairobi/app/controllers/moderation/users_controller.rb
Javi Martín 4c8dfb6695 Use just one action to hide users
Other than removing a redundant action, we're fixing two bugs when
blocking an author using the links in the public views:

* We were always redirecting to the debates index, even if we blocked
  the author of a proposal or an investment
* We weren't showing any kind of success message
2021-12-30 15:50:02 +01:00

39 lines
846 B
Ruby

class Moderation::UsersController < Moderation::BaseController
before_action :load_users, only: :index
load_and_authorize_resource
def index
end
def hide
block_user
redirect_with_query_params_to index_path_options, { notice: I18n.t("moderation.users.notice_hide") }
end
private
def load_users
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
end
def block_user
@user.block
Activity.log(current_user, :block, @user)
end
def index_path_options
if request.referer
referer_params = Rails.application.routes.recognize_path(request.referer)
referer_params.except(:id).merge({
controller: "/#{referer_params[:controller]}",
action: :index
})
else
{ action: :index }
end
end
end