diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 89c81f766a..baf5c3973b 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -7,6 +7,9 @@ class DomainBlock < ApplicationRecord validates :domain, presence: true, uniqueness: true + has_many :accounts, foreign_key: :domain, primary_key: :domain + delegate :count, to: :accounts, prefix: true + def self.blocked?(domain) where(domain: domain, severity: :suspend).exists? end diff --git a/app/views/admin/domain_blocks/show.html.haml b/app/views/admin/domain_blocks/show.html.haml index 49933cbd99..70dfef9b2d 100644 --- a/app/views/admin/domain_blocks/show.html.haml +++ b/app/views/admin/domain_blocks/show.html.haml @@ -9,7 +9,7 @@ label: t(".retroactive.#{@domain_block.severity}"), hint: t(:affected_accounts, scope: [:admin, :domain_blocks, :show], - count: Account.where(domain: @domain_block.domain).count) + count: @domain_block.accounts_count) .actions = f.button :button, t('.undo'), type: :submit