about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-07-02 12:03:15 +0200
committerGitHub <noreply@github.com>2021-07-02 12:03:15 +0200
commit38b34199507d81cac9f4ff18b5ce11f5e7ef9f23 (patch)
treef4d7a1f23c135996de5ba9e7aca59b7589a1703c
parent92c8c30e177ff68c804707b72b123fede956d944 (diff)
Fix not being able to suspend accounts that already have a canonical e-mail block (#16455)
-rw-r--r--app/models/account.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 2c5455d8e..8be36bf5b 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -570,7 +570,11 @@ class Account < ApplicationRecord
   def create_canonical_email_block!
     return unless local? && user_email.present?
 
-    CanonicalEmailBlock.create(reference_account: self, email: user_email)
+    begin
+      CanonicalEmailBlock.create(reference_account: self, email: user_email)
+    rescue ActiveRecord::RecordNotUnique
+      # A canonical e-mail block may already exist for the same e-mail
+    end
   end
 
   def destroy_canonical_email_block!