From 0da69de6a73543d90c032b09bd04b74be5c8cbef Mon Sep 17 00:00:00 2001 From: f Date: Tue, 5 Mar 2024 16:24:16 -0300 Subject: [PATCH] feat: filtros comunes --- app/controllers/actor_moderations_controller.rb | 3 ++- .../concerns/moderation_filters_concern.rb | 15 +++++++++++++++ app/controllers/moderation_queue_controller.rb | 4 ++-- app/processors/instance_moderation_processor.rb | 4 ++-- app/views/components/_comments_show_submenu.haml | 2 +- app/views/components/_dropdown_item.haml | 2 +- app/views/components/_instances_filters.haml | 2 +- app/views/components/_instances_show_submenu.haml | 7 ++++--- app/views/components/_profiles_show_submenu.haml | 2 +- app/views/moderation_queue/_instances.haml | 2 +- 10 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 app/controllers/concerns/moderation_filters_concern.rb diff --git a/app/controllers/actor_moderations_controller.rb b/app/controllers/actor_moderations_controller.rb index 00874321..6b924677 100644 --- a/app/controllers/actor_moderations_controller.rb +++ b/app/controllers/actor_moderations_controller.rb @@ -3,6 +3,7 @@ # Gestiona la cola de moderación de actores class ActorModerationsController < ApplicationController include ModerationConcern + include ModerationFiltersConcern ActorModeration.events.each do |actor_event| define_method(actor_event) do @@ -20,7 +21,7 @@ class ActorModerationsController < ApplicationController # Ver el perfil remoto def show @remote_profile = actor_moderation.actor.content - @moderation_queue = site.activity_pubs.where(actor_id: actor_moderation.actor_id) + @moderation_queue = rubanok_process(site.activity_pubs.where(actor_id: actor_moderation.actor_id), with: ActivityPubProcessor) end def action_on_several diff --git a/app/controllers/concerns/moderation_filters_concern.rb b/app/controllers/concerns/moderation_filters_concern.rb new file mode 100644 index 00000000..25293a4f --- /dev/null +++ b/app/controllers/concerns/moderation_filters_concern.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module ModerationFiltersConcern + extend ActiveSupport::Concern + + included do + before_action :store_filters_in_session!, only: %i[index show] + + private + + def store_filters_in_session! + session[:moderation_queue_filters] = params.permit(:instance_state, :actor_state, :activity_pub_state) + end + end +end diff --git a/app/controllers/moderation_queue_controller.rb b/app/controllers/moderation_queue_controller.rb index 0df62499..eebd9eae 100644 --- a/app/controllers/moderation_queue_controller.rb +++ b/app/controllers/moderation_queue_controller.rb @@ -2,10 +2,10 @@ # Cola de moderación de ActivityPub class ModerationQueueController < ApplicationController + include ModerationFiltersConcern + # Cola de moderación viendo todo el sitio def index - session[:moderation_queue_filters] = params.permit(:state, :actor_state, :activity_pub_state) - # @todo cambiar el estado por query @activity_pubs = site.activity_pubs @instance_moderations = rubanok_process(site.instance_moderations, with: InstanceModerationProcessor) diff --git a/app/processors/instance_moderation_processor.rb b/app/processors/instance_moderation_processor.rb index 908beaf7..eb9a7c8b 100644 --- a/app/processors/instance_moderation_processor.rb +++ b/app/processors/instance_moderation_processor.rb @@ -6,7 +6,7 @@ class InstanceModerationProcessor < Rubanok::Processor raw.includes(:instance).order('activity_pub_instances.hostname') end - map :state, activate_always: true do |state: 'paused'| - raw.where(aasm_state: state) + map :instance_state, activate_always: true do |instance_state: 'paused'| + raw.where(aasm_state: instance_state) end end diff --git a/app/views/components/_comments_show_submenu.haml b/app/views/components/_comments_show_submenu.haml index eb037975..60c02501 100644 --- a/app/views/components/_comments_show_submenu.haml +++ b/app/views/components/_comments_show_submenu.haml @@ -1,4 +1,4 @@ - ActivityPub.states.each do |state| = render 'components/dropdown_item', text: t(".submenu_#{state}", count: activity_pubs.unscope(where: :aasm_state).public_send(state).count), - path: site_moderation_queue_path(filter_states(activity_pub_state: state)) + path: filter_states(activity_pub_state: state) diff --git a/app/views/components/_dropdown_item.haml b/app/views/components/_dropdown_item.haml index 3f79403d..e5b16950 100644 --- a/app/views/components/_dropdown_item.haml +++ b/app/views/components/_dropdown_item.haml @@ -1,4 +1,4 @@ -# @param :text [String] Contenido del link - @param :path [String] Link + @param :path [String,Hash] Link = link_to text, path, class: 'dropdown-item', data: { target: 'dropdown.item' } diff --git a/app/views/components/_instances_filters.haml b/app/views/components/_instances_filters.haml index 9e8509c4..2c23fd72 100644 --- a/app/views/components/_instances_filters.haml +++ b/app/views/components/_instances_filters.haml @@ -6,4 +6,4 @@ = render 'components/instances_checked_submenu', form_id: form_id, current_state: current_state = render 'components/dropdown', text: t('.text_show') do - = render 'components/instances_show_submenu', site: site + = render 'components/instances_show_submenu', instance_moderations: instance_moderations diff --git a/app/views/components/_instances_show_submenu.haml b/app/views/components/_instances_show_submenu.haml index 811d65c7..c56df547 100644 --- a/app/views/components/_instances_show_submenu.haml +++ b/app/views/components/_instances_show_submenu.haml @@ -1,3 +1,4 @@ -= render 'components/dropdown_item', text: t('.submenu_paused', count: site.instance_moderations.paused.count), path: site_moderation_queue_path(state: 'paused') -= render 'components/dropdown_item', text: t('.submenu_allowed', count: site.instance_moderations.allowed.count), path: site_moderation_queue_path(state: 'allowed') -= render 'components/dropdown_item', text: t('.submenu_blocked', count: site.instance_moderations.blocked.count), path: site_moderation_queue_path(state: 'blocked') +- InstanceModeration.states.each do |state| + = render 'components/dropdown_item', + text: t(".submenu_#{state}", count: instance_moderations.unscope(where: :aasm_state).public_send(state).count), + path: filter_states(instance_state: state) diff --git a/app/views/components/_profiles_show_submenu.haml b/app/views/components/_profiles_show_submenu.haml index 0209ef2f..99694698 100644 --- a/app/views/components/_profiles_show_submenu.haml +++ b/app/views/components/_profiles_show_submenu.haml @@ -1,4 +1,4 @@ - ActorModeration.states.each do |actor_state| = render 'components/dropdown_item', text: t(".submenu_#{actor_state}", count: actor_moderations.unscope(where: :aasm_state).public_send(actor_state).count), - path: site_moderation_queue_path(filter_states(actor_state: actor_state)) + path: filter_states(actor_state: actor_state) diff --git a/app/views/moderation_queue/_instances.haml b/app/views/moderation_queue/_instances.haml index d9db967f..3954ce65 100644 --- a/app/views/moderation_queue/_instances.haml +++ b/app/views/moderation_queue/_instances.haml @@ -7,7 +7,7 @@ = render 'components/select_all', id: 'instances', form_id: form_id .col-11 -# Filtros - = render 'components/instances_filters', site: site, form_id: form_id + = render 'components/instances_filters', instance_moderations: instance_moderations, form_id: form_id .col-12 - if instance_moderations.count.zero?