Sha256: 8766b699601d9446cf7280d8b912833422814225864909c79df8e7236d43a4d8

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # Translates a set of ACLs into a visibility string.
  #
  # @example
  #   resource = Hyrax::Resource.new
  #   reader   = Hyrax::VisibilityReader.new(resource: resource)
  #   reader.read # => "restricted"
  #
  #   resource.read_groups = ["public"]
  #   reader.read # => "open"
  #
  class VisibilityReader
    ##
    # @!attribute [r] permission_manager
    #   @return [Hyrax::PermissionManager]
    # @!attribute [rw] resource
    #   @return [Valkyrie::Resource]
    attr_reader   :permission_manager
    attr_accessor :resource

    ##
    # @param resource [Valkyrie::Resource::AccessControls]
    def initialize(resource:)
      self.resource = resource
      @permission_manager = resource.permission_manager
    end

    ##
    # @return [String]
    def read
      if permission_manager.read_groups.include? Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC
        visibility_map.visibility_for(group: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC)
      elsif permission_manager.read_groups.include? Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED
        visibility_map.visibility_for(group: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED)
      else
        visibility_map.visibility_for(group: :PRIVATE)
      end
    end

    def visibility_map
      Hyrax::VisibilityMap.instance
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/services/hyrax/visibility_reader.rb
hyrax-4.0.0.rc1 app/services/hyrax/visibility_reader.rb
hyrax-3.5.0 app/services/hyrax/visibility_reader.rb
hyrax-4.0.0.beta2 app/services/hyrax/visibility_reader.rb
hyrax-3.4.2 app/services/hyrax/visibility_reader.rb
hyrax-4.0.0.beta1 app/services/hyrax/visibility_reader.rb
hyrax-3.4.1 app/services/hyrax/visibility_reader.rb
hyrax-3.4.0 app/services/hyrax/visibility_reader.rb
hyrax-3.3.0 app/services/hyrax/visibility_reader.rb
hyrax-3.2.0 app/services/hyrax/visibility_reader.rb
hyrax-3.1.0 app/services/hyrax/visibility_reader.rb
hyrax-3.0.2 app/services/hyrax/visibility_reader.rb
hyrax-3.0.1 app/services/hyrax/visibility_reader.rb
hyrax-3.0.0 app/services/hyrax/visibility_reader.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/visibility_reader.rb
hyrax-3.0.0.pre.rc3 app/services/hyrax/visibility_reader.rb
hyrax-3.0.0.pre.rc2 app/services/hyrax/visibility_reader.rb