Skip to content
Open
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
27 changes: 12 additions & 15 deletions app/models/requests/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
module Requests
# This class assigns "services" a given requestable object is available through
class Router
attr_reader :user, :patron, :any_loanable, :requestable

delegate :cas_provider?, :alma_provider?, to: :user
attr_reader :patron, :any_loanable, :requestable

def initialize(requestable:, any_loanable: false, patron: nil)
@requestable = requestable
@user = patron.user
@patron = patron
@any_loanable = any_loanable
end
Expand Down Expand Up @@ -48,21 +45,21 @@ def calculate_services
def eligibility_checks
[
ServiceEligibility::ILL.new(requestable:, patron:, any_loanable:),
ServiceEligibility::OnOrder.new(requestable:, user:),
ServiceEligibility::OnOrder.new(requestable:, patron:),
ServiceEligibility::Annex::Pickup.new(requestable:, patron:),
ServiceEligibility::Annex::NoItems.new(requestable:, patron:),
ServiceEligibility::OnShelfDigitize.new(requestable:, patron:),
ServiceEligibility::OnShelfPickup.new(requestable:, patron:),
ServiceEligibility::InProcess.new(requestable:, user:),
ServiceEligibility::MarquandInLibrary.new(requestable:, user:),
ServiceEligibility::MarquandEdd.new(requestable:, user:),
ServiceEligibility::MarquandPageChargedItem.new(requestable:, user:),
ServiceEligibility::Recap::NoItems.new(requestable:, user:),
ServiceEligibility::Recap::InLibrary.new(requestable:, user:),
ServiceEligibility::Recap::AskMe.new(requestable:, user:),
ServiceEligibility::Recap::Digitize.new(requestable:, user:),
ServiceEligibility::Recap::Pickup.new(requestable:, user:),
ServiceEligibility::Aeon.new(requestable:)
ServiceEligibility::InProcess.new(requestable:, patron:),
ServiceEligibility::MarquandInLibrary.new(requestable:, patron:),
ServiceEligibility::MarquandEdd.new(requestable:, patron:),
ServiceEligibility::MarquandPageChargedItem.new(requestable:, patron:),
ServiceEligibility::Recap::NoItems.new(requestable:, patron:),
ServiceEligibility::Recap::InLibrary.new(requestable:, patron:),
ServiceEligibility::Recap::AskMe.new(requestable:, patron:),
ServiceEligibility::Recap::Digitize.new(requestable:, patron:),
ServiceEligibility::Recap::Pickup.new(requestable:, patron:),
ServiceEligibility::Aeon.new(requestable:, patron:)
]
end
end
Expand Down
14 changes: 3 additions & 11 deletions app/models/requests/service_eligibility/abstract_on_shelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def to_s
end

def eligible?
requestable_eligible? && user_eligible?
requestable_eligible? && patron_group_eligible?
end

protected
Expand All @@ -22,10 +22,6 @@ def requestable_eligible?
raise "Please implement requestable_eligible? in the subclass"
end

def user_eligible?
provider_eligible? && patron_group_eligible?
end

def on_shelf_eligible?
!requestable.aeon? && !requestable.charged? &&
!requestable.in_process? &&
Expand All @@ -35,16 +31,12 @@ def on_shelf_eligible?
!requestable.held_at_marquand_library?
end

def provider_eligible?
user.cas_provider? || user.alma_provider?
end

def patron_group_eligible?
allowed_patron_groups.include?(patron.patron_group)
allowed_patron_groups.include?(patron.patron_group) && !patron.guest?
end

def allowed_patron_groups
@allowed_patron_groups ||= %w[P REG GRAD SENR UGRD]
@allowed_patron_groups ||= %w[P REG GRAD SENR UGRD SUM]
end

attr_reader :requestable, :user, :patron
Expand Down
13 changes: 11 additions & 2 deletions app/models/requests/service_eligibility/aeon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module ServiceEligibility
# This class is responsible for determining if a specific
# resource can be requested via Aeon
class Aeon
def initialize(requestable:)
def initialize(requestable:, patron:)
@requestable = requestable
@patron = patron
end

def to_s
Expand All @@ -16,9 +17,17 @@ def eligible?
requestable.aeon? || !(requestable.alma_managed? || requestable.partner_holding?)
end

def patron_group_eligible?
allowed_patron_groups.include?(patron.patron_group)
end

def allowed_patron_groups
@allowed_patron_groups ||= %w[P REG GRAD SENR UGRD SUM]
end

private

attr_reader :requestable
attr_reader :requestable, :patron
end
end
end
15 changes: 3 additions & 12 deletions app/models/requests/service_eligibility/ill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module ServiceEligibility
class ILL
def initialize(requestable:, patron:, any_loanable:)
@requestable = requestable
@user = patron.user
@any_loanable = any_loanable
@patron = patron
end
Expand All @@ -16,7 +15,7 @@ def to_s
end

def eligible?
requestable_eligible? && user_eligible? && patron_group_eligible?
requestable_eligible? && patron_group_eligible? && !patron.guest?
end

private
Expand All @@ -26,19 +25,11 @@ def requestable_eligible?
(!any_loanable || requestable.enumerated? || requestable.preservation_conservation?)
end

