mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 19:56:21 +00:00
feat: hacer una acción con las seleccionadas
This commit is contained in:
parent
761d68604b
commit
9b2efaafac
8 changed files with 60 additions and 24 deletions
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
4
app/views/components/_dropdown_button.haml
Normal file
4
app/views/components/_dropdown_button.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
-#
|
||||
@param name [String]
|
||||
@param value [String]
|
||||
%button.dropdown-item{type: 'submit', data: { target: 'dropdown.item' }, name: name, value: value }= text
|
|
@ -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'
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
%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'
|
||||
|
@ -11,14 +13,14 @@
|
|||
|
||||
- instance_moderations.each do |instance_moderation|
|
||||
%hr
|
||||
= render 'moderation_queue/instance', instance: instance_moderation.instance
|
||||
= 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
|
||||
|
||||
%hr
|
||||
.col-12
|
||||
%div
|
||||
%h3.mt-5= t('moderation_queue.instances.title')
|
||||
%lead= t('moderation_queue.instances.description')
|
||||
= render 'components/block_lists', blocklists: @blocklists
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue