about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-11-27 22:47:06 +0100
committerGitHub <noreply@github.com>2017-11-27 22:47:06 +0100
commit706e534455e2137c324c0ebb30435e7630ab7c1f (patch)
tree9875215f85439929a41d70853a674a2c33096f93 /app/models
parentff78c1177a180f1b9aec8464734ac3aa1c888874 (diff)
Add UI for setting up account migration (#5832)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/form/migration.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/form/migration.rb b/app/models/form/migration.rb
new file mode 100644
index 000000000..53cee7ee1
--- /dev/null
+++ b/app/models/form/migration.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class Form::Migration
+  include ActiveModel::Validations
+
+  attr_accessor :acct, :account
+
+  validates :acct, presence: true
+
+  def initialize(attrs = {})
+    @account = attrs[:account]
+    @acct    = attrs[:account].acct unless @account.nil?
+    @acct    = attrs[:acct].gsub(/\A@/, '').strip unless attrs[:acct].nil?
+  end
+
+  def valid?
+    return false unless super
+    set_account
+    errors.empty?
+  end
+
+  private
+
+  def set_account
+    self.account = ResolveRemoteAccountService.new.call(acct) if account.nil? && acct.present?
+  end
+end