about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-17 03:14:25 +0200
committerGitHub <noreply@github.com>2021-04-17 03:14:25 +0200
commitb3ceb3dcc4df62803aa967d7aecee686973a8996 (patch)
treedc34486813237852b90cc81b26c4e361323c7757 /app/models/account.rb
parent170e05db127c9f357183239a5543bdfc9525680d (diff)
Add canonical e-mail blocks for suspended accounts (#16049)
Prevent new accounts from being created using the same underlying
e-mail as a suspended account using extensions and period
permutations. Stores e-mails as a SHA256 hash
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 80689d4aa..a573365de 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -235,6 +235,7 @@ class Account < ApplicationRecord
     transaction do
       create_deletion_request!
       update!(suspended_at: date, suspension_origin: origin)
+      create_canonical_email_block!
     end
   end
 
@@ -242,6 +243,7 @@ class Account < ApplicationRecord
     transaction do
       deletion_request&.destroy!
       update!(suspended_at: nil, suspension_origin: nil)
+      destroy_canonical_email_block!
     end
   end
 
@@ -569,4 +571,16 @@ class Account < ApplicationRecord
   def clean_feed_manager
     FeedManager.instance.clean_feeds!(:home, [id])
   end
+
+  def create_canonical_email_block!
+    return unless local? && user_email.present?
+
+    CanonicalEmailBlock.create(reference_account: self, email: user_email)
+  end
+
+  def destroy_canonical_email_block!
+    return unless local?
+
+    CanonicalEmailBlock.where(reference_account: self).delete_all
+  end
 end