ip_block_batch.rb 546 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. class Form::IpBlockBatch
  3. include ActiveModel::Model
  4. include Authorization
  5. include AccountableConcern
  6. attr_accessor :ip_block_ids, :action, :current_account
  7. def save
  8. case action
  9. when 'delete'
  10. delete!
  11. end
  12. end
  13. private
  14. def ip_blocks
  15. @ip_blocks ||= IpBlock.where(id: ip_block_ids)
  16. end
  17. def delete!
  18. ip_blocks.each { |ip_block| authorize(ip_block, :destroy?) }
  19. ip_blocks.each do |ip_block|
  20. ip_block.destroy
  21. log_action :destroy, ip_block
  22. end
  23. end
  24. end