Sha256: f3f849ff09949c1ade8159c4a23aef644fb327a4f2f79f30c3e509c46f5ef355

Contents?: true

Size: 997 Bytes

Versions: 27

Compression:

Stored size: 997 Bytes

Contents

module Ddr
  module Auth
    class RoleBasedAbilityDefinitions < AbilityDefinitions

      def call
        Permissions::ALL.each do |permission|
          can permission, [Ddr::Models::Base, 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::Models::Base, 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(pid, &block)
        cache[pid] ||= block.call
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

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