Sha256: 789f809056bd043c7db0b1e396c645dc3266b5682a9515fa55ccef1203c90deb

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

module CurationConcerns
  module Workflow
    class StatusListService
      # @param user [User]
      def initialize(user)
        @user = user
      end

      attr_reader :user

      # TODO: We will want to paginate this
      # @return [Array<StatusRow>] a list of results that the given user can take action on.
      def each
        return enum_for(:each) unless block_given?
        solr_documents.each do |doc|
          yield doc
        end
      end

      private

        # @return [Hash<String,SolrDocument>] a hash of id to solr document
        def solr_documents
          search_solr.map { |result| SolrDocument.new(result) }
        end

        def search_solr
          actionable_roles = roles_for_user
          return [] if actionable_roles.empty?
          WorkRelation.new.search_with_conditions(
            { actionable_workflow_roles_ssim: actionable_roles },
            fl: 'id title_tesim has_model_ssim, workflow_state_name_ssim',
            rows: 1000)
        end

        # @return [Array<String>] the list of workflow-role combinations this user has
        def roles_for_user
          Sipity::Workflow.all.flat_map do |wf|
            workflow_roles_for_user_and_workflow(wf).map do |wf_role|
              "#{wf.name}-#{wf_role.role.name}"
            end
          end
        end

        # @param workflow [Sipity::Workflow]
        # @return [ActiveRecord::Relation<Sipity::WorkflowRole>]
        def workflow_roles_for_user_and_workflow(workflow)
          CurationConcerns::Workflow::PermissionQuery.scope_processing_workflow_roles_for_user_and_workflow(user: user, workflow: workflow)
        end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.7 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-2.0.0 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-2.0.0.rc2 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.6 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.5 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.4 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.3 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.2 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-2.0.0.rc1 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.1 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.0 app/services/curation_concerns/workflow/status_list_service.rb
curation_concerns-1.7.0.beta1 app/services/curation_concerns/workflow/status_list_service.rb