Revert "Upstream 20240517"

This commit is contained in:
KMY(雪あすか) 2024-05-24 08:15:12 +09:00 committed by GitHub
parent 9c006fd893
commit f6dec44e95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2347 changed files with 26470 additions and 87494 deletions

View file

@ -1,18 +0,0 @@
# frozen_string_literal: true
# NOTE: I initially wrote this as `EmailValidator` but it ended up clashing
# with an indirect dependency of ours, `validate_email`, which, turns out,
# has the same approach as we do, but with an extra check disallowing
# single-label domains. Decided to not switch to `validate_email` because
# we do want to allow at least `localhost`.
class EmailAddressValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value = value.strip
address = Mail::Address.new(value)
record.errors.add(attribute, :invalid) if address.address != value
rescue Mail::Field::FieldError
record.errors.add(attribute, :invalid)
end
end

View file

@ -1,40 +0,0 @@
# frozen_string_literal: true
class EmojiReactionValidator < ActiveModel::Validator
SUPPORTED_EMOJIS = Oj.load_file(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json').to_s).keys.freeze
def validate(emoji_reaction)
return if emoji_reaction.name.blank?
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.blank? && !unicode_emoji?(emoji_reaction.name)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.present? && disabled_custom_emoji?(emoji_reaction.custom_emoji)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_emoji_reactions?(emoji_reaction)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if blocking?(emoji_reaction) || domain_blocking?(emoji_reaction)
end
private
def unicode_emoji?(name)
SUPPORTED_EMOJIS.include?(name)
end
def disabled_custom_emoji?(custom_emoji)
custom_emoji.nil? ? false : custom_emoji.disabled
end
def deny_emoji_reactions?(emoji_reaction)
!emoji_reaction.status.account.allow_emoji_reaction?(emoji_reaction.account)
end
def blocking?(emoji_reaction)
return false if !emoji_reaction.status.local? || emoji_reaction.status.account == emoji_reaction.account
emoji_reaction.status.account.blocking?(emoji_reaction.account)
end
def domain_blocking?(emoji_reaction)
return false unless !emoji_reaction.account.local? && emoji_reaction.status.local?
emoji_reaction.status.account.domain_blocking?(emoji_reaction.account.domain)
end
end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
class PollValidator < ActiveModel::Validator
MAX_OPTIONS = 8
MAX_OPTIONS = 4
MAX_OPTION_CHARS = 50
MAX_EXPIRATION = 1.month.freeze
MIN_EXPIRATION = 5.minutes.freeze

View file

@ -19,7 +19,7 @@ class ReactionValidator < ActiveModel::Validator
end
def new_reaction?(reaction)
!reaction.announcement.announcement_reactions.exists?(name: reaction.name)
!reaction.announcement.announcement_reactions.where(name: reaction.name).exists?
end
def limit_reached?(reaction)

View file

@ -35,7 +35,7 @@ class VoteValidator < ActiveModel::Validator
if vote.persisted?
account_votes_on_same_poll(vote).where(choice: vote.choice).where.not(poll_votes: { id: vote }).exists?
else
account_votes_on_same_poll(vote).exists?(choice: vote.choice)
account_votes_on_same_poll(vote).where(choice: vote.choice).exists?
end
end