Merge tag 'v4.0.0rc1'

This commit is contained in:
bgme 2022-11-06 11:59:14 +08:00
commit 7ef0a46ebb
1463 changed files with 51604 additions and 34943 deletions

View file

@ -6,7 +6,7 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
usernames_and_domains = begin
value.split(',').map do |str|
username, domain = str.strip.gsub(/\A@/, '').split('@')
username, domain = str.strip.gsub(/\A@/, '').split('@', 2)
domain = nil if TagManager.instance.local_domain?(domain)
next if username.blank?
@ -21,8 +21,8 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
if options[:multiple]
record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: usernames_with_no_accounts.join(', '))) if usernames_with_no_accounts.any?
else
record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) if usernames_with_no_accounts.any? || usernames_and_domains.size > 1
elsif usernames_with_no_accounts.any? || usernames_and_domains.size > 1
record.errors.add(attribute, I18n.t('existing_username_validator.not_found'))
end
end
end

View file

@ -26,6 +26,8 @@ class ImportValidator < ActiveModel::Validator
when 'following'
validate_following_import(import, row_count)
end
rescue CSV::MalformedCSVError
import.errors.add(:data, :malformed)
end
private

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
class LanguageValidator < ActiveModel::EachValidator
include LanguagesHelper
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid) unless valid?(value)
end
private
def valid?(str)
if str.nil?
true
elsif str.is_a?(Array)
str.all? { |x| valid_locale?(x) }
else
valid_locale?(str)
end
end
end

View file

@ -2,7 +2,7 @@
class URLValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, I18n.t('applications.invalid_url')) unless compliant?(value)
record.errors.add(attribute, :invalid) unless compliant?(value)
end
private