From 38b34199507d81cac9f4ff18b5ce11f5e7ef9f23 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 2 Jul 2021 12:03:15 +0200 Subject: [PATCH] Fix not being able to suspend accounts that already have a canonical e-mail block (#16455) --- app/models/account.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index 2c5455d8e5..8be36bf5b8 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!