forked from cybrespace/mastodon
Create DomainNormalizable#normalize_domain (#9631)
This commit is contained in:
parent
bf70e5cfda
commit
0c1e4bb969
|
@ -59,6 +59,7 @@ class Account < ApplicationRecord
|
||||||
include Attachmentable
|
include Attachmentable
|
||||||
include Paginable
|
include Paginable
|
||||||
include AccountCounters
|
include AccountCounters
|
||||||
|
include DomainNormalizable
|
||||||
|
|
||||||
enum protocol: [:ostatus, :activitypub]
|
enum protocol: [:ostatus, :activitypub]
|
||||||
|
|
||||||
|
@ -457,7 +458,6 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
before_create :generate_keys
|
before_create :generate_keys
|
||||||
before_validation :normalize_domain
|
|
||||||
before_validation :prepare_contents, if: :local?
|
before_validation :prepare_contents, if: :local?
|
||||||
before_destroy :clean_feed_manager
|
before_destroy :clean_feed_manager
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ class Account < ApplicationRecord
|
||||||
def normalize_domain
|
def normalize_domain
|
||||||
return if local?
|
return if local?
|
||||||
|
|
||||||
self.domain = TagManager.instance.normalize_domain(domain)
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def emojifiable_text
|
def emojifiable_text
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module DomainNormalizable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
before_validation :normalize_domain
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def normalize_domain
|
||||||
|
self.domain = TagManager.instance.normalize_domain(domain)
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,6 +13,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class DomainBlock < ApplicationRecord
|
class DomainBlock < ApplicationRecord
|
||||||
|
include DomainNormalizable
|
||||||
|
|
||||||
enum severity: [:silence, :suspend, :noop]
|
enum severity: [:silence, :suspend, :noop]
|
||||||
|
|
||||||
attr_accessor :retroactive
|
attr_accessor :retroactive
|
||||||
|
@ -25,12 +27,4 @@ class DomainBlock < ApplicationRecord
|
||||||
def self.blocked?(domain)
|
def self.blocked?(domain)
|
||||||
where(domain: domain, severity: :suspend).exists?
|
where(domain: domain, severity: :suspend).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
before_validation :normalize_domain
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def normalize_domain
|
|
||||||
self.domain = TagManager.instance.normalize_domain(domain)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class EmailDomainBlock < ApplicationRecord
|
class EmailDomainBlock < ApplicationRecord
|
||||||
before_validation :normalize_domain
|
include DomainNormalizable
|
||||||
|
|
||||||
validates :domain, presence: true, uniqueness: true
|
validates :domain, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
@ -27,10 +27,4 @@ class EmailDomainBlock < ApplicationRecord
|
||||||
|
|
||||||
where(domain: domain).exists?
|
where(domain: domain).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def normalize_domain
|
|
||||||
self.domain = TagManager.instance.normalize_domain(domain)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue