Merge remote-tracking branch 'parent/main' into kb-upstream-20231026

This commit is contained in:
KMY 2023-10-26 20:24:34 +09:00
commit 5448bcf276
313 changed files with 3717 additions and 4735 deletions

View file

@ -23,10 +23,7 @@ class AccountAlias < ApplicationRecord
after_create :add_to_account
after_destroy :remove_from_account
def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..] : val)
end
normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }
def pretty_acct
username, domain = acct.split('@', 2)

View file

@ -25,6 +25,8 @@ class AccountMigration < ApplicationRecord
before_validation :set_target_account
before_validation :set_followers_count
normalizes :acct, with: ->(acct) { acct.strip.delete_prefix('@') }
validates :acct, presence: true, domain: { acct: true }
validate :validate_migration_cooldown
validate :validate_target_account
@ -51,10 +53,6 @@ class AccountMigration < ApplicationRecord
created_at + COOLDOWN_PERIOD
end
def acct=(val)
super(val.to_s.strip.gsub(/\A@/, ''))
end
private
def set_target_account

View file

@ -28,7 +28,7 @@ class AccountWarning < ApplicationRecord
suspend: 4_000,
}, _suffix: :action
before_validation :before_validate
normalizes :text, with: ->(text) { text.to_s }, apply_to_nil: true
belongs_to :account, inverse_of: :account_warnings
belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
@ -51,10 +51,4 @@ class AccountWarning < ApplicationRecord
def to_log_human_identifier
target_account.acct
end
private
def before_validate
self.text = '' if text.blank?
end
end

View file

@ -4,7 +4,7 @@ module HasUserSettings
extend ActiveSupport::Concern
included do
serialize :settings, UserSettingsSerializer
serialize :settings, coder: UserSettingsSerializer
end
def settings_attributes=(attributes)

View file

@ -15,7 +15,7 @@ module StatusSafeReblogInsert
#
# The code is kept similar to ActiveRecord::Persistence code and calls it
# directly when we are not handling a reblog.
def _insert_record(values)
def _insert_record(values, returning)
return super unless values.is_a?(Hash) && values['reblog_of_id']&.value.present?
primary_key = self.primary_key
@ -34,7 +34,7 @@ module StatusSafeReblogInsert
# Instead, we use a custom builder when a reblog is happening:
im = _compile_reblog_insert(values)
connection.insert(im, "#{self} Create", primary_key || false, primary_key_value).tap do |result|
connection.insert(im, "#{self} Create", primary_key || false, primary_key_value, returning: returning).tap do |result|
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
# For our purposes, it's equivalent to a foreign key constraint violation
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil?

View file

@ -23,7 +23,7 @@ class FeaturedTag < ApplicationRecord
validate :validate_tag_uniqueness, on: :create
validate :validate_featured_tags_limit, on: :create
before_validation :strip_name
normalizes :name, with: ->(name) { name.strip.delete_prefix('#') }
before_create :set_tag
before_create :reset_data
@ -50,10 +50,6 @@ class FeaturedTag < ApplicationRecord
private
def strip_name
self.name = name&.strip&.delete_prefix('#')
end
def set_tag
self.tag = Tag.find_or_create_by_names(name)&.first
end

View file

@ -19,7 +19,8 @@ class Relay < ApplicationRecord
scope :enabled, -> { accepted }
before_validation :strip_url
normalizes :inbox_url, with: ->(inbox_url) { inbox_url.strip }
before_destroy :ensure_disabled
alias enabled? accepted?
@ -76,8 +77,4 @@ class Relay < ApplicationRecord
def ensure_disabled
disable! if enabled?
end
def strip_url
inbox_url&.strip!
end
end

View file

@ -142,6 +142,11 @@ class Report < ApplicationRecord
target_type: 'Status',
target_id: status_ids
).unscope(:order).arel,
Admin::ActionLog.where(
target_type: 'AccountWarning',
target_id: AccountWarning.where(report_id: id).select(:id)
).unscope(:order).arel,
].reduce { |union, query| Arel::Nodes::UnionAll.new(union, query) }
Admin::ActionLog.from(Arel::Nodes::As.new(subquery, Admin::ActionLog.arel_table))

View file

@ -37,7 +37,7 @@ class Tag < ApplicationRecord
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
HASHTAG_RE = %r{(?:^|[^/)\w])#(#{HASHTAG_NAME_PAT})}i
HASHTAG_RE = %r{(?<![=/)[:word]])#(#{HASHTAG_NAME_PAT})}i
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/