Sha256: 1932aa2e3977f047bcb962b6fe3199ebec5edc2d7fd55f7b713d851e028805d3

Contents?: true

Size: 1.7 KB

Versions: 16

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true
module Hyrax
  # Overrides FilterSuppressed filter to hide documents marked as
  # suppressed when the current user is permitted to take no workflow
  # actions for the work's current state
  #
  # Assumes presence of `blacklight_params[:id]` and a SolrDocument
  # corresponding to that `:id` value
  module FilterSuppressedWithRoles
    extend ActiveSupport::Concern
    include FilterSuppressed

    # Skip the filter if the current user is:
    #
    # *  permitted to take workflow actions on the work
    # *  the depositor
    #
    # corresponding to the SolrDocument with id = `blacklight_params[:id]`
    #
    # @note This is another case in which the Sipity workflows and the
    #       SOLR permissions are not adequately synchronized.  Sipity COULD
    #       be used to include that information, however that is not
    #       presently scoped work.
    def only_active_works(solr_parameters)
      current_work = ::SolrDocument.find(blacklight_params[:id])
      return if user_has_active_workflow_role?(current_work: current_work)
      return if depositor?(current_work: current_work)
      super
    end

    private

    def user_has_active_workflow_role?(current_work:)
      Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(user: current_ability.current_user, entity: current_work).any?
    rescue PowerConverter::ConversionError
      # The current_work doesn't have a sipity workflow entity
      false
    end

    def depositor?(current_work:)
      depositors = current_work[DepositSearchBuilder.depositor_field]

      return false if depositors.nil?

      depositors.first == current_ability.current_user.user_key
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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