mirror of
https://github.com/mastodon/mastodon.git
synced 2025-10-05 16:42:47 +00:00
Extract constant for attribution domains limit in account (#35350)
This commit is contained in:
parent
c0eabe289b
commit
0efb889a9c
|
@ -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)
|
||||||
|
|
|
@ -506,6 +506,8 @@ RSpec.describe Account do
|
||||||
context 'when account is local' do
|
context 'when account is local' do
|
||||||
subject { Fabricate.build :account, domain: nil }
|
subject { Fabricate.build :account, domain: nil }
|
||||||
|
|
||||||
|
let(:domains_limit) { described_class::ATTRIBUTION_DOMAINS_LIMIT }
|
||||||
|
|
||||||
context 'with an existing differently-cased username account' do
|
context 'with an existing differently-cased username account' do
|
||||||
before { Fabricate :account, username: 'the_doctor' }
|
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(: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'], (1..domains_limit).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_not allow_values(['example com'], ['@'], (1..(domains_limit + 1)).to_a).for(:attribution_domains) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when account is remote' do
|
context 'when account is remote' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user