about summary refs log tree commit diff
path: root/app/models/form/email_domain_block_batch.rb
blob: df120182bc290621ffbb35b3b0e332911b5a562b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class Form::EmailDomainBlockBatch
  include ActiveModel::Model
  include Authorization
  include AccountableConcern

  attr_accessor :email_domain_block_ids, :action, :current_account

  def save
    case action
    when 'delete'
      delete!
    end
  end

  private

  def email_domain_blocks
    @email_domain_blocks ||= EmailDomainBlock.where(id: email_domain_block_ids)
  end

  def delete!
    email_domain_blocks.each do |email_domain_block|
      authorize(email_domain_block, :destroy?)
      email_domain_block.destroy!
      log_action :destroy, email_domain_block
    end
  end
end