5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-23 18:46:08 +00:00

chore: rubocop

This commit is contained in:
f 2024-05-02 16:05:35 -03:00
parent b11282997b
commit c2cc08007e
No known key found for this signature in database
24 changed files with 52 additions and 49 deletions

View file

@ -14,7 +14,7 @@ class ApplicationController < ActionController::Base
after_action :store_location!
before_action do
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?('@' + ENV.fetch('SUTTY', 'sutty.nl'))
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?("@#{ENV.fetch('SUTTY', 'sutty.nl')}")
end
# No tenemos índice de sutty, vamos directamente a ver el listado de
@ -24,7 +24,7 @@ class ApplicationController < ActionController::Base
end
private
def notify_unconfirmed_email
return unless current_usuarie
return if current_usuarie.confirmed?
@ -58,9 +58,7 @@ class ApplicationController < ActionController::Base
def current_locale
locale = params[:change_locale_to]
if locale.present? && I18n.locale_available?(locale)
session[:locale] = params[:change_locale_to]
end
session[:locale] = params[:change_locale_to] if locale.present? && I18n.locale_available?(locale)
session[:locale] || current_usuarie&.lang || I18n.locale
end
@ -119,5 +117,4 @@ class ApplicationController < ActionController::Base
session[:usuarie_return_to] = request.fullpath
end
end

View file

@ -13,7 +13,7 @@ module ApplicationHelper
root = names.shift
names.each do |n|
root += '[' + n.to_s + ']'
root += "[#{n}]"
end
[root, name]
@ -22,7 +22,7 @@ module ApplicationHelper
def plain_field_name_for(*names)
root, name = field_name_for(*names)
root + '[' + name.to_s + ']'
"#{root}[#{name}]"
end
def distance_of_time_in_words_if_more_than_a_minute(seconds)

View file

@ -50,7 +50,8 @@ class ActivityPub
content = FastJsonparser.parse(response.body)
# Modificar atómicamente
::ActivityPub::Object.lock.find(object_id).update!(content: content, type: ActivityPub::Object.type_from(content).name)
::ActivityPub::Object.lock.find(object_id).update!(content: content,
type: ActivityPub::Object.type_from(content).name)
object = ::ActivityPub::Object.find(object_id)
# Actualiza la mención

View file

@ -43,7 +43,9 @@ class ActivityPub
# Si alguna falló, reintentar
raise if logs.present?
rescue Exception => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, logs: logs, blocklist: blocklist, allowlist: allowlist, pauselist: pauselist })
ExceptionNotifier.notify_exception(e,
data: { site: site.name, logs: logs, blocklist: blocklist,
allowlist: allowlist, pauselist: pauselist })
raise
end

View file

@ -8,7 +8,7 @@ class ApplicationJob < ActiveJob::Base
# superpongan tareas
#
# @return [Array<Integer>]
RANDOM_WAIT = [3, 5, 7, 11, 13]
RANDOM_WAIT = [3, 5, 7, 11, 13].freeze
# @return [ActiveSupport::Duration]
def self.random_wait
@ -17,8 +17,6 @@ class ApplicationJob < ActiveJob::Base
attr_reader :site
private
# Si falla por cualquier cosa informar y descartar
discard_on(Exception) do |job, error|
ExceptionNotifier.notify_exception(error, data: { job: job })

View file

@ -64,7 +64,7 @@ class ActivityPub < ApplicationRecord
# Array<String> o mezcla y obtener el que más nos convenga o
# adivinar uno.
when Array
links = object['url'].map.with_index do |link, i|
links = object['url'].map.with_index do |link, _i|
case link
when Hash then link
else { 'href' => link.to_s }
@ -93,7 +93,8 @@ class ActivityPub < ApplicationRecord
# Gestionar todos los errores
error_on_all_events do |e|
ExceptionNotifier.notify_exception(e, data: { site: site.name, activity_pub: self.id, activity: activities.first.uri })
ExceptionNotifier.notify_exception(e,
data: { site: site.name, activity_pub: id, activity: activities.first.uri })
end
# Se puede volver a pausa en caso de actualización remota, para

View file

@ -35,9 +35,9 @@ class ActivityPub
validates_inclusion_of :format, in: %w[mastodon fediblock none]
HOSTNAME_HEADERS = {
'mastodon' => '#domain',
'mastodon' => '#domain',
'fediblock' => 'domain'
}
}.freeze
def client
@client ||= Client.new

View file

@ -39,13 +39,14 @@ class ActivityPub
def referenced(site)
require 'distributed_press/v1/social/referenced_object'
@referenced ||= DistributedPress::V1::Social::ReferencedObject.new(object: content, dereferencer: site.social_inbox.dereferencer)
@referenced ||= DistributedPress::V1::Social::ReferencedObject.new(object: content,
dereferencer: site.social_inbox.dereferencer)
end
private
def uri_is_content_id?
return if self.uri == content['id']
return if uri == content['id']
errors.add(:activity_pub_objects, 'El ID del objeto no coincide con su URI')
end

View file

@ -40,7 +40,8 @@ class ActivityPub
def content
{
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => Rails.application.routes.url_helpers.v1_activity_pub_remote_flag_url(self, host: site.social_inbox_hostname),
'id' => Rails.application.routes.url_helpers.v1_activity_pub_remote_flag_url(self,
host: site.social_inbox_hostname),
'type' => 'Flag',
'actor' => main_site.social_inbox.actor_id,
'content' => message.to_s,
@ -53,7 +54,7 @@ class ActivityPub
#
# @return [Site]
def main_site
@main_site ||= Site.find(ENV.fetch('PANEL_ACTOR_SITE_ID') { 1 })
@main_site ||= Site.find(ENV.fetch('PANEL_ACTOR_SITE_ID', 1))
end
end
end

View file

@ -17,7 +17,7 @@ module Tienda
return t if new_record?
t.blank? ? 'https://' + name + '.' + ENV.fetch('TIENDA', 'tienda.sutty.nl') : t
t.blank? ? "https://#{name}.#{ENV.fetch('TIENDA', 'tienda.sutty.nl')}" : t
end
end
end

View file

@ -45,7 +45,8 @@ class FediblockState < ApplicationRecord
private
def block_instances!
ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: fediblock.hostnames, perform_remotely: false)
ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: fediblock.hostnames,
perform_remotely: false)
end
# Pausar todas las moderaciones de las instancias que no estén

View file

@ -16,7 +16,9 @@ class InstanceModeration < ApplicationRecord
state :blocked
error_on_all_events do |e|
ExceptionNotifier.notify_exception(e, data: { site: site.name, instance: instance.hostname, instance_moderation: id })
ExceptionNotifier.notify_exception(e,
data: { site: site.name, instance: instance.hostname,
instance_moderation: id })
end
after_all_events do

View file

@ -134,7 +134,7 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
# En caso de que algún campo necesite realizar acciones antes de ser
# guardado
def save
if !changed?
unless changed?
self[:value] = document_value if private?
return true

View file

@ -45,7 +45,7 @@ class SocialInbox
# @param url [String]
# @return [DistributedPress::V1::Social::Client]
def client_for(url)
raise "Falló generar un cliente" if url.blank?
raise 'Falló generar un cliente' if url.blank?
@client_for ||= {}
@client_for[url] ||=
@ -54,7 +54,7 @@ class SocialInbox
public_key_url: public_key_url,
private_key_pem: site.private_key_pem,
logger: Rails.logger,
cache_store: HTTParty::Cache::Store::Redis.new(redis_url: ENV['REDIS_SERVER'])
cache_store: HTTParty::Cache::Store::Redis.new(redis_url: ENV.fetch('REDIS_SERVER', nil))
)
end

View file

@ -222,8 +222,6 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
end
end
private
# Asignar un rol a cada deploy si no lo tenía ya
def add_role_to_deploys!(role = current_role)
site.deploys.each do |deploy|

View file

@ -62,7 +62,7 @@ Rails.application.configure do
config.log_tags = %i[request_id]
# Use a different cache store in production.
config.cache_store = :redis_cache_store, { url: ENV['REDIS_SERVER'] }
config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_SERVER', nil) }
config.action_mailer.perform_caching = false
@ -87,7 +87,7 @@ Rails.application.configure do
config.lograge.enabled = true
# Use default logging formatter so that PID and timestamp are not
# suppressed.
config.log_formatter = ::Logger::Formatter.new
config.log_formatter = Logger::Formatter.new
# Use a different logger for distributed setups.
require 'syslog/logger'
@ -140,9 +140,10 @@ Rails.application.configure do
domain: ENV.fetch('SUTTY', 'sutty.nl'),
enable_starttls_auto: false
}
config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', "noreply@sutty.nl") }
config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', 'noreply@sutty.nl') }
config.middleware.use ExceptionNotification::Rack, gitlab: {}, error_grouping: true, ignore_exceptions: ['DeployJob::DeployAlreadyRunningException']
config.middleware.use ExceptionNotification::Rack, gitlab: {}, error_grouping: true,
ignore_exceptions: ['DeployJob::DeployAlreadyRunningException']
Rails.application.routes.default_url_options[:host] = "panel.#{ENV.fetch('SUTTY', 'sutty.nl')}"
Rails.application.routes.default_url_options[:protocol] = 'https'

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
Que::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == [ENV['HTTP_BASIC_USER'], ENV['HTTP_BASIC_PASSWORD']]
[user, password] == [ENV.fetch('HTTP_BASIC_USER', nil), ENV.fetch('HTTP_BASIC_PASSWORD', nil)]
end

View file

