From 89f89d738f5840c80ff938f8bf6734cdafe0fa83 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 21 May 2024 10:56:08 +0200 Subject: [PATCH] Revert "Allow unblocking email addresses from any matching account (#29305)" (#30385) --- app/controllers/admin/accounts_controller.rb | 2 +- app/models/canonical_email_block.rb | 1 - app/views/admin/accounts/show.html.haml | 2 +- spec/fabricators/canonical_email_block_fabricator.rb | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index d3be7817ff..9beb8fde6b 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -128,7 +128,7 @@ module Admin def unblock_email authorize @account, :unblock_email? - CanonicalEmailBlock.matching_account(@account).delete_all + CanonicalEmailBlock.where(reference_account: @account).delete_all log_action :unblock_email, @account diff --git a/app/models/canonical_email_block.rb b/app/models/canonical_email_block.rb index c05eb9801d..d09df6f5e2 100644 --- a/app/models/canonical_email_block.rb +++ b/app/models/canonical_email_block.rb @@ -20,7 +20,6 @@ class CanonicalEmailBlock < ApplicationRecord validates :canonical_email_hash, presence: true, uniqueness: true scope :matching_email, ->(email) { where(canonical_email_hash: email_to_canonical_email_hash(email)) } - scope :matching_account, ->(account) { matching_email(account&.user_email).or(where(reference_account: account)) } def to_log_human_identifier canonical_email_hash diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index bcf7c07314..f148b9a082 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -30,7 +30,7 @@ = render 'admin/accounts/counters', account: @account - if @account.local? && @account.user.nil? - = link_to t('admin.accounts.unblock_email'), unblock_email_admin_account_path(@account.id), method: :post, class: 'button' if can?(:unblock_email, @account) && CanonicalEmailBlock.matching_account(@account).exists? + = link_to t('admin.accounts.unblock_email'), unblock_email_admin_account_path(@account.id), method: :post, class: 'button' if can?(:unblock_email, @account) && CanonicalEmailBlock.exists?(reference_account_id: @account.id) - else .table-wrapper %table.table.inline-table diff --git a/spec/fabricators/canonical_email_block_fabricator.rb b/spec/fabricators/canonical_email_block_fabricator.rb index 2f979df794..1ef53ff4a4 100644 --- a/spec/fabricators/canonical_email_block_fabricator.rb +++ b/spec/fabricators/canonical_email_block_fabricator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Fabricator(:canonical_email_block) do - email { |attrs| attrs[:reference_account] ? attrs[:reference_account].user_email : sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } } + email { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } } reference_account { Fabricate.build(:account) } end