From 3f7a94d56c7eb889498ce171c774dad7e7847ebe Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 20 Aug 2022 21:17:08 +0200 Subject: [PATCH] Move actions from `ModerationController` to `Moderation::ReportsController` --- .../moderation/reports_controller.rb | 27 +++++++++++++++++++ app/controllers/moderation_controller.rb | 24 ----------------- 2 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 app/controllers/moderation/reports_controller.rb diff --git a/app/controllers/moderation/reports_controller.rb b/app/controllers/moderation/reports_controller.rb new file mode 100644 index 00000000..87dc2440 --- /dev/null +++ b/app/controllers/moderation/reports_controller.rb @@ -0,0 +1,27 @@ +class Moderation::ReportsController < ApplicationController + before_action :authenticate_user! + + def index + @type = params[:type] + @reports = list_reports(type: @type, last_id: params[:last_id]) + @reports_last_id = @reports.map(&:id).min + @more_data_available = !list_reports(type: @type, last_id: @reports_last_id, size: 1).count.zero? + + respond_to do |format| + format.html + format.js { render layout: false } + end + end + + private + + def list_reports(type:, last_id:, size: nil) + cursor_params = { last_id: last_id, size: size }.compact + + if type == 'all' + Report.cursored_reports(**cursor_params) + else + Report.cursored_reports_of_type(type, **cursor_params) + end + end +end diff --git a/app/controllers/moderation_controller.rb b/app/controllers/moderation_controller.rb index 2e301055..780139d4 100644 --- a/app/controllers/moderation_controller.rb +++ b/app/controllers/moderation_controller.rb @@ -1,32 +1,8 @@ class ModerationController < ApplicationController before_action :authenticate_user! - def index - @type = params[:type] - @reports = list_reports(type: @type, last_id: params[:last_id]) - @reports_last_id = @reports.map(&:id).min - @more_data_available = !list_reports(type: @type, last_id: @reports_last_id, size: 1).count.zero? - - respond_to do |format| - format.html - format.js { render layout: false } - end - end - def toggle_unmask session[:moderation_view] = !session[:moderation_view] redirect_back fallback_location: root_path end - - private - - def list_reports(type:, last_id:, size: nil) - cursor_params = { last_id: last_id, size: size }.compact - - if type == 'all' - Report.cursored_reports(**cursor_params) - else - Report.cursored_reports_of_type(type, **cursor_params) - end - end end