@ -16,9 +16,7 @@ class CreateFediblockStates < ActiveRecord::Migration[6.1]
# Todas las listas están activas por defecto
DeploySocialDistributedPress.find_each do |deploy|
ActivityPub::Fediblock.find_each do |fediblock|
FediblockState.create(site: deploy.site, fediblock: fediblock, aasm_state: 'disabled').tap do |f|
f.enable!
end
FediblockState.create(site: deploy.site, fediblock: fediblock, aasm_state: 'disabled').tap(&:enable!)
end
end
end

View file

@ -4,9 +4,11 @@
# decompresión
class BrsDecompressorCorruptedSourceError < ActiveRecord::Migration[6.1]
def up
raise unless HTTParty.get("https://mas.to/api/v2/instance", headers: { "Accept-Encoding": "br;q=1.0,gzip;q=1.0,deflate;q=0.6,identity;q=0.3" }).ok?
raise unless HTTParty.get('https://mas.to/api/v2/instance',
headers: { 'Accept-Encoding': 'br;q=1.0,gzip;q=1.0,deflate;q=0.6,identity;q=0.3' }).ok?
QueJob.where("last_error_message like '%BRS::DecompressorCorruptedSourceError%'").update_all(error_count: 0, run_at: Time.now)
QueJob.where("last_error_message like '%BRS::DecompressorCorruptedSourceError%'").update_all(error_count: 0,
run_at: Time.now)
end
def down; end

View file

@ -4,7 +4,9 @@
class FixActivityType < ActiveRecord::Migration[6.1]
def up
%w[Like Announce].each do |type|
ActivityPub::Activity.where(Arel.sql("content->>'type' = '#{type}'")).update_all(type: "ActivityPub::Activity::#{type}", updated_at: Time.now)
ActivityPub::Activity.where(Arel.sql("content->>'type' = '#{type}'")).update_all(
type: "ActivityPub::Activity::#{type}", updated_at: Time.now
)
end
end

View file

@ -3,7 +3,7 @@
# De alguna forma se guardaron objetos duplicados!
class FixDuplicateObjects < ActiveRecord::Migration[6.1]
def up
ActivityPub::Object.group(:uri).count.select { |_, v| v > 1 }.keys.each do |uri|
ActivityPub::Object.group(:uri).count.select { |_, v| v > 1 }.each_key do |uri|
objects = ActivityPub::Object.where(uri: uri)
deleted_ids = objects[1..].map(&:delete).map(&:id)

View file

@ -14,9 +14,7 @@ class AddFedipactToFediblocks < ActiveRecord::Migration[6.1]
)
DeploySocialDistributedPress.find_each do |deploy|
FediblockState.create(site: deploy.site, fediblock: fedipact, aasm_state: 'disabled').tap do |f|
f.enable!
end
FediblockState.create(site: deploy.site, fediblock: fedipact, aasm_state: 'disabled').tap(&:enable!)
end
end

View file

@ -4,14 +4,14 @@
# no es válida y por eso teníamos objetos duplicados.
class AddMissingUniqueIndexes < ActiveRecord::Migration[6.1]
def up
ActivityPub::Object.group(:uri).count.select { |_, v| v > 1 }.keys.each do |uri|
ActivityPub::Object.group(:uri).count.select { |_, v| v > 1 }.each_key do |uri|
objects = ActivityPub::Object.where(uri: uri)
deleted_ids = objects[1..].map(&:delete).map(&:id)
ActivityPub.where(object_id: deleted_ids).update_all(object_id: objects.first.id, updated_at: Time.now)
end
ActivityPub::Actor.group(:uri).count.select { |_, v| v > 1 }.keys.each do |uri|
ActivityPub::Actor.group(:uri).count.select { |_, v| v > 1 }.each_key do |uri|
objects = ActivityPub::Actor.where(uri: uri)
deleted_ids = objects[1..].map(&:delete).map(&:id)
@ -21,7 +21,7 @@ class AddMissingUniqueIndexes < ActiveRecord::Migration[6.1]
ActivityPub::RemoteFlag.where(actor_id: deleted_ids).update_all(actor_id: objects.first.id, updated_at: Time.now)
end
ActivityPub::Instance.group(:hostname).count.select { |_, v| v > 1 }.keys.each do |hostname|
ActivityPub::Instance.group(:hostname).count.select { |_, v| v > 1 }.each_key do |hostname|
objects = ActivityPub::Instance.where(hostname: hostname)
deleted_ids = objects[1..].map(&:delete).map(&:id)

View file

@ -20,13 +20,13 @@ if CodeOfConduct.count.zero?
YAML.safe_load(File.read('db/seeds/codes_of_conduct.yml')).each do |coc|
CodeOfConduct.new(**coc).save!
end
end
end
if PrivacyPolicy.count.zero?
YAML.safe_load(File.read('db/seeds/privacy_policies.yml')).each do |pp|
PrivacyPolicy.new(**pp).save!
end
end
end
YAML.safe_load(File.read('db/seeds/activity_pub/fediblocks.yml')).each do |fediblock|
ActivityPub::Fediblock.find_or_create_by(id: fediblock['id']).tap do |f|