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

Adds report for thesis files with no defined purpose #795

Merged
merged 1 commit into from
Oct 4, 2021
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
8 changes: 8 additions & 0 deletions app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ class ReportController < ApplicationController

include ThesisHelper

def files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to consider a more explicit name for this. In the future looking at this method it won't be clear that this is really for the files_with_no_defined_purpose versus some generic files route without having to poke around further.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fair, but I'd like to move this to a different name once we have an idea of what the alternative report is going to be. Looking at the current reporting epic in Jira, no other requested report seems likely to overlap with this method.

report = Report.new
theses = Thesis.all
@terms = report.extract_terms theses
subset = filter_theses_by_term theses
@list = report.list_unattached_files subset
end

def index
report = Report.new
@terms = Thesis.pluck(:grad_date).uniq.sort
Expand Down
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def processor

can :manage, :submitter

can :files, Report
can :index, Report
can :term, Report

Expand Down
10 changes: 10 additions & 0 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ def extract_terms(collection)
collection.pluck(:grad_date).uniq.sort
end

def list_unattached_files(collection)
result = []
collection.joins(:files_attachments).order(:grad_date).uniq.each do |record|
record.files.where(purpose: nil).each do |file|
result.push(file)
end
end
result
end

def table_copyright(collection)
result = {}
collection.group(:copyright).count.each do |record|
Expand Down
3 changes: 3 additions & 0 deletions app/views/report/_files_empty.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<tr>
<td colspan="4">There are no files without an assigned purpose within the selected term.</td>
</tr>
14 changes: 14 additions & 0 deletions app/views/report/_files_without_purpose.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<tr>
<td><%= link_to(files_without_purpose.blob[:filename],thesis_process_path(files_without_purpose[:record_id])) %></td>
<td>
<% files_without_purpose.record.authors.each do |author| %>
<%= author.user.display_name %><br>
<% end %>
</td>
<td>
<% files_without_purpose.record.departments.each do |dept| %>
<%= dept.name_dw %><br>
<% end %>
</td>
<td><%= files_without_purpose[:description] %></td>
</tr>
30 changes: 30 additions & 0 deletions app/views/report/files.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= content_for(:title, "Thesis Reporting | MIT Libraries") %>

<div class="layout-3q1q layout-band">
<div class="col3q">
<h3 class="title title-page">Files without a defined purpose</h3>

<%= render 'shared/defined_terms_filter' %>

<table class="table" summary="This table presents a list of files which are attached to theses but which have no purpose defined.
Clicking the link in the left column will take you to the processing form for that thesis, where a purpose can
be declared." title="Files without a defined purpose">
<thead>
<tr>
<th scope="col">File</th>
<th scope="col">Authors</th>
<th scope="col">Departments</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<%= render(partial: 'report/files_without_purpose', collection: @list) || render('files_empty') %>
</tbody>
</table>

</div>

<aside class="content-sup col1q-r">
<%= render 'shared/report_submenu' %>
</aside>
</div>
3 changes: 3 additions & 0 deletions app/views/shared/_report_submenu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<% if can?(:select, Thesis) %>
<li><%= link_to("Theses with co-authors", thesis_deduplicate_path) %></li>
<% end %>
<% if can?(:files, Report) %>
<li><%= link_to("Files without purpose", report_files_path) %></li>
<% end %>
</ul>
</nav>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
end

get 'report', to: 'report#index', as: 'report_index'
get 'report/files', to: 'report#files', as: 'report_files'
get 'report/term', to: 'report#term', as: 'report_term'
get 'thesis/confirm', to: 'thesis#confirm', as: 'thesis_confirm'
get 'thesis/deduplicate', to: 'thesis#deduplicate', as: 'thesis_deduplicate'
Expand Down
104 changes: 104 additions & 0 deletions test/controllers/report_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
require 'test_helper'

class ReportControllerTest < ActionDispatch::IntegrationTest
def attach_files(tr, th)
# Ideally our fixtures would have already-attached files, but they do not
# yet. So we attach two files to a transfer and thesis record, to prepare
# for tests with an accurate set of file attachments.
f1 = Rails.root.join('test', 'fixtures', 'files', 'a_pdf.pdf')
f2 = Rails.root.join('test', 'fixtures', 'files', 'a_pdf.pdf')
tr.files.attach(io: File.open(f1), filename: 'a_pdf.pdf')
tr.files.attach(io: File.open(f2), filename: 'a_pdf.pdf')
tr.save
tr.reload
th.files.attach(tr.files.first.blob)
th.files.attach(tr.files.second.blob)
th.save
th.reload
end

# ~~~~~~~~~~~~~~~~~~~~ Report dashboard ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test 'summary report exists' do
sign_in users(:admin)
get report_index_path
Expand Down Expand Up @@ -120,4 +137,91 @@ class ReportControllerTest < ActionDispatch::IntegrationTest
assert_select '.card-overall .message', text: '2 thesis records', count: 1
assert_response :success
end

# ~~~~~~~~~~~~~~~~~~~~ Files without purpose report ~~~~~~~~~~~~~~~~~~~~~~~~
test 'files report exists' do
sign_in users(:admin)
get report_files_path
assert_response :success
end

test 'anonymous users are prompted to log in by files report' do
# Note that nobody is signed in.
get report_files_path
assert_response :redirect
end

test 'basic users cannot see files report' do
sign_in users(:basic)
get report_files_path
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'submitters cannot see files report' do
sign_in users(:transfer_submitter)
get report_files_path
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'processors can see files report' do
sign_in users(:processor)
get report_files_path
assert_response :success
end

test 'thesis_admins can see files report' do
sign_in users(:thesis_admin)
get report_files_path
assert_response :success
end

test 'admins can see files report' do
sign_in users(:admin)
get report_files_path
assert_response :success
end

test 'default files report is empty' do
sign_in users(:processor)
get report_files_path
assert_select 'table tbody td', text: 'There are no files without an assigned purpose within the selected term.', count: 1
end

test 'files have no default purpose, and appear on the files report' do
sign_in users(:processor)
xfer = transfers(:valid)
thesis = theses(:one)
attach_files(xfer, thesis)
get report_files_path
assert_select 'table tbody td', text: 'a_pdf.pdf', count: 2
end

test 'files report can be filtered by term' do
sign_in users(:processor)
xfer = transfers(:valid)
thesis = theses(:one)
attach_files(xfer, thesis)
get report_files_path
assert_select 'table tbody td', text: 'a_pdf.pdf', count: 2
get report_files_path, params: { graduation: '2018-09-01' }
assert_select 'table tbody td', text: 'There are no files without an assigned purpose within the selected term.', count: 1
end

test 'files disappear from files report when a purpose is set' do
sign_in users(:processor)
xfer = transfers(:valid)
thesis = theses(:one)
attach_files(xfer, thesis)
get report_files_path
assert_select 'table tbody td', text: 'a_pdf.pdf', count: 2
file = thesis.files.first
file.purpose = 0
file.save
get report_files_path
assert_select 'table tbody td', text: 'a_pdf.pdf', count: 1
end
end