From 95231511b78243dede6c4cab52ab6116fb145a54 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 22 Mar 2024 18:54:18 -0300 Subject: [PATCH 1/7] fix: poder ver el estado --- app/policies/site_policy.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/policies/site_policy.rb b/app/policies/site_policy.rb index 2ca96256..d5465d6b 100644 --- a/app/policies/site_policy.rb +++ b/app/policies/site_policy.rb @@ -14,6 +14,10 @@ class SitePolicy true end + def status? + true + end + # Puede ver la versión privada del sitio? def private? edit? && site.deploys.find_by_type('DeployPrivate') From 1128f0495436777e95af4fcccbafde34ea4845db Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 12:42:15 -0300 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20mostrar=20los=20botones=20de=20invit?= =?UTF-8?q?aci=C3=B3n=20en=20una=20sola=20l=C3=ADnea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/sites/index.haml | 53 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/app/views/sites/index.haml b/app/views/sites/index.haml index ed87180a..f771be3b 100644 --- a/app/views/sites/index.haml +++ b/app/views/sites/index.haml @@ -29,29 +29,30 @@ = site.title %p.lead= site.description %br - = link_to t('.visit'), site.url, class: 'btn btn-secondary' - - if rol.temporal - = button_to t('sites.invitations.accept'), - site_usuaries_accept_invitation_path(site), - method: :patch, - title: t('help.sites.invitations.accept'), - class: 'btn btn-secondary' - = button_to t('sites.invitations.reject'), - site_usuaries_reject_invitation_path(site), - method: :patch, - title: t('help.sites.invitations.reject'), - class: 'btn btn-secondary' - - else - - if policy(site).show? - = render 'layouts/btn_with_tooltip', - tooltip: t('help.sites.edit_posts'), - type: 'success', - link: site_path(site), - text: t('sites.posts') - - if policy(SiteUsuarie.new(site, current_usuarie)).index? - = render 'layouts/btn_with_tooltip', - tooltip: t('usuaries.index.help.self'), - text: t('usuaries.index.title'), - type: 'info', - link: site_usuaries_path(site) - = render 'sites/build', site: site + .d-flex.flex-row + = link_to t('.visit'), site.url, class: 'btn btn-secondary' + - if rol.temporal + = button_to t('sites.invitations.accept'), + site_usuaries_accept_invitation_path(site), + method: :patch, + title: t('help.sites.invitations.accept'), + class: 'btn btn-secondary' + = button_to t('sites.invitations.reject'), + site_usuaries_reject_invitation_path(site), + method: :patch, + title: t('help.sites.invitations.reject'), + class: 'btn btn-secondary' + - else + - if policy(site).show? + = render 'layouts/btn_with_tooltip', + tooltip: t('help.sites.edit_posts'), + type: 'success', + link: site_path(site), + text: t('sites.posts') + - if policy(SiteUsuarie.new(site, current_usuarie)).index? + = render 'layouts/btn_with_tooltip', + tooltip: t('usuaries.index.help.self'), + text: t('usuaries.index.title'), + type: 'info', + link: site_usuaries_path(site) + = render 'sites/build', site: site From 316b192d1e2bb5b504d9edfbba43de206c74404f Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 12:42:26 -0300 Subject: [PATCH 3/7] fix: poder aceptar o rechazar invitaciones #15154 --- app/policies/site_usuarie_policy.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/policies/site_usuarie_policy.rb b/app/policies/site_usuarie_policy.rb index f07dc1c9..31e98cfe 100644 --- a/app/policies/site_usuarie_policy.rb +++ b/app/policies/site_usuarie_policy.rb @@ -36,8 +36,7 @@ class SiteUsuariePolicy end def accept_invitation? - su = site_usuarie - (usuarie? || invitade?) && su.usuarie.rol_for_site(su.site).temporal + !!site_usuarie.usuarie.rol_for_site(site_usuarie.site)&.temporal end def reject_invitation? From d7de351e1af36ab1383d2cf0c4e8f040fef6a686 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 13:32:08 -0300 Subject: [PATCH 4/7] fix: espaciar el procesamiento de tareas closes #15621 closes #15622 closes #15623 closes #15729 closes #15730 closes #15731 closes #15735 closes #15736 closes #15824 --- .../api/v1/webhooks/social_inbox_controller.rb | 4 +++- app/jobs/application_job.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index 6ac91a51..9d215812 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -49,7 +49,9 @@ module Api # # @param initial_state [Symbol] def process!(initial_state) - ::ActivityPub::ProcessJob.perform_later(site: site, body: request.raw_post, initial_state: initial_state) + ::ActivityPub::ProcessJob + .set(wait: ApplicationJob.random_wait) + .perform_later(site: site, body: request.raw_post, initial_state: initial_state) end end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 06690c53..1bf20345 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,6 +4,17 @@ class ApplicationJob < ActiveJob::Base include Que::ActiveJob::JobExtensions + # Esperar una cantidad random de segundos primos, para que no se + # superpongan tareas + # + # @return [Array] + RANDOM_WAIT = [3, 5, 7, 11, 13].seconds + + # @return [ActiveSupport::Duration] + def self.random_wait + RANDOM_WAIT.sample + end + private def site From 718b8643562f2f1d3202ed3c0a7ded93a115ceb5 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 13:33:52 -0300 Subject: [PATCH 5/7] fixup! fix: espaciar el procesamiento de tareas --- app/jobs/application_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 1bf20345..dc6d0478 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -7,12 +7,12 @@ class ApplicationJob < ActiveJob::Base # Esperar una cantidad random de segundos primos, para que no se # superpongan tareas # - # @return [Array] - RANDOM_WAIT = [3, 5, 7, 11, 13].seconds + # @return [Array] + RANDOM_WAIT = [3, 5, 7, 11, 13] # @return [ActiveSupport::Duration] def self.random_wait - RANDOM_WAIT.sample + RANDOM_WAIT.sample.seconds end private From 88cc5f9cb0adee2eca01b5b905d69dd6f160fd37 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 14:17:26 -0300 Subject: [PATCH 6/7] fix: reintentar antes de reportar el error #15824 --- app/jobs/activity_pub/process_job.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/jobs/activity_pub/process_job.rb b/app/jobs/activity_pub/process_job.rb index af686dbd..d94c31e2 100644 --- a/app/jobs/activity_pub/process_job.rb +++ b/app/jobs/activity_pub/process_job.rb @@ -3,15 +3,16 @@ class ActivityPub # Procesar las actividades a medida que llegan class ProcessJob < ApplicationJob - attr_reader :body + attr_reader :body, :initial_state # Procesa la actividad en segundo plano # # @param :body [String] # @param :initial_state [Symbol,String] def perform(site:, body:, initial_state: :paused) - @body = body @site = site + @body = body + @initial_state = initial_state ActiveRecord::Base.connection_pool.with_connection do ::ActivityPub.transaction do @@ -25,10 +26,24 @@ class ActivityPub activity.update_activity_pub_state! end end + end + # Al generar una excepción, en lugar de seguir intentando, enviamos # el reporte. - rescue Exception => e - ExceptionNotifier.notify_exception(e, data: { site: site.name, body: body, initial_state: initial_state, activity: original_activity, message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.' }) + def handle_error(error) + case error + when ActiveRecord::RecordInvalid then retry_in(ApplicationJob.random_wait) + else + ExceptionNotifier.notify_exception( + error, + data: { + site: site.name, + body: body, + initial_state: initial_state, + activity: original_activity, + message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.' + }) + end end private From 8384a8a32ad1fadb2fa6c5ec4fe71312cffb9768 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 14:29:05 -0300 Subject: [PATCH 7/7] feat: darle formato al html guardado #14417 --- Gemfile | 1 + Gemfile.lock | 2 ++ app/models/metadata_content.rb | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 466ec079..995cb849 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,7 @@ gem 'webpacker' gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git' gem 'kaminari' gem 'device_detector' +gem 'htmlbeautifier' # database gem 'hairtrigger' diff --git a/Gemfile.lock b/Gemfile.lock index 78563c84..862880b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,7 @@ GEM heapy (0.2.0) thor hiredis (0.6.3-x86_64-linux-musl) + htmlbeautifier (1.4.2) http_parser.rb (0.8.0-x86_64-linux-musl) httparty (0.21.0) mini_mime (>= 1.0.0) @@ -616,6 +617,7 @@ DEPENDENCIES haml-lint hamlit-rails hiredis + htmlbeautifier httparty icalendar image_processing diff --git a/app/models/metadata_content.rb b/app/models/metadata_content.rb index 761518e8..444ee2fe 100644 --- a/app/models/metadata_content.rb +++ b/app/models/metadata_content.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'htmlbeautifier' + # Se encarga del contenido del artículo y quizás otros campos que # requieran texto largo. class MetadataContent < MetadataTemplate @@ -86,7 +88,7 @@ class MetadataContent < MetadataTemplate end end - html.to_s.html_safe + HtmlBeautifier.beautify(html.to_s).html_safe end # Limpia estilos en base a una lista de permitidos