Sha256: 41ee1d1dc123f6c4a3788870c025e48930dba2254bde5b7203cf42c468e003cf

Contents?: true

Size: 1.06 KB

Versions: 27

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::Models::File::CONTENT         => :download,
        Ddr::Models::File::EXTRACTED_TEXT  => :download,
        Ddr::Models::File::FITS            => :read,
        Ddr::Models::File::STRUCT_METADATA => :read,
        Ddr::Models::File::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

27 entries across 27 versions & 1 rubygems

Version Path
ddr-models-3.0.0.beta.16 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.15 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.14 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.13 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.12 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.11 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.10 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb