5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-27 02:36:21 +00:00

Merge branch 'production.panel.sutty.nl' of 0xacab.org:sutty/sutty into production.panel.sutty.nl

This commit is contained in:
f 2024-03-25 15:35:01 -03:00
commit d2fa05c573
No known key found for this signature in database
9 changed files with 72 additions and 35 deletions

View file

@ -79,6 +79,7 @@ gem 'webpacker'
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git' gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
gem 'kaminari' gem 'kaminari'
gem 'device_detector' gem 'device_detector'
gem 'htmlbeautifier'
gem 'rubanok' gem 'rubanok'
gem 'after_commit_everywhere', '~> 1.0' gem 'after_commit_everywhere', '~> 1.0'

View file

@ -270,6 +270,7 @@ GEM
hiredis (0.6.3-x86_64-linux-musl) hiredis (0.6.3-x86_64-linux-musl)
hiredis-client (0.14.1-x86_64-linux-musl) hiredis-client (0.14.1-x86_64-linux-musl)
redis-client (= 0.14.1) redis-client (= 0.14.1)
htmlbeautifier (1.4.2)
http_parser.rb (0.8.0-x86_64-linux-musl) http_parser.rb (0.8.0-x86_64-linux-musl)
httparty (0.21.0) httparty (0.21.0)
mini_mime (>= 1.0.0) mini_mime (>= 1.0.0)
@ -659,6 +660,7 @@ DEPENDENCIES
hamlit-rails hamlit-rails
hiredis hiredis
hiredis-client hiredis-client
htmlbeautifier
httparty httparty
icalendar icalendar
image_processing image_processing

View file

@ -49,7 +49,9 @@ module Api
# #
# @param initial_state [Symbol] # @param initial_state [Symbol]
def process!(initial_state) 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 end
end end

View file

@ -3,15 +3,16 @@
class ActivityPub class ActivityPub
# Procesar las actividades a medida que llegan # Procesar las actividades a medida que llegan
class ProcessJob < ApplicationJob class ProcessJob < ApplicationJob
attr_reader :body attr_reader :body, :initial_state
# Procesa la actividad en segundo plano # Procesa la actividad en segundo plano
# #
# @param :body [String] # @param :body [String]
# @param :initial_state [Symbol,String] # @param :initial_state [Symbol,String]
def perform(site:, body:, initial_state: :paused) def perform(site:, body:, initial_state: :paused)
@body = body
@site = site @site = site
@body = body
@initial_state = initial_state
ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.connection_pool.with_connection do
::ActivityPub.transaction do ::ActivityPub.transaction do
@ -25,10 +26,24 @@ class ActivityPub
activity.update_activity_pub_state! activity.update_activity_pub_state!
end end
end end
end
# Al generar una excepción, en lugar de seguir intentando, enviamos # Al generar una excepción, en lugar de seguir intentando, enviamos
# el reporte. # el reporte.
rescue Exception => e def handle_error(error)
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.' }) 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 end
private private

View file

@ -4,6 +4,17 @@
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
include Que::ActiveJob::JobExtensions include Que::ActiveJob::JobExtensions
# Esperar una cantidad random de segundos primos, para que no se
# superpongan tareas
#
# @return [Array<Integer>]
RANDOM_WAIT = [3, 5, 7, 11, 13]
# @return [ActiveSupport::Duration]
def self.random_wait
RANDOM_WAIT.sample.seconds
end
private private
def site def site

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'htmlbeautifier'
# Se encarga del contenido del artículo y quizás otros campos que # Se encarga del contenido del artículo y quizás otros campos que
# requieran texto largo. # requieran texto largo.
class MetadataContent < MetadataTemplate class MetadataContent < MetadataTemplate
@ -91,7 +93,7 @@ class MetadataContent < MetadataTemplate
end end
end end
html.to_s.html_safe HtmlBeautifier.beautify(html.to_s).html_safe
end end
# Limpia estilos en base a una lista de permitidos # Limpia estilos en base a una lista de permitidos

View file

@ -14,6 +14,10 @@ class SitePolicy
true true
end end
def status?
true
end
# Puede ver la versión privada del sitio? # Puede ver la versión privada del sitio?
def private? def private?
edit? && site.deploys.find_by_type('DeployPrivate') edit? && site.deploys.find_by_type('DeployPrivate')

View file

@ -36,8 +36,7 @@ class SiteUsuariePolicy
end end
def accept_invitation? def accept_invitation?
su = site_usuarie !!site_usuarie.usuarie.rol_for_site(site_usuarie.site)&.temporal
(usuarie? || invitade?) && su.usuarie.rol_for_site(su.site).temporal
end end
def reject_invitation? def reject_invitation?

View file

@ -24,6 +24,7 @@
= site.title = site.title
%p.lead= site.description %p.lead= site.description
%br %br
.d-flex.flex-row
= link_to t('.visit'), site.url, class: 'btn btn-secondary' = link_to t('.visit'), site.url, class: 'btn btn-secondary'
- if current_usuarie.rol_for_site(site).temporal? - if current_usuarie.rol_for_site(site).temporal?
= render 'components/btn_base', = render 'components/btn_base',