about summary refs log tree commit diff
diff options
context:
space:
mode:
authorysksn <bluewhale1982@gmail.com>2018-12-26 14:38:42 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-12-26 06:38:42 +0100
commit0c1e4bb969a117c186e08396f9db0f747f04bdbd (patch)
tree0a006b6b39dcae71a50366125d4d1eb26099bbcb
parentbf70e5cfdaef9b7a3a927548a05203a864d5bea9 (diff)
Create DomainNormalizable#normalize_domain (#9631)
-rw-r--r--app/models/account.rb4
-rw-r--r--app/models/concerns/domain_normalizable.rb15
-rw-r--r--app/models/domain_block.rb10
-rw-r--r--app/models/email_domain_block.rb8
4 files changed, 20 insertions, 17 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 16ef6c187..cf804fc67 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -59,6 +59,7 @@ class Account < ApplicationRecord
   include Attachmentable
   include Paginable
   include AccountCounters
+  include DomainNormalizable
 
   enum protocol: [:ostatus, :activitypub]
 
@@ -457,7 +458,6 @@ class Account < ApplicationRecord
   end
 
   before_create :generate_keys
-  before_validation :normalize_domain
   before_validation :prepare_contents, if: :local?
   before_destroy :clean_feed_manager
 
@@ -479,7 +479,7 @@ class Account < ApplicationRecord
   def normalize_domain
     return if local?
 
-    self.domain = TagManager.instance.normalize_domain(domain)
+    super
   end
 
   def emojifiable_text
diff --git a/app/models/concerns/domain_normalizable.rb b/app/models/concerns/domain_normalizable.rb
new file mode 100644
index 000000000..dff3e5414
--- /dev/null
+++ b/app/models/concerns/domain_normalizable.rb
@@ -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
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index b828a9d71..1064ea7c8 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -13,6 +13,8 @@
 #
 
 class DomainBlock < ApplicationRecord
+  include DomainNormalizable
+
   enum severity: [:silence, :suspend, :noop]
 
   attr_accessor :retroactive
@@ -25,12 +27,4 @@ class DomainBlock < ApplicationRecord
   def self.blocked?(domain)
     where(domain: domain, severity: :suspend).exists?
   end
-
-  before_validation :normalize_domain
-
-  private
-
-  def normalize_domain
-    self.domain = TagManager.instance.normalize_domain(domain)
-  end
 end
diff --git a/app/models/email_domain_block.rb b/app/models/email_domain_block.rb
index 10490375b..0fcd36477 100644
--- a/app/models/email_domain_block.rb
+++ b/app/models/email_domain_block.rb
@@ -10,7 +10,7 @@
 #
 
 class EmailDomainBlock < ApplicationRecord
-  before_validation :normalize_domain
+  include DomainNormalizable
 
   validates :domain, presence: true, uniqueness: true
 
@@ -27,10 +27,4 @@ class EmailDomainBlock < ApplicationRecord
 
     where(domain: domain).exists?
   end
-
-  private
-
-  def normalize_domain
-    self.domain = TagManager.instance.normalize_domain(domain)
-  end
 end