diff --git a/.env.sample b/.env.sample index 60277911..81cc6343 100644 --- a/.env.sample +++ b/.env.sample @@ -5,3 +5,5 @@ FRAMEWORK_ALMA_API_KEY=KEY_GOES_HERE FRAMEWORK_ALMA_API_URL=https://api-na.hosted.exlibrisgroup.com/almaws/v1/ FRAMEWORK_ALMA_SANDBOX_KEY=KEY_GOES_HERE LIT_TIND_API_KEY=KEY_GOES_HERE +# set a warning message when we know we're getting rate limited by OCLC +FRAMEWORK_LOCATION_REQUESTS_ALERT="Location Requests that involve WorldCat lookups are currently being rate limited by OCLC. We have contacted OCLC support and are awaiting resolution." diff --git a/app/helpers/location_requests_alert_helper.rb b/app/helpers/location_requests_alert_helper.rb new file mode 100644 index 00000000..fb99a46a --- /dev/null +++ b/app/helpers/location_requests_alert_helper.rb @@ -0,0 +1,10 @@ +module LocationRequestsAlertHelper + def location_requests_alert + Rails.configuration.location_requests_alert.presence + end + + def display_location_requests_alert + alert = location_requests_alert + content_tag(:div, alert, class: 'alert alert-warning', role: 'alert') if alert + end +end diff --git a/app/views/location_requests/new.html.erb b/app/views/location_requests/new.html.erb index b37dc58e..b9f5acc9 100644 --- a/app/views/location_requests/new.html.erb +++ b/app/views/location_requests/new.html.erb @@ -1,4 +1,7 @@
The Location Request tool takes an OCLC number and queries OCLC and/or HathiTrust. The tool is good for searching for single-volume monographs. For multi-volume monographs diff --git a/config/altmedia.yml b/config/altmedia.yml index f69c3e73..63a9f876 100644 --- a/config/altmedia.yml +++ b/config/altmedia.yml @@ -15,6 +15,7 @@ default: &default alma_api_url: <%= ENV["FRAMEWORK_ALMA_API_URL"].presence || 'https://api-na.hosted.exlibrisgroup.com/almaws/v1/' %> alma_api_key: <%= ENV["FRAMEWORK_ALMA_API_KEY"].presence || 'fake-api-key' %> alma_sandbox_key: <%= ENV["FRAMEWORK_ALMA_SANDBOX_KEY"].presence || 'fake-api-key' %> + location_requests_alert: <%= ENV["FRAMEWORK_LOCATION_REQUESTS_ALERT"] %> paypal_payflow_url: <%= ENV["PAYPAL_PAYFLOW_URL"] || 'https://payflowlink.paypal.com' %> paypal_payflow_login: <%= ENV["PAYPAL_PAYFLOW_LOGIN"] || 'ucblibrary' %> tind_base_uri: <%= ENV["LIT_TIND_BASE_URL"] || 'https://digicoll.lib.berkeley.edu/' %> diff --git a/config/application.rb b/config/application.rb index bfffb17c..e80b167b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -85,6 +85,9 @@ def log_active_storage_root!(active_storage_root) # Valid groups for libproxy access based on Alma groups config.libproxy_groups = config.libproxy['valid_groups'] + # alert message on location requests when we know we're being rate limited + config.location_requests_alert = config.altmedia['location_requests_alert'] + # Tind set values for marc inserts config.tind_resource_types = config.tind_marc['resource_types'] config.tind_restrictions = config.tind_marc['restrictions'] diff --git a/spec/helpers/location_requests_alert_helper_spec.rb b/spec/helpers/location_requests_alert_helper_spec.rb new file mode 100644 index 00000000..ab7426bd --- /dev/null +++ b/spec/helpers/location_requests_alert_helper_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +describe LocationRequestsAlertHelper, type: :helper do + let(:configured_alert) { nil } + + before do + allow(Rails.configuration).to receive(:location_requests_alert).and_return(configured_alert) + end + + describe '#location_requests_alert' do + subject(:location_requests_alert) { helper.location_requests_alert } + + context 'when the alert is not configured' do + it { is_expected.to be_nil } + end + + context 'when the alert is blank' do + let(:configured_alert) { ' ' } + + it { is_expected.to be_nil } + end + + context 'when the alert is configured' do + let(:configured_alert) { 'OCLC requests are currently rate limited.' } + + it { is_expected.to eq(configured_alert) } + end + end + + describe '#display_location_requests_alert' do + subject(:output) { helper.display_location_requests_alert } + + context 'when the alert is not configured' do + it { is_expected.to be_nil } + end + + context 'when the alert is configured' do + let(:configured_alert) { 'OCLC requests are currently rate limited.' } + + it 'renders the configured message as a warning alert' do + render html: output + + assert_dom 'div.alert.alert-warning[role=?]', 'alert', text: configured_alert, count: 1 + end + end + end +end diff --git a/spec/system/location_requests_system_spec.rb b/spec/system/location_requests_system_spec.rb index 05110537..f8538d95 100644 --- a/spec/system/location_requests_system_spec.rb +++ b/spec/system/location_requests_system_spec.rb @@ -13,6 +13,29 @@ end end + describe 'location requests alert' do + let(:configured_alert) { nil } + + before do + allow(Rails.configuration).to receive(:location_requests_alert).and_return(configured_alert) + visit new_location_request_path + end + + context 'when the alert is not configured' do + it 'does not display a warning alert' do + expect(page).to have_no_selector('div.alert.alert-warning[role="alert"]') + end + end + + context 'when the alert is configured' do + let(:configured_alert) { 'OCLC requests are currently rate limited.' } + + it 'displays the configured warning alert' do + expect(page).to have_selector('div.alert.alert-warning[role="alert"]', text: configured_alert) + end + end + end + shared_examples 'a form with immediate and off-hours options' do it 'includes the "immediate" radio group' do [true, false].each do |state|