Sha256: 13ad44c598333821952d656adcf5062dffeb73a9a4c6917a28917e5c2262bb7a

Contents?: true

Size: 995 Bytes

Versions: 40

Compression:

Stored size: 995 Bytes

Contents

module Ddr
  module Auth
    class RoleBasedAbilityDefinitions < AbilityDefinitions

      def call
        Permissions::ALL.each do |permission|
          can permission, [ Ddr::Resource, ::SolrDocument, String ] do |obj|
            has_permission? permission, obj
          end
        end
      end

      private

      def has_permission?(permission, object_or_id)
        permissions(object_or_id).include? permission
      end

      def permissions(object_or_id)
        case object_or_id
        when Ddr::Resource, ::SolrDocument
          cached_permissions(object_or_id.id) do
            object_or_id.effective_permissions(agents)
          end
        when String
          cached_permissions(object_or_id) do
            doc = ::SolrDocument.find(object_or_id) # raises SolrDocument::NotFound
            doc.effective_permissions(agents)
          end
        end
      end

      def cached_permissions(id, &block)
        cache[id] ||= block.call
      end

    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ddr-core-1.17.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.16.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.15.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.14.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.13.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.13.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.13.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.12.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.12.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.12.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.11.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.10.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.9.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.8.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.7.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.6.6 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.6.5 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.6.4 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.6.3 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-core-1.6.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb