ip_block_batch.rb 629 B

1234567891011121314151617181920212223242526272829303132333435
  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. verify_authorization(:destroy?)
  19. ip_blocks.each do |ip_block|
  20. ip_block.destroy
  21. log_action :destroy, ip_block
  22. end
  23. end
  24. def verify_authorization(permission)
  25. ip_blocks.each { |ip_block| authorize(ip_block, permission) }
  26. end
  27. end