Skip to content

Commit

Permalink
Allow unblocking email addresses from any matching account (#29305)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Mar 20, 2024
1 parent 0a33be3 commit 8a1423a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def remove_header
def unblock_email
authorize @account, :unblock_email?

CanonicalEmailBlock.where(reference_account: @account).delete_all
CanonicalEmailBlock.matching_account(@account).delete_all

log_action :unblock_email, @account

Expand Down
1 change: 1 addition & 0 deletions app/models/canonical_email_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/accounts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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.exists?(reference_account_id: @account.id)
= 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?
- else
.table-wrapper
%table.table.inline-table
Expand Down
2 changes: 1 addition & 1 deletion spec/fabricators/canonical_email_block_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

Fabricator(:canonical_email_block) do
email { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } }
email { |attrs| attrs[:reference_account] ? attrs[:reference_account].user_email : sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } }
reference_account { Fabricate.build(:account) }
end

0 comments on commit 8a1423a

Please sign in to comment.