From 15800e1096f01707def8a9c845407b38a9e8d545 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 28 Feb 2024 15:47:40 -0300 Subject: [PATCH] BREAKING CHANGE: renombrar instancias por hostnames --- app/jobs/activity_pub/fediblock_fetch_job.rb | 6 +++--- app/jobs/activity_pub/fediblock_updated_job.rb | 9 ++++++--- app/models/activity_pub/fediblock.rb | 7 ++++++- app/views/components/_block_list.haml | 2 +- ...0228171335_rename_fediblock_instances_to_hostnames.rb | 9 +++++++++ db/structure.sql | 5 +++-- 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20240228171335_rename_fediblock_instances_to_hostnames.rb diff --git a/app/jobs/activity_pub/fediblock_fetch_job.rb b/app/jobs/activity_pub/fediblock_fetch_job.rb index aa748bc6..3d12f4cd 100644 --- a/app/jobs/activity_pub/fediblock_fetch_job.rb +++ b/app/jobs/activity_pub/fediblock_fetch_job.rb @@ -11,12 +11,12 @@ class ActivityPub ActivityPub::Fediblock.find_each do |fediblock| fediblock.process! - instances_added = fediblock.instances - fediblock.instances_was + hostnames_added = fediblock.hostnames - fediblock.hostnames_was # No hacer nada si no cambió con respecto a la versión anterior - next if instances_added.empty? + next if hostnames_added.empty? - ActivityPub::FediblockUpdatedJob.perform_later(fediblock: fediblock, hostnames: instances_added) + ActivityPub::FediblockUpdatedJob.perform_later(fediblock: fediblock, hostnames: hostnames_added) rescue ActivityPub::Fediblock::FediblockDownloadError => e ExceptionNotifier.notify_exception(e, data: { fediblock: fediblock.title }) end diff --git a/app/jobs/activity_pub/fediblock_updated_job.rb b/app/jobs/activity_pub/fediblock_updated_job.rb index b4a56609..1bb47517 100644 --- a/app/jobs/activity_pub/fediblock_updated_job.rb +++ b/app/jobs/activity_pub/fediblock_updated_job.rb @@ -2,14 +2,17 @@ # Se encarga de mantener sincronizadas las listas de instancias # de los fediblocks con los sitios que las tengan activadas. +# +# También va a asociar las listas con todos los sitios que tengan la +# Social Inbox habilitada. class ActivityPub class FediblockUpdatedJob < ApplicationJob self.priority = 50 # @param :fediblock [ActivityPub::Fediblock] - # @param :instances [Array] + # @param :hostnames [Array] def perform(fediblock:, hostnames:) - instances = ActivityPub::Instance.where(hostname: instances) + instances = ActivityPub::Instance.where(hostname: hostnames) # Todos los sitios con la Social Inbox habilitada Site.where(id: DeploySocialDistributedPress.pluck(:site_id)).find_each do |site| @@ -19,7 +22,7 @@ class ActivityPub # No hace nada con los deshabilitados next unless fediblock_state.enabled? - ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: instances) + ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: hostnames) end end end diff --git a/app/models/activity_pub/fediblock.rb b/app/models/activity_pub/fediblock.rb index 8d024f56..4abcb80f 100644 --- a/app/models/activity_pub/fediblock.rb +++ b/app/models/activity_pub/fediblock.rb @@ -43,6 +43,11 @@ class ActivityPub @client ||= Client.new end + # Todas las instancias de este fediblock + def instances + ActivityPub::Instance.where(hostname: hostnames) + end + # Descarga la lista y crea las instancias con el estado necesario def process! response = client.get(download_url) @@ -53,7 +58,7 @@ class ActivityPub csv = response.parsed_response process_csv! csv - update(instances: csv.map { |r| r[hostname_header] }) + update(hostnames: csv.map { |r| r[hostname_header] }) end end diff --git a/app/views/components/_block_list.haml b/app/views/components/_block_list.haml index 79481363..75825bb0 100644 --- a/app/views/components/_block_list.haml +++ b/app/views/components/_block_list.haml @@ -7,6 +7,6 @@ %dl.mb-0 %dt.d-inline= t('.instances_blocked') - %dd.d-inline.font-weight-normal= blocklist.instances.count + %dd.d-inline.font-weight-normal= blocklist.hostnames.count %p.mb-0.font-weight-normal %a{ href: blocklist.url }= know_more diff --git a/db/migrate/20240228171335_rename_fediblock_instances_to_hostnames.rb b/db/migrate/20240228171335_rename_fediblock_instances_to_hostnames.rb new file mode 100644 index 00000000..bad343f2 --- /dev/null +++ b/db/migrate/20240228171335_rename_fediblock_instances_to_hostnames.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# Cambia el nombre de la columna para que podamos obtener todas las +# instancias de un fediblock +class RenameFediblockInstancesToHostnames < ActiveRecord::Migration[6.1] + def change + rename_column :activity_pub_fediblocks, :instances, :hostnames + end +end diff --git a/db/structure.sql b/db/structure.sql index ac897695..740f5d87 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -514,7 +514,7 @@ CREATE TABLE public.activity_pub_fediblocks ( url character varying NOT NULL, download_url character varying NOT NULL, format character varying NOT NULL, - instances jsonb DEFAULT '[]'::jsonb + hostnames jsonb DEFAULT '[]'::jsonb ); @@ -2615,6 +2615,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240226133022'), ('20240226134335'), ('20240227134845'), -('20240227142019'); +('20240227142019'), +('20240228171335');