diff --git a/app/controllers/admin/email_domain_blocks_controller.rb b/app/controllers/admin/email_domain_blocks_controller.rb index faa0a061a6..fe822d8c99 100644 --- a/app/controllers/admin/email_domain_blocks_controller.rb +++ b/app/controllers/admin/email_domain_blocks_controller.rb @@ -5,7 +5,7 @@ module Admin def index authorize :email_domain_block, :index? - @email_domain_blocks = EmailDomainBlock.where(parent_id: nil).includes(:children).order(id: :desc).page(params[:page]) + @email_domain_blocks = EmailDomainBlock.parents.includes(:children).order(id: :desc).page(params[:page]) @form = Form::EmailDomainBlockBatch.new end diff --git a/app/models/email_domain_block.rb b/app/models/email_domain_block.rb index f3a86eae8f..583d2e6c1b 100644 --- a/app/models/email_domain_block.rb +++ b/app/models/email_domain_block.rb @@ -28,6 +28,8 @@ class EmailDomainBlock < ApplicationRecord validates :domain, presence: true, uniqueness: true, domain: true + scope :parents, -> { where(parent_id: nil) } + # Used for adding multiple blocks at once attr_accessor :other_domains diff --git a/lib/mastodon/cli/email_domain_blocks.rb b/lib/mastodon/cli/email_domain_blocks.rb index 4aa31f8af8..7b2da8ef9f 100644 --- a/lib/mastodon/cli/email_domain_blocks.rb +++ b/lib/mastodon/cli/email_domain_blocks.rb @@ -7,11 +7,11 @@ module Mastodon::CLI class EmailDomainBlocks < Base desc 'list', 'List blocked e-mail domains' def list - EmailDomainBlock.where(parent_id: nil).find_each do |entry| - say(entry.domain.to_s, :white) + EmailDomainBlock.parents.find_each do |parent| + say(parent.domain.to_s, :white) shell.indent do - EmailDomainBlock.where(parent_id: entry.id).find_each do |child| + EmailDomainBlock.where(parent_id: parent.id).find_each do |child| say(child.domain, :cyan) end end