mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 22:06:21 +00:00
Merge branch 'production.panel.sutty.nl' of 0xacab.org:sutty/sutty into production.panel.sutty.nl
This commit is contained in:
commit
d2fa05c573
9 changed files with 72 additions and 35 deletions
1
Gemfile
1
Gemfile
|
@ -79,6 +79,7 @@ gem 'webpacker'
|
|||
gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git'
|
||||
gem 'kaminari'
|
||||
gem 'device_detector'
|
||||
gem 'htmlbeautifier'
|
||||
gem 'rubanok'
|
||||
|
||||
gem 'after_commit_everywhere', '~> 1.0'
|
||||
|
|
|
@ -270,6 +270,7 @@ GEM
|
|||
hiredis (0.6.3-x86_64-linux-musl)
|
||||
hiredis-client (0.14.1-x86_64-linux-musl)
|
||||
redis-client (= 0.14.1)
|
||||
htmlbeautifier (1.4.2)
|
||||
http_parser.rb (0.8.0-x86_64-linux-musl)
|
||||
httparty (0.21.0)
|
||||
mini_mime (>= 1.0.0)
|
||||
|
@ -659,6 +660,7 @@ DEPENDENCIES
|
|||
hamlit-rails
|
||||
hiredis
|
||||
hiredis-client
|
||||
htmlbeautifier
|
||||
httparty
|
||||
icalendar
|
||||
image_processing
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Integer>]
|
||||
RANDOM_WAIT = [3, 5, 7, 11, 13]
|
||||
|
||||
# @return [ActiveSupport::Duration]
|
||||
def self.random_wait
|
||||
RANDOM_WAIT.sample.seconds
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def site
|
||||
|
|
|
@ -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
|
||||
|
@ -91,7 +93,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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -24,30 +24,31 @@
|
|||
= site.title
|
||||
%p.lead= site.description
|
||||
%br
|
||||
= link_to t('.visit'), site.url, class: 'btn btn-secondary'
|
||||
- if current_usuarie.rol_for_site(site).temporal?
|
||||
= render 'components/btn_base',
|
||||
text: t('sites.invitations.accept'),
|
||||
path: site_usuaries_accept_invitation_path(site),
|
||||
title: t('help.sites.invitations.accept'),
|
||||
class: 'btn-secondary'
|
||||
= render 'components/btn_base',
|
||||
text: t('sites.invitations.reject'),
|
||||
path: site_usuaries_reject_invitation_path(site),
|
||||
title: t('help.sites.invitations.reject'),
|
||||
class: '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')
|
||||
= render 'sites/build', site: site
|
||||
= render 'sites/moderation_queue', site: site
|
||||
- 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)
|
||||
.d-flex.flex-row
|
||||
= link_to t('.visit'), site.url, class: 'btn btn-secondary'
|
||||
- if current_usuarie.rol_for_site(site).temporal?
|
||||
= render 'components/btn_base',
|
||||
text: t('sites.invitations.accept'),
|
||||
path: site_usuaries_accept_invitation_path(site),
|
||||
title: t('help.sites.invitations.accept'),
|
||||
class: 'btn-secondary'
|
||||
= render 'components/btn_base',
|
||||
text: t('sites.invitations.reject'),
|
||||
path: site_usuaries_reject_invitation_path(site),
|
||||
title: t('help.sites.invitations.reject'),
|
||||
class: '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')
|
||||
= render 'sites/build', site: site
|
||||
= render 'sites/moderation_queue', site: site
|
||||
- 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)
|
||||
|
|
Loading…
Reference in a new issue