about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-02-03 03:59:51 +0100
committerGitHub <noreply@github.com>2019-02-03 03:59:51 +0100
commitd14c276e58f0f223b0e4889d342a948c961081b2 (patch)
treef25b687f755725ee58b80ab2281dc368f5dc42eb /app/models
parentc5071f2d787e81251c2b3111074b20d94773ee44 (diff)
Add option to overwrite imported data (#9962)
* Add option to overwrite imported data

Fix #7465

* Add import for domain blocks
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_domain_block.rb1
-rw-r--r--app/models/concerns/domain_normalizable.rb2
-rw-r--r--app/models/export.rb1
-rw-r--r--app/models/import.rb14
4 files changed, 15 insertions, 3 deletions
diff --git a/app/models/account_domain_block.rb b/app/models/account_domain_block.rb
index e352000c3..7c0d60379 100644
--- a/app/models/account_domain_block.rb
+++ b/app/models/account_domain_block.rb
@@ -12,6 +12,7 @@
 
 class AccountDomainBlock < ApplicationRecord
   include Paginable
+  include DomainNormalizable
 
   belongs_to :account
   validates :domain, presence: true, uniqueness: { scope: :account_id }
diff --git a/app/models/concerns/domain_normalizable.rb b/app/models/concerns/domain_normalizable.rb
index dff3e5414..fb84058fc 100644
--- a/app/models/concerns/domain_normalizable.rb
+++ b/app/models/concerns/domain_normalizable.rb
@@ -10,6 +10,6 @@ module DomainNormalizable
   private
 
   def normalize_domain
-    self.domain = TagManager.instance.normalize_domain(domain)
+    self.domain = TagManager.instance.normalize_domain(domain&.strip)
   end
 end
diff --git a/app/models/export.rb b/app/models/export.rb
index a2520e9c2..fc4bb6964 100644
--- a/app/models/export.rb
+++ b/app/models/export.rb
@@ -1,4 +1,5 @@
 # frozen_string_literal: true
+
 require 'csv'
 
 class Export
diff --git a/app/models/import.rb b/app/models/import.rb
index 55e970b0d..a7a0d8065 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -13,20 +13,30 @@
 #  data_file_size    :integer
 #  data_updated_at   :datetime
 #  account_id        :bigint(8)        not null
+#  overwrite         :boolean          default(FALSE), not null
 #
 
 class Import < ApplicationRecord
-  FILE_TYPES = ['text/plain', 'text/csv'].freeze
+  FILE_TYPES = %w(text/plain text/csv).freeze
+  MODES = %i(merge overwrite).freeze
 
   self.inheritance_column = false
 
   belongs_to :account
 
-  enum type: [:following, :blocking, :muting]
+  enum type: [:following, :blocking, :muting, :domain_blocking]
 
   validates :type, presence: true
 
   has_attached_file :data
   validates_attachment_content_type :data, content_type: FILE_TYPES
   validates_attachment_presence :data
+
+  def mode
+    overwrite? ? :overwrite : :merge
+  end
+
+  def mode=(str)
+    self.overwrite = str.to_sym == :overwrite
+  end
 end