module ActiveScaffold::Actions::BatchDestroy

Public Class Methods

included(base) click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 4
def self.included(base)
  base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
  base.before_action :batch_destroy_authorized_filter, :only => [:batch_destroy]
end

Public Instance Methods

batch_destroy() click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 9
def batch_destroy
  batch_action
end

Protected Instance Methods

batch_destroy_authorized?(record = nil) click to toggle source

The default security delegates to ActiveRecordPermissions. You may override the method to customize.

# File lib/active_scaffold/actions/batch_destroy.rb, line 62
def batch_destroy_authorized?(record = nil)
  authorized_for?(:crud_type => :delete)
end
batch_destroy_listed() click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 18
def batch_destroy_listed
  case active_scaffold_config.batch_destroy.process_mode
  when :delete then
    each_record_in_scope do |record|
      destroy_record(record) if authorized_for_job?(record)
    end
  when :delete_all then
    do_search if respond_to? :do_search, true
    # dummy condition cause we have to call delete_all on relation not on association
    beginning_of_chain.where('1=1').delete_all(all_conditions)
  else
    Rails.logger.error("Unknown process_mode: #{active_scaffold_config.batch_destroy.process_mode} for action batch_destroy")
  end
  
end
batch_destroy_marked() click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 34
def batch_destroy_marked
  case active_scaffold_config.batch_destroy.process_mode
  when :delete then
    each_marked_record do |record|
      destroy_record(record) if authorized_for_job?(record)
    end
  when :delete_all then
    active_scaffold_config.model.where(active_scaffold_config.model.primary_key => marked_records.to_a).delete_all
    do_demark_all
  else
    Rails.logger.error("Unknown process_mode: #{active_scaffold_config.batch_destroy.process_mode} for action batch_destroy")
  end
end
batch_destroy_marked_ignore?(record = nil) click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 66
def batch_destroy_marked_ignore?(record = nil)
  !active_scaffold_config.actions.include? :mark
end
before_do_batch_destroy() click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 15
def before_do_batch_destroy
end
destroy_record(record) click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 48
def destroy_record(record)
  @successful = nil
  @record = record

  do_destroy(record)
  if successful?
    @record.as_marked = false if batch_scope == 'MARKED'
  else
    error_records << @record
  end
end

Private Instance Methods

batch_destroy_authorized_filter() click to toggle source
# File lib/active_scaffold/actions/batch_destroy.rb, line 72
def batch_destroy_authorized_filter
  link = active_scaffold_config.batch_destroy.link || active_scaffold_config.batch_destroy.class.link
  raise ActiveScaffold::ActionNotAllowed unless self.send(link.first.security_method)
end