diff --git a/app/controllers/instance_moderations_controller.rb b/app/controllers/instance_moderations_controller.rb index 55f3c51b..67a6be1d 100644 --- a/app/controllers/instance_moderations_controller.rb +++ b/app/controllers/instance_moderations_controller.rb @@ -2,7 +2,7 @@ # Actualiza la relación entre un sitio y una instancia class InstanceModerationsController < ApplicationController - before_action :authorize_policy + before_action :authorize_policy, except: %i[action_on_several] def pause instance_moderation.pause! @@ -22,6 +22,27 @@ class InstanceModerationsController < ApplicationController redirect_to site_moderation_queue_path end + def action_on_several + instance_moderations = site.instance_moderations.where(id: params[:instance_moderation]) + + authorize instance_moderations + + action = params[:instance_moderation_action].to_sym + method = :"#{action}!" + + InstanceModeration.transaction do + instance_moderations.find_each do |instance_moderation| + events = instance_moderation.aasm.events.map(&:name) + + next unless events.include? action + + instance_moderation.public_send(method) + end + end + + redirect_to site_moderation_queue_path + end + private # @return [InstanceModeration] diff --git a/app/policies/instance_moderation_policy.rb b/app/policies/instance_moderation_policy.rb index 6b3157e8..c07455b3 100644 --- a/app/policies/instance_moderation_policy.rb +++ b/app/policies/instance_moderation_policy.rb @@ -13,4 +13,10 @@ InstanceModerationPolicy = Struct.new(:usuarie, :instance_moderation) do def block? pause? end + + # En este paso tenemos varias instancias por moderar pero todas son + # del mismo sitio. + def action_on_several? + instance_moderation.first.site.usuarie? usuarie + end end diff --git a/app/views/components/_checkbox.haml b/app/views/components/_checkbox.haml index 1932df90..596ff074 100644 --- a/app/views/components/_checkbox.haml +++ b/app/views/components/_checkbox.haml @@ -1,4 +1,5 @@ -# Componente Checkbox +- local_assigns[:name] ||= id .custom-control.custom-checkbox - %input.custom-control-input{ type: 'checkbox', id: id, name: id, **local_assigns } + %input.custom-control-input{ type: 'checkbox', id: id, **local_assigns } %label.custom-control-label{ for: id }= yield diff --git a/app/views/components/_dropdown_button.haml b/app/views/components/_dropdown_button.haml new file mode 100644 index 00000000..8b0c4684 --- /dev/null +++ b/app/views/components/_dropdown_button.haml @@ -0,0 +1,4 @@ +-# + @param name [String] + @param value [String] +%button.dropdown-item{type: 'submit', data: { target: 'dropdown.item' }, name: name, value: value }= text diff --git a/app/views/components/_instances_checked_submenu.haml b/app/views/components/_instances_checked_submenu.haml index 9da642a7..c3573ead 100644 --- a/app/views/components/_instances_checked_submenu.haml +++ b/app/views/components/_instances_checked_submenu.haml @@ -1,3 +1,3 @@ -= render 'components/dropdown_item', text: t('.submenu_pause'), path: '/' -= render 'components/dropdown_item', text: t('.submenu_allow'), path: '/' -= render 'components/dropdown_item', text: t('.submenu_block'), path: '/' += render 'components/dropdown_button', text: t('.submenu_pause'), name: 'instance_moderation_action', value: 'pause' += render 'components/dropdown_button', text: t('.submenu_allow'), name: 'instance_moderation_action', value: 'allow' += render 'components/dropdown_button', text: t('.submenu_block'), name: 'instance_moderation_action', value: 'block' diff --git a/app/views/moderation_queue/_instance.haml b/app/views/moderation_queue/_instance.haml index 327ea892..e7f74b7e 100644 --- a/app/views/moderation_queue/_instance.haml +++ b/app/views/moderation_queue/_instance.haml @@ -1,6 +1,6 @@ .row.no-gutters.pt-2 .col-1 - = render 'components/checkbox', id: instance.hostname, data: { target: 'select-all.input' } + = render 'components/checkbox', id: instance.hostname, name: 'instance_moderation[]', value: instance_moderation.id, data: { target: 'select-all.input' } .col-11 %h4 %a{ href: instance.uri }= instance.content['title'] diff --git a/app/views/moderation_queue/_instances.haml b/app/views/moderation_queue/_instances.haml index 1540ae53..129e1d41 100644 --- a/app/views/moderation_queue/_instances.haml +++ b/app/views/moderation_queue/_instances.haml @@ -1,24 +1,26 @@ -.row.no-gutters.pt-2{ data: { controller: 'select-all' } } - .col-1.d-flex.align-items-center - = render 'components/select_all', id: 'instances' - .col-11 - -# Filtros - = render 'components/instances_filters' +%section + %form{ action: site_instance_moderations_action_on_several_path, method: :post } + .row.no-gutters.pt-2{ data: { controller: 'select-all' } } + .col-1.d-flex.align-items-center + = render 'components/select_all', id: 'instances' + .col-11 + -# Filtros + = render 'components/instances_filters' - .col-12 - - if instance_moderations.count.zero? - %h3= t('moderation_queue.nothing') + .col-12 + - if instance_moderations.count.zero? + %h3= t('moderation_queue.nothing') + + - instance_moderations.each do |instance_moderation| + %hr + = render 'moderation_queue/instance', instance_moderation: instance_moderation, instance: instance_moderation.instance + + -# Botones moderación + .d-flex.pb-4 + = render 'components/instances_btn_box', site: site, instance_moderation: instance_moderation - - instance_moderations.each do |instance_moderation| %hr - = render 'moderation_queue/instance', instance: instance_moderation.instance - - -# Botones moderación - .d-flex.pb-4 - = render 'components/instances_btn_box', site: site, instance_moderation: instance_moderation - - %hr - .col-12 + %div %h3.mt-5= t('moderation_queue.instances.title') %lead= t('moderation_queue.instances.description') = render 'components/block_lists', blocklists: @blocklists diff --git a/config/routes.rb b/config/routes.rb index b6250902..d9e2aca7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,8 @@ Rails.application.routes.draw do patch :block, to: 'instance_moderations#block' end + patch :instance_moderations_action_on_several, to: 'instance_moderations#action_on_several' + # Gestionar artículos según idioma nested do scope '/(:locale)', constraint: /[a-z]{2}(-[A-Z]{2})?/ do