闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
697 B

  1. # frozen_string_literal: true
  2. class ExistingUsernameValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. return if value.blank?
  5. if options[:multiple]
  6. missing_usernames = value.split(',').map { |username| username unless Account.find_local(username) }.compact
  7. record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: missing_usernames.join(', '))) if missing_usernames.any?
  8. else
  9. record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value)
  10. end
  11. end
  12. private
  13. def valid_html?(str)
  14. Nokogiri::HTML.fragment(str).to_s == str
  15. end
  16. end