mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 14:41:41 +00:00
feat: gestionar listas de bloqueo desde el panel
This commit is contained in:
parent
6f66bd43e5
commit
4bc11c7007
9 changed files with 93 additions and 11 deletions
40
app/controllers/fediblock_states_controller.rb
Normal file
40
app/controllers/fediblock_states_controller.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Estado de las listas de bloqueo en cada sitio
|
||||
class FediblockStatesController < ApplicationController
|
||||
# Realiza cambios en las listas de bloqueo
|
||||
def action_on_several
|
||||
if fediblock_states_ids.present?
|
||||
# Encontrar todas y deshabilitar las que no se enviaron
|
||||
site.fediblock_states.all.find_each do |fediblock_state|
|
||||
if fediblock_states_ids.include? fediblock_state.id
|
||||
fediblock_state.enable! if fediblock_state.may_enable?
|
||||
elsif fediblock_state.may_disable?
|
||||
fediblock_state.disable!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Bloquear otras instancias
|
||||
if custom_blocklist.present?
|
||||
ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: custom_blocklist)
|
||||
end
|
||||
|
||||
redirect_to site_moderation_queue_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fediblock_states_ids
|
||||
params[:fediblock_states_ids] || []
|
||||
end
|
||||
|
||||
# La lista de hostnames
|
||||
def custom_blocklist
|
||||
@custom_blocklist ||= fediblocks_states_params[:custom_blocklist].split("\n").map(&:strip).select(&:present?)
|
||||
end
|
||||
|
||||
def fediblocks_states_params
|
||||
@fediblocks_states_params ||= params.permit(:custom_blocklist, fediblock_states_ids: [])
|
||||
end
|
||||
end
|
29
app/jobs/activity_pub/instance_moderation_job.rb
Normal file
29
app/jobs/activity_pub/instance_moderation_job.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub
|
||||
# Bloquea varias instancias de una sola vez
|
||||
class InstanceModerationJob < ApplicationJob
|
||||
# @param :site [Site]
|
||||
# @param :hostnames [Array<String>]
|
||||
def perform(site:, hostnames:)
|
||||
# Crear las instancias que no existan todavía
|
||||
hostnames.each do |hostname|
|
||||
ActivityPub::Instance.find_or_create_by(hostname: hostname)
|
||||
end
|
||||
|
||||
instances = ActivityPub::Instance.where(hostname: hostnames)
|
||||
|
||||
Site.transaction do
|
||||
# Crea todas las moderaciones de instancia con un estado por
|
||||
# defecto si no existen
|
||||
instances.find_each do |instance|
|
||||
# Esto bloquea cada una individualmente en la Social Inbox,
|
||||
# idealmente son pocas instancias las que aparecen.
|
||||
site.instance_moderations.find_or_create_by(instance: instance).tap do |instance_moderation|
|
||||
instance_moderation.block! if instance_moderation.may_block?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ class Site
|
|||
has_many :activity_pubs
|
||||
has_many :instance_moderations
|
||||
has_many :fediblock_states
|
||||
has_many :instances, through: :instance_moderations
|
||||
|
||||
before_save :generate_private_key_pem!, unless: :private_key_pem?
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
-# Componente Listas de bloqueo de Instancias
|
||||
- know_more = t('.know_more')
|
||||
.card.mt-3.mb-3
|
||||
.card-body
|
||||
.d-flex.flex-row
|
||||
= render 'components/checkbox', id: state.id, checked: state.enabled? do
|
||||
%span.h4= blocklist.title
|
||||
%p.mb-0
|
||||
%a{ href: blocklist.url }= t('.more')
|
||||
= render 'components/checkbox', id: state.id, name: 'fediblock_states_ids[]', value: state.id, checked: state.enabled? do
|
||||
%span.h4.mb-0= blocklist.title
|
||||
|
||||
%dl.mb-0
|
||||
%dt.d-inline= t('.instances_blocked')
|
||||
%dd.d-inline.font-weight-normal= blocklist.instances.count
|
||||
%p.mb-0.font-weight-normal
|
||||
%a{ href: blocklist.url }= know_more
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
.form-group
|
||||
= label_tag "custom_blocklist", t('moderation_queue.instances.custom_block')
|
||||
= text_area_tag "custom_blocklist", nil, class: 'form-control'
|
||||
%button.btn.btn-secondary.mt-3{ type: 'submit' }= t('moderation_queue.instances.submit')
|
||||
|
||||
= label_tag 'custom_blocklist', t('moderation_queue.instances.custom_block')
|
||||
= text_area_tag 'custom_blocklist', nil, class: 'form-control'
|
||||
|
|
|
@ -19,5 +19,10 @@
|
|||
%div
|
||||
%h3.mt-5= t('moderation_queue.instances.title')
|
||||
%lead= t('moderation_queue.instances.description')
|
||||
|
||||
= form_tag site_fediblock_states_action_on_several_path, method: :patch do
|
||||
= render 'components/block_lists', blocklists: fediblock_states
|
||||
= render 'moderation_queue/block_instances_textarea'
|
||||
|
||||
.form-group
|
||||
%button.btn.btn-secondary.mt-3{ type: 'submit' }= t('moderation_queue.instances.submit')
|
||||
|
|
|
@ -50,6 +50,8 @@ en:
|
|||
pm: pm
|
||||
format: '%-I:%M %p'
|
||||
components:
|
||||
block_list:
|
||||
know_more: Know more
|
||||
instances_filters:
|
||||
text_show: Show
|
||||
text_checked: With selected
|
||||
|
|
|
@ -50,6 +50,8 @@ es:
|
|||
pm: pm
|
||||
format: '%-H:%M'
|
||||
components:
|
||||
block_list:
|
||||
know_more: Saber más (en inglés)
|
||||
instances_filters:
|
||||
text_show: Ver
|
||||
text_checked: Con los marcados
|
||||
|
|
|
@ -69,6 +69,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
patch :instance_moderations_action_on_several, to: 'instance_moderations#action_on_several'
|
||||
patch :fediblock_states_action_on_several, to: 'fediblock_states#action_on_several'
|
||||
|
||||
# Gestionar artículos según idioma
|
||||
nested do
|
||||
|
|
Loading…
Reference in a new issue