Skip to content

Commit

Permalink
Merge pull request #22 from cul-it/dev
Browse files Browse the repository at this point in the history
Merge changes for v1.0.3
  • Loading branch information
Baroquem authored Oct 10, 2019
2 parents 2ba02fe + d394501 commit 43f6416
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
49 changes: 33 additions & 16 deletions app/controllers/my_account/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def index

# Given an array of item "ids" (of the form 'select-<id>'), return an array of the bare IDs
def ids_from_strings items
Rails.logger.debug "mjc12test: items: #{items}"
items.keys.map { |item, value| item.match(/select\-(.+)/)[1] }
end

Expand Down Expand Up @@ -105,6 +106,7 @@ def renew items
error_messages = []
# Retrieve the list of item IDs that have been selected for renewal
item_ids= ids_from_strings items

# if @checkouts.length <= 100
# @renewable_lookup_hash ||= get_renewable_lookup user
# end
Expand All @@ -125,23 +127,38 @@ def renew items
errors = false
successful_renewal_count = 0
renewable_item_ids.each do |id|
http = Net::HTTP.new("#{ENV['MY_ACCOUNT_VOYAGER_URL']}")
url = "#{ENV['MY_ACCOUNT_VOYAGER_URL']}/patron/#{@patron['patron_id']}/circulationActions/loans/1@#{ENV['VOYAGER_DB']}%7C#{id}?patron_homedb=1@#{ENV['VOYAGER_DB']}"
Rails.logger.debug "mjc12test: Trying to renew with url: #{url}"
response = RestClient.post(url, {})
xml = XmlSimple.xml_in response.body
Rails.logger.debug "mjc12test: response #{xml}"
response_loan_info = xml && xml['renewal'][0]['institution'][0]['loan'][0]
if xml && xml['reply-code'][0] != '0'
error_messages << "Item '#{response_loan_info['title'][0]}' could not be renewed due to an error: " + xml['reply-text'][0]
Rails.logger.error "My Account: couldn't renew item #{id}. XML returned: #{xml}"
errors = true
elsif response_loan_info && response_loan_info['renewalStatus'][0] != 'Success'
error_messages << "Item '#{response_loan_info['title'][0]}' could not be renewed due to an error: " + response_loan_info['renewalStatus'][0]
Rails.logger.error "My Account: couldn't renew item #{id}. XML returned: #{xml}"
errors = true
# Check for ILLiad item
if id.start_with? 'illiad'
transaction_id = id.split(/-/)[1]
response = RestClient.get "https://ill-access.library.cornell.edu/illrenew.cgi?netid=#{@patron['netid']}&iid=#{transaction_id}"
response = JSON.parse response.body
Rails.logger.debug "mjc12test: got renew response: #{response['error']}"
if response['error'].present?
error_messages << "Could not renew item in ILLiad"
Rails.logger.error "My Account: Couldn't renew ILLiad item with transaction ID #{transaction_id}. Request returned error: #{response['error']}"
errors = true
else
successful_renewal_count += 1
end
else
successful_renewal_count += 1
http = Net::HTTP.new("#{ENV['MY_ACCOUNT_VOYAGER_URL']}")
url = "#{ENV['MY_ACCOUNT_VOYAGER_URL']}/patron/#{@patron['patron_id']}/circulationActions/loans/1@#{ENV['VOYAGER_DB']}%7C#{id}?patron_homedb=1@#{ENV['VOYAGER_DB']}"
Rails.logger.debug "mjc12test: Trying to renew with url: #{url}"
response = RestClient.post(url, {})
xml = XmlSimple.xml_in response.body
Rails.logger.debug "mjc12test: response #{xml}"
response_loan_info = xml && xml['renewal'][0]['institution'][0]['loan'][0]
if xml && xml['reply-code'][0] != '0'
error_messages << "Item '#{response_loan_info['title'][0]}' could not be renewed due to an error: " + xml['reply-text'][0]
Rails.logger.error "My Account: couldn't renew item #{id}. XML returned: #{xml}"
errors = true
elsif response_loan_info && response_loan_info['renewalStatus'][0] != 'Success'
error_messages << "Item '#{response_loan_info['title'][0]}' could not be renewed due to an error: " + response_loan_info['renewalStatus'][0]
Rails.logger.error "My Account: couldn't renew item #{id}. XML returned: #{xml}"
errors = true
else
successful_renewal_count += 1
end
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/helpers/my_account/my_account_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def cased_title_link item
# indistinguishable from regular records.) The one property that seems to offer
# guidance is the 'lo' (location) field, which is unpopulated for BD/ILL records
# but indicates an actual library location for Voyager records.
item['lo'] == '' ?
item['lo'] == '' || item['TransactionNumber'] ?
display_title :
link_to(display_title, "https://newcatalog.library.cornell.edu/catalog/#{item['bid']}")
end
Expand All @@ -24,5 +24,12 @@ def status_display item
status == 'pahr' ? '' : status
end

# Return a 'system' data tag for a checkout. Can be Voyager or Illiad for now. Note that
# this is *not* the same as the 'system' field in the item metadata, which apparently always reads
# 'voyager' regardless when an item is checked out. Instead, this goes on the assumption that
# a TransactionNumber indicates an Illiad loan.
def system_tag item
item['TransactionNumber'].present? ? 'illiad' : 'voyager'
end
end
end
2 changes: 1 addition & 1 deletion app/views/my_account/account/_checkouts.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%th{:scope => 'col', :class => 'myacct-col-20'} Status
%tbody
- @checkouts.each do |c|
%tr.item{:id => "#{c['iid']}"}
%tr.item{:id => "#{c['iid']}", :data => {:system => system_tag(c)}}
%td
= label_tag "select-#{c['iid']}", 'Select', { :class => 'sr-only' }
= check_box_tag "select-#{c['iid']}", 1, false, { 'aria-label' => 'Select', :title => 'Select' }
Expand Down
2 changes: 1 addition & 1 deletion lib/my_account/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MyAccount
VERSION = "1.0.2"
VERSION = "1.0.3"
end
3 changes: 3 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes - my-account

## v1.0.3
- Fixed a bug preventing renewals through ILLiad

## v1.0.2
### Bug fixes
- Improved renewal status and error messages
Expand Down

0 comments on commit 43f6416

Please sign in to comment.