From c4a879ac0dffcdb7d4afbb0d2d4ba9688112c7b1 Mon Sep 17 00:00:00 2001
From: jazairi <16103405+jazairi@users.noreply.github.com>
Date: Fri, 15 Sep 2023 13:49:24 -0400
Subject: [PATCH] Ensure theses are not publishable if their degree period has
no accession number
Why these changes are being introduced:
Because we want the accession number to be used in the preservation
workflow, we do not want a thesis without an accession number to
be published.
Relevant ticket(s):
https://mitlibraries.atlassian.net/browse/ETD-596
How this addresses that need:
This adds an `accession_number` convenience method to the Thesis model
that can look up an accession based on a thesis' degree period. This
method is included in the publication checks.
The thesis processing form now shows whether it can find an accession
number. If no accession number exists, the form will render a hint that
prompts the user to create an accession number for the given degree
period.
Side effects of this change:
* A future state of this application is for the Thesis model to belong
to the Degree Period model. For now, there is no direct assocation,
so we are using ActiveRecord lookups based on the thesis' graduation
year and graduation month.
* Some fixtures have been added to allow tests related to publication
status to pass. (Certain thesis fixtures had no degree periods or
accession numbers, they could not be put into publication review.)
* The `new` action on the Archivematica Accessions dashboard has been
overwritten to prefill the degree period ID from params.
---
.../archivematica_accessions_controller.rb | 7 ++
app/models/thesis.rb | 16 +++-
app/views/thesis/process_theses.html.erb | 8 ++
test/fixtures/archivematica_accessions.yml | 12 +++
test/fixtures/degree_periods.yml | 12 +++
.../admin_archivematica_accession_test.rb | 14 ++++
test/models/thesis_test.rb | 77 +++++++++++++++++++
7 files changed, 145 insertions(+), 1 deletion(-)
diff --git a/app/controllers/admin/archivematica_accessions_controller.rb b/app/controllers/admin/archivematica_accessions_controller.rb
index 559b7940..ee8795e4 100644
--- a/app/controllers/admin/archivematica_accessions_controller.rb
+++ b/app/controllers/admin/archivematica_accessions_controller.rb
@@ -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.
diff --git a/app/models/thesis.rb b/app/models/thesis.rb
index 18826619..ecd64ea7 100644
--- a/app/models/thesis.rb
+++ b/app/models/thesis.rb
@@ -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'.
@@ -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
diff --git a/app/views/thesis/process_theses.html.erb b/app/views/thesis/process_theses.html.erb
index 5dc33e59..d4cc6482 100644
--- a/app/views/thesis/process_theses.html.erb
+++ b/app/views/thesis/process_theses.html.erb
@@ -47,6 +47,14 @@
hint_html: { style: 'display: block' },
hint: link_to('See details in admin interface', admin_thesis_path(f.object), target: :_blank) %>
+