about summary refs log tree commit diff
path: root/app/models/account_alias.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-04-13 06:41:43 +0200
committerGitHub <noreply@github.com>2020-04-13 06:41:43 +0200
commitf7e011919e8819e0d706f15eab87b84fce6fd3c7 (patch)
treee098ead99e188bda09065087eb92505afe24783b /app/models/account_alias.rb
parent490ff09c5a503f1e5f9cad964470fdefa3eabea8 (diff)
Fix account aliases page (#13452)
* Fix error not being displayed when adding an account alias, add error for self-references

Co-Authored-By: Mélanie Chauvel (ariasuni) <perso@hack-libre.org>

* Add “You have no aliases.” note in confusing empty aliases table

Co-Authored-By: Mélanie Chauvel (ariasuni) <perso@hack-libre.org>

Co-authored-by: Mélanie Chauvel (ariasuni) <perso@hack-libre.org>
Diffstat (limited to 'app/models/account_alias.rb')
-rw-r--r--app/models/account_alias.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/account_alias.rb b/app/models/account_alias.rb
index 66f8ce409..3d0b5d188 100644
--- a/app/models/account_alias.rb
+++ b/app/models/account_alias.rb
@@ -18,6 +18,7 @@ class AccountAlias < ApplicationRecord
   validates :acct, presence: true, domain: { acct: true }
   validates :uri, presence: true
   validates :uri, uniqueness: { scope: :account_id }
+  validate :validate_target_account
 
   before_validation :set_uri
   after_create :add_to_account
@@ -44,4 +45,12 @@ class AccountAlias < ApplicationRecord
   def remove_from_account
     account.update(also_known_as: account.also_known_as.reject { |x| x == uri })
   end
+
+  def validate_target_account
+    if uri.nil?
+      errors.add(:acct, I18n.t('migrations.errors.not_found'))
+    elsif ActivityPub::TagManager.instance.uri_for(account) == uri
+      errors.add(:acct, I18n.t('migrations.errors.move_to_self'))
+    end
+  end
 end