about summary refs log tree commit diff
path: root/app/models/form/ip_block_batch.rb
blob: f6fe9b59357779c59c3f0db4d91acb3e22d024db (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
31
# frozen_string_literal: true

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

  attr_accessor :ip_block_ids, :action, :current_account

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

  private

  def ip_blocks
    @ip_blocks ||= IpBlock.where(id: ip_block_ids)
  end

  def delete!
    ip_blocks.each { |ip_block| authorize(ip_block, :destroy?) }

    ip_blocks.each do |ip_block|
      ip_block.destroy
      log_action :destroy, ip_block
    end
  end
end