From cfd42635790a347d4dc0fc58b0b7697d8ad67659 Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Tue, 3 Dec 2024 15:46:30 -0500 Subject: [PATCH] Remove code for connecting to old borrow direct service (replaced by reshare) --- Gemfile | 2 - Gemfile.lock | 4 - app/models/borrow_direct_requests.rb | 72 ---------------- app/models/folio/patron.rb | 9 +- config/initializers/borrow_direct.rb | 7 -- config/settings.yml | 3 - spec/controllers/requests_controller_spec.rb | 2 +- spec/models/borrow_direct_requests_spec.rb | 91 -------------------- 8 files changed, 4 insertions(+), 186 deletions(-) delete mode 100644 app/models/borrow_direct_requests.rb delete mode 100644 config/initializers/borrow_direct.rb delete mode 100644 spec/models/borrow_direct_requests_spec.rb diff --git a/Gemfile b/Gemfile index 5d4af579..330af6c1 100644 --- a/Gemfile +++ b/Gemfile @@ -46,8 +46,6 @@ gem 'warden' gem 'nokogiri' -gem 'borrow_direct' - gem 'recaptcha' gem 'global_alerts' diff --git a/Gemfile.lock b/Gemfile.lock index a0464fd9..22944b07 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,8 +103,6 @@ GEM bindex (0.8.1) bootsnap (1.18.4) msgpack (~> 1.2) - borrow_direct (1.2.0) - httpclient (~> 2.4) builder (3.3.0) bundler-audit (0.9.2) bundler (>= 1.2.0, < 3) @@ -206,7 +204,6 @@ GEM http-cookie (1.0.7) domain_name (~> 0.5) http-form_data (2.3.0) - httpclient (2.8.3) i18n (1.14.6) concurrent-ruby (~> 1.0) ice_nine (0.11.2) @@ -473,7 +470,6 @@ PLATFORMS DEPENDENCIES axe-core-rspec bootsnap (>= 1.1.0) - borrow_direct capistrano (~> 3.0) capistrano-passenger capistrano-rails diff --git a/app/models/borrow_direct_requests.rb b/app/models/borrow_direct_requests.rb deleted file mode 100644 index 6df04cbc..00000000 --- a/app/models/borrow_direct_requests.rb +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -## -# Wrap the BorrowDirect::RequestQuery in a class that we -# can inject our patron barcode from (and do error handling) -class BorrowDirectRequests - attr_reader :patron_barcode - - def initialize(patron_barcode) - @patron_barcode = patron_barcode - end - - def requests - request_client.requests('open', true).map { |request| BorrowDirectRequests::Request.new(request) }.select(&:active?) - rescue BorrowDirect::Error - [] - end - - private - - def request_client - @request_client ||= BorrowDirect::RequestQuery.new(patron_barcode) - end - - ## - # Wrap the BorrowDirect::RequestQuery::Item in a class - # so we can give it a similar interface to ILS Requests - class Request < SimpleDelegator - # Request becomes ON_LOAN once we receive it (and should show as a request ready for pickup/checkout) - # Request becomes COMPLETED once the uesr returns it - ACTIVE_REQUEST_STATUSES = %w[ - ENTERED IN_PROCESS SHIPPED - ].freeze - - def active? - ACTIVE_REQUEST_STATUSES.include? request_status - end - - def key - request_number - end - - def sort_key(sort) - case sort - when :title - title - when :date - [::Folio::Request::END_OF_DAYS.strftime('%FT%T'), title].join('---') - else - '' - end - end - - def service_point_name; end - - def service_point_code; end - - def expiration_date; end - - def fill_by_date; end - - def ready_for_pickup? - false - end - - def to_partial_path - 'requests/borrow_direct_request' - end - - def manage_request_link; end - end -end diff --git a/app/models/folio/patron.rb b/app/models/folio/patron.rb index 48a63ffa..bb0d0ad6 100644 --- a/app/models/folio/patron.rb +++ b/app/models/folio/patron.rb @@ -208,13 +208,10 @@ def academic_staff_or_fellow? end def borrow_direct_requests - return [] if proxy_borrower? # Proxies can't submit borrow direct requests, so don't check. + # Proxies can't submit borrow direct requests, so don't check. + return [] unless Settings.borrow_direct_reshare.enabled && !proxy_borrower? - if Settings.borrow_direct_reshare.enabled - BorrowDirectReshareRequests.new(university_id).requests - else - BorrowDirectRequests.new(barcode).requests - end + BorrowDirectReshareRequests.new(university_id).requests end # this is all requests including self and group/proxy diff --git a/config/initializers/borrow_direct.rb b/config/initializers/borrow_direct.rb deleted file mode 100644 index 3b194309..00000000 --- a/config/initializers/borrow_direct.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -BorrowDirect::Defaults.api_key = Settings.borrow_direct.api_key - -BorrowDirect::Defaults.library_symbol = 'STANFORD' - -BorrowDirect::Defaults.api_base = BorrowDirect::Defaults::PRODUCTION_API_BASE if Rails.env.production? diff --git a/config/settings.yml b/config/settings.yml index ea98c95c..66632c02 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,8 +1,5 @@ debug: false -borrow_direct: - api_key: '' - folio: okapi_url: <%= ENV['OKAPI_URL'] %> online_service_point_id: 7c5abc9f-f3d7-4856-b8d7-6712462ca007 diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index d7e5c3d2..1e122403 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -50,7 +50,7 @@ let(:requests) do [ instance_double(Folio::Request, key: '1', sort_key: nil), - instance_double(BorrowDirectRequests::Request, key: 'sta-1', sort_key: nil) + instance_double(BorrowDirectReshareRequests::ReshareRequest, key: 'sta-1', sort_key: nil) ] end diff --git a/spec/models/borrow_direct_requests_spec.rb b/spec/models/borrow_direct_requests_spec.rb deleted file mode 100644 index 32a69c48..00000000 --- a/spec/models/borrow_direct_requests_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe BorrowDirectRequests do - subject(:bd_requests) { described_class.new(patron_barcode) } - - let(:patron_barcode) { '123456' } - let(:in_process_request) do - instance_double( - BorrowDirect::RequestQuery::Item, - request_number: 'STA-123454321', - request_status: 'IN_PROCESS', - date_submitted: Time.zone.today - 3.days - ) - end - let(:completed_request) do - instance_double(BorrowDirect::RequestQuery::Item, request_status: 'COMPLETED', title: 'BD Request Title') - end - let(:mock_requests) do - instance_double(BorrowDirect::RequestQuery, requests: [in_process_request, completed_request]) - end - - context 'when successful' do - before do - allow(BorrowDirect::RequestQuery).to receive(:new).with(patron_barcode).and_return(mock_requests) - end - - it 'only return requests with active statuses' do - expect(bd_requests.requests.length).to be(1) - end - end - - context 'when borrow direct returns an error' do - before do - allow(BorrowDirect::RequestQuery).to receive(:new).with(patron_barcode).and_raise( - BorrowDirect::Error, 'Item not Found' - ) - end - - it 'returns an empty array' do - expect(bd_requests.requests).to eq([]) - end - end - - describe 'BorrowDirectRequests::Request' do - let(:request) do - BorrowDirectRequests::Request.new(in_process_request) - end - - it 'delegates methods to the given request oboject' do - expect(request.date_submitted).to eq in_process_request.date_submitted - end - - it 'returns the request_number as the key' do - expect(request.key).to eq in_process_request.request_number - end - - it { expect(request).not_to be_ready_for_pickup } - - context 'when in an active state' do - it { expect(request).to be_active } - end - - context 'when not in an active state' do - let(:request) do - BorrowDirectRequests::Request.new(completed_request) - end - - it { expect(request).not_to be_active } - end - - describe '#sort_key' do - let(:request) { BorrowDirectRequests::Request.new(completed_request) } - - context 'when title' do - it { expect(request.sort_key(:title)).to eq 'BD Request Title' } - end - - context 'when date' do - it { - expect(request.sort_key(:date)).to eq "#{Folio::Request::END_OF_DAYS.strftime('%FT%T')}---BD Request Title" - } - end - - context 'when any other sort value' do - it { expect(request.sort_key(:something_else)).to eq '' } - end - end - end -end