module CurationConcerns::Collections::AcceptsBatches

Public Instance Methods

batch() click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 4
def batch
  @batch ||= batch_ids_from_params
end
batch=(val) click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 8
def batch=(val)
  @batch = val
end
check_for_empty_batch?() click to toggle source

Callback to be used in before_filter

# File lib/curation_concerns/collections/accepts_batches.rb, line 13
def check_for_empty_batch?
  batch.empty?
end

Protected Instance Methods

batch_ids_from_params() click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 19
def batch_ids_from_params
  if params['batch_document_ids'].blank?
    []
  elsif params['batch_document_ids'] == 'all'
    CurationConcerns::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
  else
    params['batch_document_ids']
  end
end
filter_docs_with_access!(access_type = :edit) click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 37
def filter_docs_with_access!(access_type = :edit)
  no_permissions = []
  if batch.empty?
    flash[:notice] = 'Select something first'
  else
    batch.dup.each do |doc_id|
      unless can?(access_type, doc_id)
        batch.delete(doc_id)
        no_permissions << doc_id
      end
    end
    flash[:notice] = "You do not have permission to edit the documents: #{no_permissions.join(', ')}" unless no_permissions.empty?
  end
end
filter_docs_with_edit_access!() click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 33
def filter_docs_with_edit_access!
  filter_docs_with_access!(:edit)
end
filter_docs_with_read_access!() click to toggle source
# File lib/curation_concerns/collections/accepts_batches.rb, line 29
def filter_docs_with_read_access!
  filter_docs_with_access!(:read)
end