Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug with workflow pagination - updates overridden hyrax files #610

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/services/hyrax/solr_query_service_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# OVERRIDE: Hyrax 3.4.1 changes GET request to POST to allow for larger query size
# OVERRIDE: Hyrax 3.6.0 changes GET request to POST to allow for larger query size

# frozen_string_literal: true

module Hyrax
module SolrQueryServiceDecorator
def get
solr_service.post(build)
def get(*args)
solr_service.post(build, *args)
end
end
end
Expand Down
41 changes: 32 additions & 9 deletions app/services/hyrax/workflow/permission_query.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# OVERRIDE Hyrax v3.4.2 Expand functionality for Groups with Roles Feature
# OVERRIDE Hyrax v3.6.0 Expand functionality for Groups with Roles Feature
# @see https://github.com/samvera/hyku/wiki/Groups-with-Roles-Feature
# rubocop:disable Metrics/ModuleLength
module Hyrax
Expand Down Expand Up @@ -73,7 +73,8 @@ def scope_permitted_workflow_actions_available_for_current_state(user:, entity:)
# @param role [Object] that can be converted into a Sipity::Role
# @return [ActiveRecord::Relation<Sipity::Agent>] augmented with
#
def scope_agents_associated_with_entity_and_role(entity:, role:) # rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/MethodLength
def scope_agents_associated_with_entity_and_role(entity:, role:)
entity = Sipity::Entity(entity)
role = Sipity::Role(role)

Expand Down Expand Up @@ -196,7 +197,8 @@ def scope_processing_agents_for(user:)
#
# @return [ActiveRecord::Relation<Sipity::Entity>]
#
def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def scope_entities_for_the_user(user:, page: 1, per_page: nil, workflow_state_filter: nil)
entities = Sipity::Entity.arel_table
workflow_state_actions = Sipity::WorkflowStateAction.arel_table
workflow_states = Sipity::WorkflowState.arel_table
Expand Down Expand Up @@ -229,13 +231,34 @@ def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize
entity_specific_where = where_builder.call(entity_responsibilities).and(
entities[:id].eq(entity_responsibilities[:entity_id])
)
entity_specific_where = filter_by_workflow_state(entity_specific_where, workflow_states, workflow_state_filter) if workflow_state_filter
workflow_specific_where = where_builder.call(workflow_responsibilities)
workflow_specific_where = filter_by_workflow_state(workflow_specific_where, workflow_states, workflow_state_filter) if workflow_state_filter

Sipity::Entity.where(
result = Sipity::Entity.where(
entities[:id].in(entity_specific_joins.where(entity_specific_where))
.or(entities[:id].in(workflow_specific_joins.where(workflow_specific_where)))
)
# Apply paging if provided
if per_page.nil?
result
else
result.page(page).per(per_page)
end
end

# @api private
#
# Append a filter by workflow state name to the provided where builder.
# If the filter begins with a !, it will filter to states not equal to the filter.
def filter_by_workflow_state(where_builder, workflow_states, filter)
if filter.start_with?('!')
where_builder.and(workflow_states[:name].not_eq(filter[1..-1]))
else
where_builder.and(workflow_states[:name].eq(filter))
end
end

# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

# @api public
Expand All @@ -251,7 +274,8 @@ def scope_entities_for_the_user(user:) # rubocop:disable Metrics/AbcSize
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<User>]
#
def scope_users_for_entity_and_roles(entity:, roles:) # rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def scope_users_for_entity_and_roles(entity:, roles:)
entity = Sipity::Entity(entity)
role_ids = Array.wrap(roles).map { |role| Sipity::Role(role).id }
user_polymorphic_type = ::User.base_class
Expand Down Expand Up @@ -347,7 +371,7 @@ def scope_processing_workflow_roles_for_user_and_workflow(user:, workflow:)
# @param user [User]
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<Sipity::WorkflowRole>]
def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:)
def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:) # rubocop:disable Metrics/MethodLength
entity = Sipity::Entity(entity)
agent_scope = scope_processing_agents_for(user: user)

Expand Down Expand Up @@ -386,7 +410,7 @@ def scope_processing_workflow_roles_for_user_and_entity_specific(user:, entity:)
# @param entity an object that can be converted into a Sipity::Entity
# @return [ActiveRecord::Relation<Sipity::WorkflowStateAction>]
#
def scope_permitted_entity_workflow_state_actions(user:, entity:)
def scope_permitted_entity_workflow_state_actions(user:, entity:) # rubocop:disable Metrics/MethodLength
entity = Sipity::Entity(entity)
workflow_state_actions = Sipity::WorkflowStateAction
permissions = Sipity::WorkflowStateActionPermission
Expand Down Expand Up @@ -446,5 +470,4 @@ def scope_workflow_actions_available_for_current_state(entity:)
end
end
end
end
# rubocop:enable Metrics/ModuleLength
end
143 changes: 59 additions & 84 deletions app/views/hyrax/admin/workflows/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,95 +1,70 @@
<%# OVERRIDE: Hyrax v3.5.0 to show the user/depositor's display_name if available %>
<%# OVERRIDE: Hyrax v3.6.0 to show the user/depositor's display_name if available %>

