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

Ensure theses are not publishable without an accession number #1222

Merged
merged 1 commit into from
Sep 25, 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
7 changes: 7 additions & 0 deletions app/controllers/admin/archivematica_accessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class ArchivematicaAccessionsController < Admin::ApplicationController
# send_foo_updated_email(requested_resource)
# end

def new
resource = ArchivematicaAccession.new(degree_period_id: params[:degree_period_id])
render locals: {
page: Administrate::Page::Form.new(dashboard, resource)
}
end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
Expand Down
16 changes: 15 additions & 1 deletion app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class Thesis < ApplicationRecord

enum proquest_exported: ['Not exported', 'Full harvest', 'Partial harvest']

# Looks up the thesis' accession number based on its degree period.
def accession_number
degree_period = look_up_degree_period
return if degree_period.nil?
return if degree_period.archivematica_accession.nil?

degree_period.archivematica_accession.accession_number
end

def look_up_degree_period
DegreePeriod.find_by(grad_year: graduation_year, grad_month: graduation_month)
end

# Returns a true/false value (rendered as "yes" or "no") if there are any
# holds with a status of either 'active' or 'expired'. A false/"No" is
# only returned if all holds are 'released'.
Expand Down Expand Up @@ -189,7 +202,8 @@ def evaluate_status
no_active_holds?,
authors_graduated?,
departments_have_dspace_name?,
degrees_have_types?
degrees_have_types?,
accession_number.present?
].all?
end

Expand Down
8 changes: 8 additions & 0 deletions app/views/thesis/process_theses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
hint_html: { style: 'display: block' },
hint: link_to('See details in admin interface', admin_thesis_path(f.object), target: :_blank) %>
</li>
<li>
<%= f.input :accession_number?, as: :string,
readonly: true,
label_html: { style: 'width: 50%' },
input_html: { class: 'disabled', style: 'width: 40%', value: f.object.accession_number.present?? 'Yes' : 'No' },
hint_html: { style: 'display: block' },
hint: (link_to('Create new accession number', new_admin_archivematica_accession_path(degree_period_id: f.object.look_up_degree_period), target: :_blank) if f.object.accession_number.nil?) %>
</li>
<li>
<fieldset>
<legend>Issues found</legend>
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/archivematica_accessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@
valid_number_and_degree_period:
accession_number: '2023_001'
degree_period: june_2023

september_2017_001:
accession_number: '2017_001'
degree_period: september_2017

june_2018_001:
accession_number: '2018_001'
degree_period: june_2018

june_2021_001:
accession_number: '2021_001'
degree_period: june_2021
12 changes: 12 additions & 0 deletions test/fixtures/degree_periods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ june_2023:
no_archivematica_accessions:
grad_month: 'May'
grad_year: '2024'

september_2017:
grad_month: 'September'
grad_year: '2017'

june_2018:
grad_month: 'June'
grad_year: '2018'

june_2021:
grad_month: 'June'
grad_year: '2021'
14 changes: 14 additions & 0 deletions test/integration/admin/admin_archivematica_accession_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,18 @@ def teardown
delete admin_archivematica_accession_path(archivematica_accession)
assert_not ArchivematicaAccession.exists?(archivematica_accession_id)
end

test 'new form can be prefilled with degree period' do
mock_auth users(:thesis_admin)
get new_admin_archivematica_accession_path, params: { degree_period_id: degree_periods(:june_2023).id }
assert_select 'select#archivematica_accession_degree_period_id', count: 1
assert_select 'option', text: 'June 2023', count: 1
end

test 'new form can be loaded with no prefilled degree period' do
mock_auth users(:thesis_admin)
get new_admin_archivematica_accession_path
assert_select 'select#archivematica_accession_degree_period_id', count: 1
assert_select 'option', text: '', count: 1
end
end
77 changes: 77 additions & 0 deletions test/models/thesis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def attach_file_with_purpose_to(thesis, purpose = 'thesis_pdf')
assert_equal true, thesis.no_active_holds?
assert_equal true, thesis.departments_have_dspace_name?
assert_equal true, thesis.degrees_have_types?
assert_equal true, thesis.accession_number.present?
assert_equal 'Publication review', thesis.publication_status
# Attempting to set a different status will be overwritten by the update_status method
thesis.publication_status = 'Not ready for publication'
Expand Down Expand Up @@ -1442,4 +1443,80 @@ def attach_file_with_purpose_to(thesis, purpose = 'thesis_pdf')
assert_not_includes Thesis.ready_for_proquest_export, wrong_term_full_export_thesis
assert_not_includes Thesis.ready_for_proquest_export, no_export_thesis
end

test 'can look up accession number' do
t = theses(:one)

# a thesis needs a grad date to have an accession number
assert_not t.grad_date.nil?
assert_not t.accession_number.nil?
end

test 'accession number matches expectations' do
t = theses(:one)
assert t.accession_number.starts_with? t.graduation_year
end

test 'can look up degree period' do
thesis = theses(:one)

# Ensure the thesis has a degree period
assert_not_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month)

# Ensure that degree period lookup returns the appropriate record
degree_period = thesis.look_up_degree_period
assert_equal thesis.graduation_year, degree_period.grad_year
assert_equal thesis.graduation_month, degree_period.grad_month
end

test 'returns nil on degree period lookup if no degree period exists' do
thesis = theses(:one)

# Ensure the thesis has no degree period
thesis.graduation_year = '3000'
thesis.save
assert_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month)

# Ensure that degree period lookup also returns nil
assert_nil thesis.look_up_degree_period
end

test 'bachelor theses cannot be put into publication review without accession number' do
t = theses(:bachelor)
t.save
t.reload
assert_equal 'Publication review', t.publication_status

t.graduation_year = '3000'
t.save
t.reload
assert_nil t.accession_number
assert_not_equal 'Publication review', t.publication_status
end

test 'master theses cannot be put into publication review without an accession number' do
t = theses(:master)
t.save
t.reload
assert_equal 'Publication review', t.publication_status

t.graduation_year = '3000'
t.save
t.reload
assert_nil t.accession_number
assert_not_equal 'Publication review', t.publication_status
end

test 'doctoral theses cannot be put into publication review without an accession number' do
t = theses(:doctor)
t.save
t.reload
assert_equal 'Publication review', t.publication_status

t.graduation_year = '3000'
t.save
t.reload
assert_nil t.accession_number
assert_not_equal 'Publication review', t.publication_status
end
end
Loading