Skip to content

Commit

Permalink
Merge pull request #1237 from MITLibraries/etd638-reset-pub-statues-f…
Browse files Browse the repository at this point in the history
…or-errors

Allow processors to reset publication error status
  • Loading branch information
JPrevost authored Oct 5, 2023
2 parents 2fad84a + 0363e5d commit 716268e
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/controllers/thesis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ def proquest_export
redirect_to thesis_proquest_export_preview_path
end

def reset_all_publication_errors
Thesis.where(publication_status: 'Publication error').update(publication_status: 'Not ready for publication')

flash[:success] = 'Publication error statuses have been reset'

redirect_to thesis_select_path
end

private

# Various methods need to build an array of academic terms which meet varying conditions, in order to support a UI
Expand Down
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def processor
can :publish_to_dspace, Thesis
can :proquest_export, Thesis
can :proquest_export_preview, Thesis
can :reset_all_publication_errors, Thesis
can :select, Thesis

can :read, Transfer
Expand Down
19 changes: 19 additions & 0 deletions app/views/thesis/select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
</div>
</div>

<div id="reset-publication-errors"class="gridband" style="display: none;" aria-live="polite" role="region">
<div class="inline-action well">
<div class="message">
<h4 class="title">Ready to republish everything on this list?</h4>
<p>Once you have resolved any errors, you can reset this entire list.</p>
</div>
<div class="actions">
<%= link_to "Reset all errors to Publication Review", reset_all_publication_errors_path(:graduation => params[:graduation]), class: 'button button-primary' %>
</div>
</div>
</div>

<script type="text/javascript">
function applyFilter(table, _status) {
// Update UI
Expand All @@ -67,6 +79,13 @@ function applyFilter(table, _status) {
} else {
$("#publish-to-dspace").attr('style', 'display: none;');
}

// Reveal the "Reset errors panel if warranted"
if( 'Publication error' === _status ) {
$("#reset-publication-errors").attr('style', '');
} else {
$("#reset-publication-errors").attr('style', 'display: none;');
}
}

$(document).ready( function () {
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
get 'thesis/start', to: 'thesis#start', as: 'thesis_start'
get 'thesis/proquest_export_preview', to: 'thesis#proquest_export_preview', as: 'thesis_proquest_export_preview'
get 'thesis/proquest_export', to: 'thesis#proquest_export', as: 'thesis_proquest_export'
get 'thesis/reset_all_publication_errors', to: 'thesis#reset_all_publication_errors', as: 'reset_all_publication_errors'

resources :registrar, only: [:new, :create, :show]
resources :thesis, only: [:new, :create, :edit, :show, :update]
get 'harvest', to: 'registrar#list_registrar', as: 'harvest'
Expand Down
77 changes: 77 additions & 0 deletions test/controllers/thesis_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,81 @@ def attach_files_to_records(tr, th)
follow_redirect!
assert_select '.alert-banner.warning', text: 'No theses are available to export.', count: 1
end

# ~~~~~~~~~~~~~~~~~~~~~ resetting publishing error status ~~~~~~~~~~~~~~~~~~~~~
test 'anonymous users get redirected if they try to reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

get reset_all_publication_errors_path
assert_response :redirect
assert_redirected_to '/login'

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0
end

test 'basic users cannot reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

sign_in users(:basic)
get reset_all_publication_errors_path
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0
end

test 'submitters cannot reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

sign_in users(:transfer_submitter)
get reset_all_publication_errors_path
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0
end

test 'processors can reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

sign_in users(:processor)
get reset_all_publication_errors_path
assert_redirected_to thesis_select_path

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count == 0
end

test 'thesis_admins can reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

sign_in users(:thesis_admin)
get reset_all_publication_errors_path
assert_redirected_to thesis_select_path

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count == 0
end

test 'admins can reset publishing errors' do
error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count > 0

sign_in users(:admin)
get reset_all_publication_errors_path
assert_redirected_to thesis_select_path

error_count = Thesis.where(publication_status: 'Publication error').count
assert error_count == 0
end
end
8 changes: 8 additions & 0 deletions test/fixtures/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ twentysix:
thesis: partial_proquest_wrong_term
graduation_confirmed: true
proquest_allowed: true

pub_error_one:
user: yo
thesis: publication_error

pub_error_too:
user: yo
thesis: publication_error_too
14 changes: 14 additions & 0 deletions test/fixtures/theses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,17 @@ budget_report_multiple:
departments: [one, two]
dspace_handle: 1234/5678
publication_status: Published

publication_error:
title: Errors are fun
grad_date: 2023-09-01
degrees: [two]
departments: [one]
publication_status: 'Publication error'

publication_error_too:
title: Errors are fun again
grad_date: 2023-09-01
degrees: [one]
departments: [two]
publication_status: 'Publication error'
10 changes: 5 additions & 5 deletions test/models/report_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReportTest < ActiveSupport::TestCase
# This includes a row of all zeros, which could only have been generated by populate_category
assert r.index_data['license'][3][:data].values.all? { |v| v == 0 }
# Also check that a row with expected data is represented accurately
assert_equal r.index_data['license'][1][:data].values, [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
assert_equal r.index_data['license'][1][:data].values, [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

# pad_terms is a private method that gets called by each reporting row, to ensure that all rows have some value for
Expand All @@ -39,7 +39,7 @@ class ReportTest < ActiveSupport::TestCase
returned_columns = r.index_data['summary'][3][:data].count
assert_equal expected_terms, returned_columns
# Test for a row of expected values
assert_equal r.index_data['summary'][3][:data].values, [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
assert_equal r.index_data['summary'][3][:data].values, [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
end

# ~~~~ Dashboard report
Expand All @@ -48,7 +48,7 @@ class ReportTest < ActiveSupport::TestCase
result = r.index_data
assert_equal Department.count, result['departments'].pluck(:label).length
assert_includes result['departments'].pluck(:label), Department.first.name_dw
assert_equal result['departments'][0][:data].values, [0, 2, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0]
assert_equal result['departments'][0][:data].values, [0, 2, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0]
end

test 'index includes summary data of authors not graduated' do
Expand All @@ -70,7 +70,7 @@ class ReportTest < ActiveSupport::TestCase

r = Report.new
result = r.index_data
assert_equal result['summary'][5][:data].values, [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
assert_equal result['summary'][5][:data].values, [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
end

test 'authors not graduated summary data dedups theses with multiple files' do
Expand All @@ -92,7 +92,7 @@ class ReportTest < ActiveSupport::TestCase
r = Report.new
result = r.index_data
assert_not_equal result['summary'][5][:data].values, [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
assert_equal result['summary'][5][:data].values, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
assert_equal result['summary'][5][:data].values, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

# ~~~~ Term detail report
Expand Down

0 comments on commit 716268e

Please sign in to comment.