<% provide :page_header do %>
<h1><span class="fa fa-check-circle"></span> <%= t('.header') %></h1>
<h1><span class="glyphicon glyphicon-ok-circle"></span> <%= t('.header') %></h1>
<% end %>

<div class="row">
<div class="col-md-12">
<div class="card tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item active">
<a class="nav-link" href="#under-review" role="tab" data-toggle="tab"><%= t('.tabs.under_review') %></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#published" role="tab" data-toggle="tab"><%= t('.tabs.published') %></a>
</li>
</ul>
<div class="tab-content">
<div id="under-review" class="tab-pane active">
<div class="card labels">
<div class="card-body">
<div class="table-responsive">
<table class="table table-sm table-striped datatable">
<thead>
<tr>
<th width="40%">Work</th>
<th width="20%">Depositor</th>
<th width="20%">Submission Date</th>
<th width="20%">Status</th>
</tr>
</thead>
<tbody>
<% @status_list.each do |document| %>
<tr>
<td>
<%= link_to document, [main_app, document] %>
</td>
<td>
<%# OVERRIDE: show the user/depositor's display_name if available %>
<% user = User.find_by(email: document.depositor) %>
<%= user&.display_name.presence %>
</td>
<td>
<%= document.date_modified %>
</td>
<td>
<span class="state state-pending"><%= document.workflow_state %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="published" class="tab-pane">
<div class="card labels">
<div class="card-body">
<div class="table-responsive">
<table class="table table-sm table-striped datatable">
<thead>
<tr>
<th width="40%">Work</th>
<th width="20%">Depositor</th>
<th width="20%">Submission Date</th>
<th width="20%">Status</th>
</tr>
</thead>
<tbody>
<% @published_list.each do |document| %>
<tr>
<td>
<%= link_to document, [main_app, document] %>
</td>
<td>
<%# OVERRIDE: show the user/depositor's display_name if available %>
<% user = User.find_by(email: document.depositor) %>
<%= user&.display_name.presence %>
<td>
<%= document.date_modified %>
</td>
<td>
<span class="state state-pending"><%= document.workflow_state %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="panel panel-default tabs">
<%= render 'tabs' %>
<div class="panel-heading">
<span class="count-display">
<% if @response.viewing_under_review? %>
<%= I18n.t('hyrax.admin.workflows.index.works_under_review', total_count: @response.total_count).html_safe %>
<% else %>
<%= I18n.t('hyrax.admin.workflows.index.works_published', total_count: @response.total_count).html_safe %>
<% end %>
</span>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<div class="sort-toggle mt-2">
<%= form_tag hyrax.admin_workflows_path, method: :get, class: 'per_page' do %>
<fieldset class="col-12">
<legend class="sr-only"><%= t('hyrax.dashboard.my.sr.results_per_page') %></legend>
<%= label_tag :per_page do %>
Show <%= select_tag :per_page, options_for_select(Hyrax.config.range_for_number_of_results_to_display_per_page.map(&:to_s), h(params[:per_page])), title: "entries" %> per page
<% end %>
<%= render_hash_as_hidden_fields(search_state.params_for_search.except(:per_page, :sort, :utf8)) %>
</fieldset>
<% end %>
</div>
</div>
</div>
<h2 class="sr-only"><%= t('.works_listing') %></h2>
<table class="table table-sm table-striped works-list">
<thead>
<tr>
<th width="40%"><%= t(".heading.work") %></th>
<th width="20%"><%= t(".heading.depositor") %></th>
<th width="20%"><%= t(".heading.submission_date") %></th>
<th width="20%"><%= t(".heading.status") %></th>
</tr>
</thead>
<tbody>
<% @response.docs.each do |document| %>
<tr>
<td>
<%= link_to document, [main_app, document] %>
</td>
<td>
<%# OVERRIDE: show the user/depositor's display_name if available %>
<% user = User.find_by(email: document.depositor) %>
<%= user&.display_name.presence %>
</td>
<td>
<%= document.date_modified %>
</td>
<td>
<span class="state state-pending"><%= document.workflow_state %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render 'hyrax/my/results_pagination' %>
</div>
</div>
</div>
Expand Down