mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-17 07:43:17 +00:00
Merge tag 'v4.0.0rc1'
This commit is contained in:
commit
7ef0a46ebb
1463 changed files with 51604 additions and 34943 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
21
app/validators/language_validator.rb
Normal file
21
app/validators/language_validator.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue