Sha256: 5a77b79fd6ab8d03ec49cb882fb0f7b51664d5ed706e5ee147ad39b40ff863a9

Contents?: true

Size: 1.36 KB

Versions: 48

Compression:

Stored size: 1.36 KB

Contents

module Hyrax
  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?
        batch.empty?
      end

      private

        def batch_ids_from_params
          if params['batch_document_ids'].blank?
            []
          elsif params['batch_document_ids'] == 'all'
            SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
          else
            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

48 entries across 48 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.5 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.4 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.3 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.2 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.9.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.8.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.7.2 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.7.1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.7.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.6.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-3.0.0.pre.rc1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-3.0.0.pre.beta3 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.5.1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.5.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-3.0.0.pre.beta2 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.4.1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-3.0.0.pre.beta1 app/controllers/concerns/hyrax/collections/accepts_batches.rb
hyrax-2.4.0 app/controllers/concerns/hyrax/collections/accepts_batches.rb