def user_eligible?
user.cas_provider? || user.alma_provider?
end

def patron_group_eligible?
allowed_patron_groups.include?(patron.patron_group)
end

def allowed_patron_groups
@allowed_patron_groups ||= %w[P REG GRAD SENR UGRD]
patron.core_patron_group?
end

attr_reader :requestable, :user, :any_loanable, :patron
attr_reader :requestable, :any_loanable, :patron
end
end
end
8 changes: 4 additions & 4 deletions app/models/requests/service_eligibility/in_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module Requests
module ServiceEligibility
class InProcess
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def to_s
Expand All @@ -18,13 +18,13 @@ def eligible?
private

def user_eligible?
user.cas_provider? || user.alma_provider?
patron.core_patron_group? && !patron.guest?
end

def requestable_eligible?
!requestable.aeon? && !requestable.charged? && requestable.in_process?
end
attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
12 changes: 6 additions & 6 deletions app/models/requests/service_eligibility/marquand_edd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
module Requests
module ServiceEligibility
class MarquandEdd
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def to_s
'marquand_edd'
end

def eligible?
requestable_eligible? && user_eligible?
requestable_eligible? && patron_group_eligible? && !patron.guest?
end

private

def user_eligible?
user.cas_provider? || user.alma_provider?
def patron_group_eligible?
patron.core_patron_group?
end

def requestable_eligible?
Expand All @@ -31,7 +31,7 @@ def requestable_eligible?
(requestable.alma_managed? || requestable.partner_holding?) &&
!requestable.aeon?
end
attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
12 changes: 6 additions & 6 deletions app/models/requests/service_eligibility/marquand_in_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
module Requests
module ServiceEligibility
class MarquandInLibrary
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def to_s
'marquand_in_library'
end

def eligible?
requestable_eligible? && user_eligible?
requestable_eligible? && patron_group_eligible? && !patron.guest?
end

private

def user_eligible?
user.cas_provider? || user.alma_provider?
def patron_group_eligible?
patron.core_patron_group?
end

def requestable_eligible?
Expand All @@ -31,7 +31,7 @@ def requestable_eligible?
(requestable.alma_managed? || requestable.partner_holding?) &&
!requestable.aeon?
end
attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module ServiceEligibility
# carrel. The materials in the other user's carrel are charged (checked out),
# so this service is only possible for charged materials.
class MarquandPageChargedItem
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def eligible?
correct_status? && correct_location? && user_eligible?
correct_status? && correct_location? && patron_group_eligible? && !patron.guest?
end

def to_s
Expand All @@ -29,11 +29,11 @@ def correct_location?
requestable.held_at_marquand_library?
end

def user_eligible?
user.cas_provider? || user.alma_provider?
def patron_group_eligible?
patron.core_patron_group?
end

attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
12 changes: 6 additions & 6 deletions app/models/requests/service_eligibility/on_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module Requests
module ServiceEligibility
# on_order - material has a status in Alma that indicates it is ordered but has not yet arrived on campus
class OnOrder
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def to_s
'on_order'
end

def eligible?
requestable_eligible? && user_eligible?
requestable_eligible? && patron_group_eligible? && !patron.guest?
end

private
Expand All @@ -26,11 +26,11 @@ def requestable_eligible?
requestable.on_order?
end

def user_eligible?
user.cas_provider? || user.alma_provider?
def patron_group_eligible?
patron.core_patron_group?
end

attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module ServiceEligibility
module Recap
# Abstract class for other recap classes to inherit from
class AbstractRecap
def initialize(requestable:, user:)
def initialize(requestable:, patron:)
@requestable = requestable
@user = user
@patron = patron
end

def to_s
Expand All @@ -20,10 +20,10 @@ def requestable_eligible?
end

def user_eligible?
user.cas_provider? || user.alma_provider?
(patron.core_patron_group? || patron.affiliate_patron_group?) && !patron.guest?
end

attr_reader :requestable, :user
attr_reader :requestable, :patron
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/requests/service_eligibility/recap/pickup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def requestable_eligible?
requestable.item_data? &&
!requestable.recap_pf? &&
!requestable.holding_library_in_library_only? &&
!(!requestable.circulates? && !requestable.recap_edd?) &&
requestable.circulates? &&
!(requestable.scsb_in_library_use? && requestable.item[:collection_code] != "MR") &&
!requestable.charged?
end
Expand Down
7 changes: 6 additions & 1 deletion spec/models/requests/service_eligibility/aeon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
require 'rails_helper'

RSpec.describe Requests::ServiceEligibility::Aeon, requests: true do
let(:user) { FactoryBot.create(:user) }
let(:valid_patron) { { "netid" => "foo", "patron_group" => "P" }.with_indifferent_access }
let(:patron) do
Requests::Patron.new(user:, patron_hash: valid_patron)
end
describe '#eligible?' do
it 'returns true if Alma-managed and aeon true' do
requestable = instance_double(Requests::Requestable)
allow(requestable).to receive_messages(
alma_managed?: true,
aeon?: true
)
eligibility = described_class.new(requestable:)
eligibility = described_class.new(requestable:, patron:)

expect(eligibility.eligible?).to be(true)
end
Expand Down
Loading