Sha256: fd680b545bf10b39fba094170c555abf278a38c9e45b7c603d028f1d049132d0

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

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 corresponding to the SolrDocument
    # with id = `blacklight_params[:id]`
    def only_active_works(solr_parameters)
      return if user_has_active_workflow_role? || depositor?
      super
    end

    private

      def current_work
        ::SolrDocument.find(blacklight_params[:id])
      end

      def user_has_active_workflow_role?
        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?
        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

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.5 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.4 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.3 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.2 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.9.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.8.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.7.2 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.7.1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.7.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.6.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-3.0.0.pre.rc1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-3.0.0.pre.beta3 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.5.1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.5.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-3.0.0.pre.beta2 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.4.1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-3.0.0.pre.beta1 app/search_builders/hyrax/filter_suppressed_with_roles.rb
hyrax-2.4.0 app/search_builders/hyrax/filter_suppressed_with_roles.rb