diff --git a/app/models/concerns/account/attribution_domains.rb b/app/models/concerns/account/attribution_domains.rb index 5f4d9afabfc..22bf27cc5dd 100644 --- a/app/models/concerns/account/attribution_domains.rb +++ b/app/models/concerns/account/attribution_domains.rb @@ -3,10 +3,12 @@ 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: 100 }, if: -> { local? && will_save_change_to_attribution_domains? } + 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) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 8ce337f1c74..be400fecd4a 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -506,6 +506,8 @@ RSpec.describe Account do context 'when account is local' do subject { Fabricate.build :account, domain: nil } + let(:domains_limit) { described_class::ATTRIBUTION_DOMAINS_LIMIT } + context 'with an existing differently-cased username account' do before { Fabricate :account, username: 'the_doctor' } @@ -547,8 +549,8 @@ RSpec.describe Account do it { is_expected.to validate_absence_of(:shared_inbox_url).on(:create) } it { is_expected.to validate_absence_of(:uri).on(:create) } - it { is_expected.to allow_values([], ['example.com'], (1..100).to_a).for(:attribution_domains) } - it { is_expected.to_not allow_values(['example com'], ['@'], (1..101).to_a).for(:attribution_domains) } + it { is_expected.to allow_values([], ['example.com'], (1..domains_limit).to_a).for(:attribution_domains) } + it { is_expected.to_not allow_values(['example com'], ['@'], (1..(domains_limit + 1)).to_a).for(:attribution_domains) } end context 'when account is remote' do