Sha256: 7c62bdc7b46177d8f6a319dde68ae74d8e49d35e4a912dd03e1a2883ebddfa6c

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 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::EXTRACTED_TEXT  => :download,
        Ddr::Datastreams::FITS            => :read,
        Ddr::Datastreams::STRUCT_METADATA => :read,
        Ddr::Datastreams::THUMBNAIL       => :read,
      }.freeze

      def call
        can :download, ActiveFedora::File do |file|
          can_download_datastream?(_dsid(file), _pid(file))
        end
      end

      private

      def _dsid(file)
        File.basename(file.id)
      end

      def _pid(file)
        File.dirname(file.id)
      end

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

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ddr-models-3.0.0.beta.9 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.8 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.7 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.6 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.alpha.4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.alpha.3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.alpha.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.alpha.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb