• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 4c391e0e-519a-40cb-8ad3-354445f4ce03

12 Aug 2025 08:47PM UTC coverage: 85.348% (-10.0%) from 95.335%
4c391e0e-519a-40cb-8ad3-354445f4ce03

push

circleci

web-flow
[#5143] Use access restriction note as Aeon ItemInfo1 if available (#5173)

With this commit, if a user visits a record with an access
restrictions note and presses the Reading Room Request
button, they will get to an Aeon form with the 'Restrictions'
field pre-filled with the restriction note.

If the record does not have an access restrictions note,
the field will be pre-filled with 'Reading Room Access Only',
as it has been previously.

Closes #5143

5493 of 6436 relevant lines covered (85.35%)

251.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.45
/app/models/concerns/requests/scsb.rb
1
# frozen_string_literal: true
2
module Requests
1✔
3
  module Scsb
1✔
4
    # for PUL Bibliographic Helpers
5
    extend ActiveSupport::Concern
1✔
6

7
    def items_by_id(id, source = 'scsb')
1✔
8
      response = scsb_conn.post do |req|
94✔
9
        req.url '/sharedCollection/bibAvailabilityStatus'
94✔
10
        req.headers['Content-Type'] = 'application/json'
94✔
11
        req.headers['Accept'] = 'application/json'
94✔
12
        req.headers['api_key'] = scsb_auth_key
94✔
13
        req.body = scsb_bib_id_request(id, source).to_json
94✔
14
      end
15
      parse_scsb_response(response)
94✔
16
    end
17

18
    # Prefer lookup by bib over barcode
19
    # def items_by_barcode(barcodes)
20
    #   response = scsb_conn.post do |req|
21
    #     req.url '/sharedCollection/itemAvailabilityStatus'
22
    #     req.headers['Content-Type'] = 'application/json'
23
    #     req.headers['Accept'] = 'application/json'
24
    #     req.headers['api_key'] = scsb_auth_key
25
    #     req.body = scsb_barcode_request(barcodes).to_json
26
    #   end
27
    #   parse_scsb_response(response)
28
    # end
29

30
    def scsb_request(request_params)
1✔
31
      response = scsb_conn.post do |req|
7✔
32
        req.url '/requestItem/requestItem'
7✔
33
        req.headers['Content-Type'] = 'application/json'
7✔
34
        req.headers['Accept'] = 'application/json'
7✔
35
        req.headers['api_key'] = scsb_auth_key
7✔
36
        req.body = request_params.to_json
7✔
37
      end
38
      response
7✔
39
    end
40

41
    def parse_scsb_response(response)
1✔
42
      if response.status != 200
100✔
43
        Rails.logger.error("The request to the SCSB server failed: #{response.body}")
38✔
44
        return {}
38✔
45
      end
46
      parsed = JSON.parse(response.body)
62✔
47
      parsed.class == Hash ? parsed.with_indifferent_access : parsed
62✔
48
    rescue JSON::ParserError
49
      Rails.logger.error("Invalid response from the SCSB server: #{response.body}")
×
50
      raise
×
51
    end
52

53
    # Not being used at the moment
54
    # def scsb_barcode_request(barcodes)
55
    #   {
56
    #     barcodes: barcodes
57
    #   }
58
    # end
59

60
    def scsb_bib_id_request(id, source)
1✔
61
      {
62
        bibliographicId: id,
94✔
63
        institutionId: source
64
      }
65
    end
66

67
    def scsb_conn
1✔
68
      conn = Faraday.new(url: Requests.config[:scsb_base]) do |faraday|
101✔
69
        faraday.request  :url_encoded # form-encode POST params
101✔
70
        faraday.response :logger unless Rails.env.test? # log requests to STDOUT
101✔
71
        faraday.adapter  Faraday.default_adapter # make requests with Net::HTTP
101✔
72
      end
73
      conn
101✔
74
    end
75

76
    def scsb_param_mapping(bib, user, item)
1✔
77
      request_type = if item["delivery_mode_#{item['item_id']}"].nil?
7✔
78
                       item['type']
×
79
                     else
80
                       item["delivery_mode_#{item['item_id']}"]
7✔
81
                     end
82
      { author: item[:edd_author], bibId: bib[:id],
7✔
83
        callNumber: item[:call_number], chapterTitle: item[:edd_art_title],
84
        deliveryLocation: item[:pick_up] || "", emailAddress: user.active_email,
85
        endPage: item[:edd_end_page], issue: item[:edd_issue], itemBarcodes: [item[:barcode]],
86
        itemOwningInstitution: scsb_owning_institution(item[:location_code]),
87
        patronBarcode: user.barcode || '198572131', requestNotes: item[:edd_note],
88
        requestType: scsb_request_map(request_type), requestingInstitution: requesting_institution,
89
        startPage: item[:edd_start_page], titleIdentifier: bib[:title],
90
        username: user.netid, volume: item[:edd_volume_number] }
91
    end
92

93
    # not being used
94
    # def scsb_topic_type(scsb_request_type)
95
    #   if scsb_request_type == 'EDD'
96
    #     '/topic/PUL.EDDT'
97
    #   elsif scsb_request_type == 'RECALL'
98
    #     '/topic/PUL.RecallT'
99
    #   else
100
    #     '/topic/PUL.RequestT'
101
    #   end
102
    # end
103

104
    def scsb_request_map(request_type)
1✔
105
      if request_type == 'edd'
7✔
106
        'EDD'
3✔
107
      else
108
        'RETRIEVAL' # Default is print retrieval
4✔
109
      end
110
    end
111

112
    def requesting_institution
1✔
113
      'PUL'
7✔
114
    end
115

116
    def scsb_owning_institution(location)
1✔
117
      Requests.config[:recap_partner_locations].fetch(location, "PUL")
102✔
118
    end
119

120
    private
1✔
121

122
      def scsb_auth_key
1✔
123
        if !Rails.env.test?
101✔
124
          ENV['SCSB_AUTH_KEY']
×
125
        else
126
          'TESTME'
101✔
127
        end
128
      end
129
  end
130
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc