Sha256: a13ce19054b635626b37c8fc1e6c3f9ecbf9e6b93e2cbc43e2a471070e6838d8

Contents?: true

Size: 1.03 KB

Versions: 65

Compression:

Stored size: 1.03 KB

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  => :download,
        Ddr::Datastreams::FITS            => :read,
        Ddr::Datastreams::MULTIRES_IMAGE  => :read,
        Ddr::Datastreams::STRUCT_METADATA => :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

65 entries across 65 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.10.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.10.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.10.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.10.0.rc2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.10.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.9.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.9.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.9.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.9.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.8.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.8.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.6 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.5 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-2.7.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb