mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
19 lines
660 B
Ruby
19 lines
660 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Account::AttributionDomains
|
|
extend ActiveSupport::Concern
|
|
|
|
ATTRIBUTION_DOMAINS_LIMIT = 100
|
|
|
|
included do
|
|
normalizes :attribution_domains, with: ->(arr) { arr.filter_map { |str| str.to_s.strip.delete_prefix('http://').delete_prefix('https://').delete_prefix('*.').presence }.uniq }
|
|
|
|
validates :attribution_domains, domain: true, length: { maximum: ATTRIBUTION_DOMAINS_LIMIT }, if: -> { local? && will_save_change_to_attribution_domains? }
|
|
end
|
|
|
|
def can_be_attributed_from?(domain)
|
|
variants = self.class.domain_variants(domain)
|
|
self[:attribution_domains].to_set.intersect?(variants.to_set)
|
|
end
|
|
end
|