Sha256: 71cfe9a2722dbaf01cd67b5ec5eb4c2b90d0be96ebf6c2dbe1dd20bac1778abb

Contents?: true

Size: 1.42 KB

Versions: 16

Compression:

Stored size: 1.42 KB

Contents

module Hydra
  module Collections
    module AcceptsBatches
      
      def batch
        @batch ||= batch_ids_from_params
      end

      def batch=(val)
        @batch = val
      end
      
      # Callback to be used in before_filter
      def check_for_empty_batch?
        return batch.empty?
      end
      
      protected
      
      def batch_ids_from_params
        if params["batch_document_ids"].nil? || params["batch_document_ids"].empty?
          return []
        elsif params["batch_document_ids"] == "all"
          return Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
        else
          return params["batch_document_ids"]
        end
      end
      
      def filter_docs_with_read_access!
        filter_docs_with_access!(:read)
      end

      def filter_docs_with_edit_access!
        filter_docs_with_access!(:edit)
      end

      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
      
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hydra-collections-3.0.0.beta3 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.5 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.4 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.3 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.2 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.1 lib/hydra/collections/accepts_batches.rb
hydra-collections-2.0.0 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.3.2 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.3.1 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.3.0 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.2.0 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.2.0.rc1 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.1.0 lib/hydra/collections/accepts_batches.rb
hydra-collections-1.0.0 lib/hydra/collections/accepts_batches.rb
hydra-collections-0.0.2 lib/hydra/collections/accepts_batches.rb
hydra-collections-0.0.1 lib/hydra/collections/accepts_batches.rb