Sha256: d484a33f59e074065517463e85dd63cd1f5939ba0b7511ccf6ae473ca7ca080f

Contents?: true

Size: 1.71 KB

Versions: 27

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true
module Hyrax
  module WorkflowsHelper
    # Does a workflow restriction exist for the given :object and
    # given :ability?
    #
    # @note If the object responds to a :workflow_restriction?, we'll
    #       use that answer.
    #
    # This method doesn't answer what kind of restriction is in place
    # (that requires a far more nuanced permissioning system than
    # Hyrax presently has).  Instead, it answers is there one in
    # place.  From that answer, you may opt out of rendering a region
    # on a view (e.g. don't show links to the edit page).
    #
    # @param object [Object]
    # @param ability [Ability]
    #
    # @return [false] when there are no applicable workflow restrictions
    #
    # @return [true] when there is an applicable workflow restriction,
    #         and you likely want to not render something.
    #
    # @note This is Jeremy, I encourage you to look at the views that
    #       call this method to understand the conceptual space this
    #       method covers.
    #
    # @todo As I noodle on this, I'm fairly certain we should be
    #       registering a CanCan ability check.  I believe in
    #       promoting this to a helper method it will be easier to
    #       incorporate this into an ability.
    #
    # @see Hyrax::FileSetsController for non-view usage.
    def workflow_restriction?(object, ability: current_ability)
      return false if object.nil? # Yup, we may get nil, and there's no restriction on nil
      return object.workflow_restriction? if object.respond_to?(:workflow_restriction?)
      return false if ability.can?(:edit, object)
      return object.suppressed? if object.respond_to?(:suppressed?)
      false
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.4 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.3 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.2 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.1 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.0 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.0.rc3 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.0.rc2 app/helpers/hyrax/workflows_helper.rb
hyrax-5.0.0.rc1 app/helpers/hyrax/workflows_helper.rb
hyrax-3.6.0 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0.rc3 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0.rc2 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0.rc1 app/helpers/hyrax/workflows_helper.rb
hyrax-3.5.0 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0.beta2 app/helpers/hyrax/workflows_helper.rb
hyrax-3.4.2 app/helpers/hyrax/workflows_helper.rb
hyrax-4.0.0.beta1 app/helpers/hyrax/workflows_helper.rb
hyrax-3.4.1 app/helpers/hyrax/workflows_helper.rb
hyrax-3.4.0 app/helpers/hyrax/workflows_helper.rb