Sha256: dd418e4e6e8fe7a74fd5ab9644568b53ddd07c235e302e1c290b78b155d2138e

Contents?: true

Size: 1.54 KB

Versions: 25

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true
module Hyrax
  class InspectWorkPresenter
    def initialize(solr_document, current_ability)
      @solr_document = solr_document
      @current_ability = current_ability
    end
    attr_reader :solr_document, :current_ability

    def workflow
      return { comments: [], roles: [] } unless sipity_entity
      {
        entity_id: sipity_entity.id,
        proxy_for: sipity_entity.proxy_for_global_id,
        workflow_id: sipity_entity.workflow_id,
        workflow_name: sipity_entity.workflow_name,
        state_id: sipity_entity.workflow_state_id,
        state_name: sipity_entity.workflow_state_name,
        comments: workflow_comments,
        roles: sipity_entity_roles
      }
    end

    def solr
      @solr_document.inspect
    end

    private

    def sipity_entity
      @sipity_entity ||= Sipity::Entity(solr_document)
    end

    def sipity_entity_roles
      roles = Workflow::PermissionQuery.scope_roles_associated_with_the_given_entity(entity: solr_document)
      roles.map do |role|
        { id: role.id, name: role.name, description: role.description, users: sipity_entity_role_users(role) }
      end
    end

    def sipity_entity_role_users(role)
      users = Workflow::PermissionQuery.scope_users_for_entity_and_roles(entity: sipity_entity, roles: role)
      users.map(&:user_key)
    end

    def workflow_comments
      return [] unless sipity_entity&.comments&.any?
      sipity_entity.comments.map do |comment|
        { comment: comment.comment, created_at: comment.created_at }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-5.0.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.6.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.5.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.4.2 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-4.0.0.beta1 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.4.1 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.4.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.3.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.2.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.1.0 app/presenters/hyrax/inspect_work_presenter.rb
hyrax-3.0.2 app/presenters/hyrax/inspect_work_presenter.rb