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.8 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.7 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.6 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.5 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc6 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc5 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc4 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc3 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc2 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.rc1 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.22 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.21 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.20 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.18 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb
ddr-models-3.0.0.beta.17 lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb