Skip to content

Commit 81a6040

Browse files
Baroquemmhk33
andauthored
Merge changes for v2.3.4 (#120)
* DACCESS-381: fix punctuation on login page * DACCESS-257: Fix bug preventing ILL requests from appearing (#118) * DACCESS-459: Fix bug breaking ReShare lookups (#117) * Update call to cul-folio-edge authenticate method to specify old auth method (DACCESS-459) * Update release notes * Require new version of cul-folio-edge * Use ILLiad API to retrieve tranactions (DACCESS-257, DACCESS-460) * Do things the Ruby way * Comment out things not being used * Update release notes * Formatting and docs --------- Co-authored-by: Melissa Wallace <[email protected]> * Add filter for ILL transactions (#119) * DACCESS-459: Fix bug breaking ReShare lookups (#117) * Update call to cul-folio-edge authenticate method to specify old auth method (DACCESS-459) * Update release notes * Require new version of cul-folio-edge * Use ILLiad API to retrieve tranactions (DACCESS-257, DACCESS-460) * Do things the Ruby way * Comment out things not being used * Update release notes * Formatting and docs * Add ILL transaction filter; update release notes * Fix merge conflict --------- Co-authored-by: Melissa Wallace <[email protected]> --------- Co-authored-by: Melissa Wallace <[email protected]>
1 parent fb665f7 commit 81a6040

File tree

6 files changed

+147
-19
lines changed

6 files changed

+147
-19
lines changed

app/controllers/my_account/account_controller.rb

+6-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
module MyAccount
99
class AccountController < ApplicationController
1010
#include Reshare
11+
include ILL
1112

1213
before_action :heading
1314
before_action :authenticate_user, except: [:intro]
@@ -149,17 +150,12 @@ def ajax_cancel
149150
# parsing below greatly. No need to try to figure out whether something is a charged item or a request
150151
def get_illiad_data
151152
record = nil
152-
153153
netid = params['netid']
154-
# folio_account_data = get_folio_accountinfo netid
155-
# Rails.logger.debug "mjc12test: Start parsing"
156154

157155
begin
158-
# NOTE: the key MY_ACCOUNT_ISLAPI_URL is a misomer now, because we've eliminated the ilsapi CGI
159-
# script and are using the illiad6.cgi script, which ilsapi called, without the middleman. Probably
160-
# the key should be renamed at some point.
161-
response = RestClient.get "#{ENV['MY_ACCOUNT_ILSAPI_URL']}?netid=#{netid}&fmt=json&wrapper=n"
162-
record = JSON.parse response.body
156+
# Now using the ILLiad API to retrieve ILL transactions
157+
transactions = ill_transactions(netid)
158+
items = JSON.parse(transactions)['items']
163159
rescue => error
164160
Rails.logger.error "MyAccount error: Could not find a patron entry for #{netid}"
165161
msg = "We're sorry, but we could not access your account. For help, please email <a href='mailto:[email protected]'>[email protected]</a>"
@@ -171,7 +167,8 @@ def get_illiad_data
171167
available_requests = []
172168

173169
# Parse the results of the ilsapiE/ILLiad lookup. Loans (from FOLIO) are handled separately
174-
record['items'].each do |i|
170+
#record['items'].each do |i|
171+
items.each do |i|
175172
# TODO: items returned with a status of 'finef' appear to be duplicates, only
176173
# indicating that a fine or fee is applied to that item. So we don't need them
177174
# in this list? But maybe check the fine-related functions below to see if we
@@ -183,9 +180,6 @@ def get_illiad_data
183180
# show up twice in the user's requests (BD/ReShare and ILL)
184181
next if i['TransactionStatus'] == 'Request Sent to BD'
185182

186-
# Skip if this is a ReShare submission that has been rerouted to BD -- otherwise it will
187-
# show up twice in the user's requests (BD/ReShare and ILL)
188-
next if i['TransactionStatus'] == 'Request Sent to BD'
189183
# Slight hack: items with the status Checked out in FOLIO are actually waiting to be
190184
# picked up. This is confusing, because 'checked out' implies that the user
191185
# has it, but that isn't the case! These should be covered by the patron account 'holds'

app/views/my_account/account/intro.html.haml

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
Email your
1010
=link_to('library', 'https://library.cornell.edu/libraries')
1111
or
12-
=link_to('[email protected]', 'mailto:[email protected]')
13-
\.
12+
=link_to('[email protected]', 'mailto:[email protected]') + '.'
1413

1514
%p
1615
Visit the library website for
17-
=link_to('fine information', 'https://www.library.cornell.edu/collections/borrow-renew-return/policies/#fines')
18-
\.
16+
= link_to('fine information', 'https://www.library.cornell.edu/collections/borrow-renew-return/policies/#fines') + '.'

lib/ill.rb

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# This module is an interface for ILLiad. Its primary function is to retrieve an array
2+
# of ILL transactions for a given user, making use of the ILLiad API. The results are
3+
# filtered and transformed into a JSON object that can be used by the My Account system.
4+
module ILL
5+
require 'rest-client'
6+
7+
def ill_transactions(user_id)
8+
transactions = fetch_ill_transactions(user_id)
9+
# NOTE: The following line should be redundant, but it's here for now, just in case. (See notes in fetch_ill_transactions)
10+
transactions = filter_by_status(transactions)
11+
transform_fields(transactions)
12+
end
13+
14+
private
15+
16+
# Fetches ILL (Interlibrary Loan) transactions for a given user via the ILLiad API.
17+
#
18+
# @param user_id [String] the ID of the user whose transactions are being fetched (netid or guest id)
19+
# @return [Array<Hash>] an array of objects representing the user's ILL transactions.
20+
# @raise [RestClient::ExceptionWithResponse] if the request to the ILLiad API fails.
21+
#
22+
# The method sends a GET request to the ILLiad API to retrieve the user's ILL transactions.
23+
# It expects the API key and URL to be set in the environment variables 'MY_ACCOUNT_ILLIAD_API_KEY' and 'MY_ACCOUNT_ILLIAD_API_URL'.
24+
# A filter is used in the query to try to only retrieve active transactions.
25+
def fetch_ill_transactions(user_id)
26+
headers = {
27+
'Accept' => 'application/json',
28+
'APIKey' => ENV['MY_ACCOUNT_ILLIAD_API_KEY']
29+
}
30+
# The filter is used here because I'm concerned about some users having massive numbers of old, completed transactions. I don't know if this
31+
# will speed up or slow down the query. In case this doesn't work properly, the filter_by_status method is called again after the query. The three
32+
# values used to catch completed transactions are the ones used in the old illid6.cgi script.
33+
filter = "not (TransactionStatus eq 'Request Finished' or TransactionStatus eq 'Cancelled by ILL Staff' or TransactionStatus eq 'Cancelled by Customer')"
34+
response = RestClient.get "#{ENV['MY_ACCOUNT_ILLIAD_API_URL']}/Transaction/UserRequests/#{user_id}?$filter=#{filter}", headers
35+
transactions = JSON.parse(response.body)
36+
transactions
37+
end
38+
39+
# Remove transactions that are completed or cancelled
40+
def filter_by_status(transactions)
41+
transactions.select do |transaction|
42+
!['Request Finished', 'Cancelled by ILL Staff', 'Cancelled by Customer'].include?(transaction['TransactionStatus'])
43+
end
44+
end
45+
46+
# Transform the transaction object. The replacement fields are primarily used for display in the My Account requests views.
47+
# This method is a near-direct port of the illiad6.cgi Perl script that was previously used as a data source for ILLiad.
48+
# illiad6.cgi directly queried the ILLiad database, then added these fields to the results before passing
49+
# the whole thing back as a response. Why do we have ii, ou_genre, etc. as fields? Do we still need them
50+
# to be this obscure? Can we make them more readable? These are questions to ponder in the future.
51+
def transform_fields(transactions)
52+
items_array = transactions.map do |transaction|
53+
genre = transaction['LoanTitle'] ? 'book' : 'article'
54+
title = transaction['LoanTitle'] || transaction['PhotoArticleTitle']
55+
title.gsub!(/"/, ' ')
56+
spot = title.index('/')
57+
title = title[0...spot - 1] if spot
58+
59+
if genre == 'article'
60+
author_last_name = transaction['PhotoArticleAuthor']
61+
volume = transaction['PhotoJournalVolume']
62+
issn = transaction['ISSN']
63+
issue = transaction['PhotoJournalIssue']
64+
year = transaction['PhotoJournalYear']
65+
pages = transaction['PhotoJournalInclusivePages']
66+
full_title = "#{transaction['PhotoJournalTitle']} #{transaction['PhotoArticleTitle']} / #{transaction['PhotoArticleAuthor']} v.#{transaction['PhotoJournalVolume']} # #{transaction['PhotoJournalIssue']} pp. #{transaction['PhotoJournalInclusivePages']} #{transaction['PhotoJournalYear']}"
67+
else
68+
author_last_name = transaction['LoanAuthor']
69+
year = transaction['LoanDate']
70+
isbn = transaction['ISSN']
71+
spot = transaction['LoanTitle'].index('/')
72+
transaction['LoanTitle'] = transaction['LoanTitle'][0...spot - 1] if spot
73+
full_title = "#{transaction['LoanTitle']} / #{transaction['LoanAuthor']}"
74+
end
75+
76+
#full_title.gsub!(/[\012\015]/, ' ').gsub!(/"/, ' ').gsub!(/"/, "'")
77+
location = transaction['NVTGC']
78+
due_date = transaction['DueDate']
79+
original_due_date = transaction['DueDate']
80+
# renewals_allowed = transaction['RenewalsAllowed']
81+
# date = due_date
82+
83+
status = transaction['TransactionStatus']
84+
case status
85+
when 'Checked Out to Customer', 'Renewal Requested by Customer'
86+
status = "chrged"
87+
url = "https://cornell.hosts.atlas-sys.com/illiad/illiad.dll?Action=10&Form=66&Value=#{transaction['TransactionNumber']}"
88+
when 'Awaiting Verisign Payment'
89+
status = "waiting"
90+
url = "https://cornell.hosts.atlas-sys.com/illiad/illiad.dll?Action=10&Form=62"
91+
when 'Delivered to Web'
92+
status = "waiting"
93+
url = "https://cornell.hosts.atlas-sys.com/illiad/illiad.dll?Action=10&Form=75&Value=#{transaction['TransactionNumber']}"
94+
when 'Customer Notified via E-Mail'
95+
status = "waiting"
96+
else
97+
status = "pahr"
98+
url = "https://cornell.hosts.atlas-sys.com/illiad/illiad.dll?Action=10&Form=63&Value=#{transaction['TransactionNumber']}"
99+
end
100+
101+
# TODO: Review these fields ... some of them are probably unnecessary.
102+
{
103+
system: "illiad",
104+
status: status,
105+
ii: transaction['TransactionNumber'],
106+
it: transaction['DocumentType'],
107+
tl: full_title,
108+
od: original_due_date,
109+
rd: due_date,
110+
lo: location,
111+
ou_genre: genre,
112+
ou_title: title,
113+
ou_aulast: author_last_name,
114+
# The following fields don't seem to be used anywhere.
115+
# ou_pages: pages,
116+
# ou_year: year,
117+
# ou_issue: issue,
118+
# ou_volume: volume,
119+
# ou_issn: issn,
120+
url: url,
121+
requestDate: transaction['CreationDate'],
122+
TransactionDate: transaction['TransactionDate'],
123+
TransactionNumber: transaction['TransactionNumber']
124+
}
125+
end
126+
127+
{ items: items_array }.to_json
128+
end
129+
130+
end

lib/my_account/engine.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ class Engine < ::Rails::Engine
33
isolate_namespace MyAccount
44

55
config.autoload_paths += Dir["#{config.root}/spec/support"]
6-
config.eager_load_paths += Dir["#{config.root}/lib"]
6+
config.autoload_paths += Dir["#{config.root}/lib/**/"]
7+
config.eager_load_paths += Dir["#{config.root}/lib/**/"]
78
config.assets.paths << config.root.join('/engines/my_account/app/assets/javascripts')
89
config.assets.precompile << "my_account/application.js"
910
config.assets.precompile << "my_account/account.js.coffee"

lib/my_account/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module MyAccount
2-
VERSION = '2.3.3'
2+
VERSION = '2.3.4'
33
end

release_notes.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Release Notes - my-account
22

3-
## IN PROGRESS
3+
## [2.3.4] - 2025-01-17
4+
### Changed
5+
- Remove dependency on external CGI script for ILLiad lookups by adding new ILL module using ILL API (DACCESS-257)
6+
47
### Fixed
8+
- Fix punctuation on login page (DACCESS-381)
59
- Specify old authentication method to fix broken ReShare account lookup (DACCESS-459)
10+
- Fix bug preventing ILLiad requests from appearing (DACCESS-460)
611

712
## [2.3.3] - 2024-09-17
813
- Update links to fine information

0 commit comments

Comments
 (0)