Sha256: d6c77bedf2840da2c527a1bf6d45a5b3dcd42592fbdf1bb33af10d6292eefded

Contents?: true

Size: 1.13 KB

Versions: 50

Compression:

Stored size: 1.13 KB

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, obj)
        permissions(obj).include? permission
      end

      def permissions(obj)
        case obj
        when Ddr::Models::Base, SolrDocument
          cached_permissions obj.pid do
            obj.effective_permissions(agents)
          end
        when String
          cached_permissions obj do
            permissions_doc(obj).effective_permissions(agents)
          end
        end
      end

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

      def permissions_doc(pid)
        roles_query_result = ActiveFedora::SolrService.query("id:\"#{pid}\"", rows: 1).first
        if roles_query_result.nil?
          raise "Solr document not found for PID \"#{pid}\"."
        end
        SolrDocument.new roles_query_result
      end

    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
ddr-models-2.4.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc6 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc5 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc4 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc3 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.4.0.rc1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.3.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.3.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.3.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-3.0.0.alpha.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-3.0.0.alpha.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.2.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.3 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.0 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.0.rc2 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb
ddr-models-2.1.0.rc1 lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb