Sha256: f8135d43bfe8dcfb89caa5467b7c87f472b2d6e4ee2c9a892b130410a0fb08cb

Contents?: true

Size: 943 Bytes

Versions: 13

Compression:

Stored size: 943 Bytes

Contents

module Ddr
  module Auth
    class DatastreamAbilityDefinitions < AbilityDefinitions

      # Maps datastream id to an ability required on the object to
      # download the datastream.
      #
      # Datastreams not listed cannot be downloaded, except of
      # course by the :manage ability.
      DATASTREAM_DOWNLOAD_ABILITIES = {
        Ddr::Datastreams::CONTENT        => :download,
        Ddr::Datastreams::DESC_METADATA  => :read,
        Ddr::Datastreams::EXTRACTED_TEXT => :read,
        Ddr::Datastreams::MULTIRES_IMAGE => :read,
        Ddr::Datastreams::THUMBNAIL      => :read,
      }.freeze

      def call
        can :download, ActiveFedora::Datastream do |ds|
          can_download_datastream?(ds.dsid, ds.pid)
        end
      end

      private

      def can_download_datastream?(dsid, pid)
        can? DATASTREAM_DOWNLOAD_ABILITIES.fetch(dsid), pid
      rescue KeyError
        false
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ddr-models-2.0.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc6 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc5 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.pre.5 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.pre.4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.pre.3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.pre.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.0.0.pre.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb