Add EmailDomainBlock.parents scope (#31968)

This commit is contained in:
Matt Jankowski 2024-11-07 08:46:20 -05:00 committed by GitHub
parent 6ae1fcd059
commit 697947116e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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