Compare commits

...

2 Commits

Author SHA1 Message Date
Matt Jankowski
6524925c58
Merge 103e42b7f6 into 94bceb8683 2025-07-11 10:56:23 -04:00
Matt Jankowski
103e42b7f6 Extract constant for attribution domains limit 2025-07-11 10:35:42 -04:00
2 changed files with 5 additions and 3 deletions

View File

@ -3,10 +3,12 @@
module Account::AttributionDomains module Account::AttributionDomains
extend ActiveSupport::Concern extend ActiveSupport::Concern
ATTRIBUTION_DOMAINS_LIMIT = 100
included do 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 } 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 end
def can_be_attributed_from?(domain) def can_be_attributed_from?(domain)

View File

@ -547,8 +547,8 @@ RSpec.describe Account do
it { is_expected.to validate_absence_of(:shared_inbox_url).on(:create) } 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 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 allow_values([], ['example.com'], Array.new(described_class::ATTRIBUTION_DOMAINS_LIMIT, &:to_s)).for(:attribution_domains) }
it { is_expected.to_not allow_values(['example com'], ['@'], (1..101).to_a).for(:attribution_domains) } it { is_expected.to_not allow_values(['example com'], ['@'], Array.new(described_class::ATTRIBUTION_DOMAINS_LIMIT * 2, &:to_s)).for(:attribution_domains) }
end end
context 'when account is remote' do context 'when account is remote' do