Sha256: cc1fe86110f3de84157365c16b6fc2262adb8ba666bb32c8adc9227d066df280

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true
module Hyrax
  ### Allows :deposit as a valid type
  class AdminSetSearchBuilder < ::SearchBuilder
    # This skips the filter added by FilterSuppressed
    self.default_processor_chain -= [:only_active_works]

    # @param [#repository,#blacklight_config,#current_ability] context
    # @param [Symbol] access one of :edit, :read, or :deposit
    def initialize(context, access)
      @access = access
      super(context)
    end

    # This overrides the models in FilterByType
    def models
      [::AdminSet, Hyrax::AdministrativeSet]
    end

    # Overrides Hydra::AccessControlsEnforcement
    def discovery_permissions
      if @access == :edit
        @discovery_permissions ||= ["edit"]
      else
        super
      end
    end

    # If :deposit access is requested, check to see which admin sets the user has
    # deposit or manage access to.
    # @return [Array<String>] a list of filters to apply to the solr query
    def gated_discovery_filters
      return super if @access != :deposit
      ["{!terms f=id}#{admin_set_ids_for_deposit.join(',')}"]
    end

    private

    # IDs of admin_sets into which a user can deposit.
    #
    # @return [Array<String>] IDs of admin_sets into which the user can deposit
    # @note Several checks get the user's groups from the user's ability.  The same values can be retrieved directly from a passed in ability.
    def admin_set_ids_for_deposit
      Hyrax::Collections::PermissionsService.source_ids_for_deposit(ability: current_ability)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-5.0.0.rc1 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.6.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0.rc3 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0.rc2 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0.rc1 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.5.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0.beta2 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.4.2 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-4.0.0.beta1 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.4.1 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.4.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.3.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.2.0 app/search_builders/hyrax/admin_set_search_builder.rb
hyrax-3.1.0 app/search_builders/hyrax/admin_set_search_builder.rb