mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 16:51: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 :activity_pubs
|
||||||
has_many :instance_moderations
|
has_many :instance_moderations
|
||||||
has_many :fediblock_states
|
has_many :fediblock_states
|
||||||
|
has_many :instances, through: :instance_moderations
|
||||||
|
|
||||||
before_save :generate_private_key_pem!, unless: :private_key_pem?
|
before_save :generate_private_key_pem!, unless: :private_key_pem?
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
-# Componente Listas de bloqueo de Instancias
|
-# Componente Listas de bloqueo de Instancias
|
||||||
|
- know_more = t('.know_more')
|
||||||
.card.mt-3.mb-3
|
.card.mt-3.mb-3
|
||||||
.card-body
|
.card-body
|
||||||
.d-flex.flex-row
|
= render 'components/checkbox', id: state.id, name: 'fediblock_states_ids[]', value: state.id, checked: state.enabled? do
|
||||||
= render 'components/checkbox', id: state.id, checked: state.enabled? do
|
%span.h4.mb-0= blocklist.title
|
||||||
%span.h4= blocklist.title
|
|
||||||
%p.mb-0
|
%dl.mb-0
|
||||||
%a{ href: blocklist.url }= t('.more')
|
%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
|
.form-group
|
||||||
= label_tag "custom_blocklist", t('moderation_queue.instances.custom_block')
|
= label_tag 'custom_blocklist', t('moderation_queue.instances.custom_block')
|
||||||
= text_area_tag "custom_blocklist", nil, class: 'form-control'
|
= text_area_tag 'custom_blocklist', nil, class: 'form-control'
|
||||||
%button.btn.btn-secondary.mt-3{ type: 'submit' }= t('moderation_queue.instances.submit')
|
|
||||||
|
|
||||||
|
|
|
@ -19,5 +19,10 @@
|
||||||
%div
|
%div
|
||||||
%h3.mt-5= t('moderation_queue.instances.title')
|
%h3.mt-5= t('moderation_queue.instances.title')
|
||||||
%lead= t('moderation_queue.instances.description')
|
%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 'components/block_lists', blocklists: fediblock_states
|
||||||
= render 'moderation_queue/block_instances_textarea'
|
= 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
|
pm: pm
|
||||||
format: '%-I:%M %p'
|
format: '%-I:%M %p'
|
||||||
components:
|
components:
|
||||||
|
block_list:
|
||||||
|
know_more: Know more
|
||||||
instances_filters:
|
instances_filters:
|
||||||
text_show: Show
|
text_show: Show
|
||||||
text_checked: With selected
|
text_checked: With selected
|
||||||
|
|
|
@ -50,6 +50,8 @@ es:
|
||||||
pm: pm
|
pm: pm
|
||||||
format: '%-H:%M'
|
format: '%-H:%M'
|
||||||
components:
|
components:
|
||||||
|
block_list:
|
||||||
|
know_more: Saber más (en inglés)
|
||||||
instances_filters:
|
instances_filters:
|
||||||
text_show: Ver
|
text_show: Ver
|
||||||
text_checked: Con los marcados
|
text_checked: Con los marcados
|
||||||
|
|
|
@ -69,6 +69,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
patch :instance_moderations_action_on_several, to: 'instance_moderations#action_on_several'
|
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
|
# Gestionar artículos según idioma
|
||||||
nested do
|
nested do
|
||||||
|
|
Loading…
Reference in a new issue