• 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

85.57
/app/helpers/requests/application_helper.rb
1
# frozen_string_literal: true
2
# rubocop:disable Metrics/ModuleLength
3
module Requests
1✔
4
  module ApplicationHelper
1✔
5
    def format_email(email)
1✔
6
      email&.downcase
134✔
7
    end
8

9
    def format_label(key)
1✔
10
      label = key.to_s
×
11
      human_label = label.tr('_', ' ')
×
12
      formatted = human_label.split.map(&:capitalize).join(' ')
×
13
      formatted
×
14
    end
15

16
    def error_key_format(key)
1✔
17
      keys_to_ignore = ['items']
×
18
      format_label(key) unless keys_to_ignore.include? key.to_s
×
19
    end
20

21
    # array of error_keys
22
    def guest_user_error?(error_keys)
1✔
23
      user_errors = [:email, :user_name, :barcode]
×
24
      error_keys.any? { |item| user_errors.include? item }
×
25
    end
26

27
    def show_pick_up_service_options(requestable, mfhd_id)
1✔
28
      if requestable.on_shelf?
135✔
29
        display_on_shelf(requestable, mfhd_id)
66✔
30
      else
31
        display_requestable_list(requestable)
69✔
32
      end
33
    end
34

35
    def show_service_options(requestable, _mfhd_id)
1✔
36
      if requestable.no_services?
×
37
        content_tag(:div, "#{requestable.title} #{enum_copy_display(requestable.item)} #{sanitize(I18n.t('requests.no_services.brief_msg'))}", class: 'visually-hidden') +
×
38
          content_tag(:div, sanitize(I18n.t("requests.no_services.brief_msg")), class: 'service-item', aria: { hidden: true })
39
      elsif requestable.charged? && !requestable.aeon? && !requestable.ask_me?
×
40
        render partial: 'checked_out_options', locals: { requestable: }
×
41
      else
42
        display_requestable_list(requestable)
×
43
      end
44
    end
45

46
    def hidden_service_options(requestable, fill_in: false)
1✔
47
      return hidden_service_options_fill_in(requestable) if fill_in
130✔
48
      hidden = output_request_input(requestable)
119✔
49
      return hidden if hidden.present?
119✔
50

51
      if requestable.services.include? 'recap'
49✔
52
        recap_print_only_input requestable
40✔
53
      else
54
        request_input(requestable.services.first)
9✔
55
      end
56
    end
57

58
    def output_request_input(requestable)
1✔
59
      output = ""
119✔
60
      ['annex', 'pres', 'ppl', 'lewis', 'paging', 'on_order', 'on_shelf'].each do |type|
119✔
61
        next unless requestable.services.include?(type)
779✔
62
        output = request_input(type)
70✔
63
        break
70✔
64
      end
65
      output
119✔
66
    end
67

68
    # only requestable services that support "user-supplied volume info"
69
    def hidden_service_options_fill_in(requestable)
1✔
70
      if requestable.annex?
11✔
71
        request_input('annex')
2✔
72
      elsif requestable.services.include? 'recap_no_items'
9✔
73
        request_input('recap_no_items')
1✔
74
      else
75
        request_input('paging')
8✔
76
      end
77
    end
78

79
    def recap_print_only_input(requestable)
1✔
80
      content_tag(:fieldset, class: 'recap--print', id: "recap_group_#{requestable.preferred_request_id}") do
40✔
81
        concat hidden_field_tag "requestable[][type]", "", value: 'recap'
40✔
82
      end
83
    end
84

85
    # rubocop:disable Style/NumericPredicate
86
    def enum_copy_display(item)
1✔
87
      return "" if item.blank?
510✔
88
      [item.description, item.copy_value].join(" ").strip
509✔
89
    end
90
    # rubocop:enable Style/NumericPredicate
91

92
    def request_input(type)
1✔
93
      hidden_field_tag "requestable[][type]", "", value: type
96✔
94
    end
95

96
    def gfa_lookup(lib_code)
1✔
97
      if lib_code == "firestone"
2✔
98
        "PA"
×
99
      else
100
        lib = Requests::BibdataService.delivery_locations.select { |_key, hash| hash["library"]["code"] == lib_code }
48✔
101
        lib.keys.first.to_s
2✔
102
      end
103
    end
104

105
    def pick_up_classlist(requestable, collapse)
1✔
106
      class_list = "collapse request--print"
142✔
107
      class_list += " show" if !requestable.digitize? && !collapse
142✔
108
      class_list
142✔
109
    end
110

111
    # move this to requestable object
112
    # Default pick-ups should be available
113
    def pick_up_choices(requestable, default_pick_ups, collapse = false)
1✔
114
      content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}", class: pick_up_classlist(requestable, collapse)) do
135✔
115
        preferred_request_content_tag(requestable, requestable.pick_up_locations || default_pick_ups)
135✔
116
      end
117
    end
118

119
    def preferred_request_content_tag(requestable, default_pick_ups)
1✔
120
      (show_pick_up_service_options(requestable, nil) || "".html_safe) +
135✔
121
        content_tag(:div, id: "fields-print__#{requestable.preferred_request_id}_card", class: "card card-body bg-light") do
122
          locs = pick_up_locations(requestable, default_pick_ups)
135✔
123
          # temporary changes issue 438
124
          name = 'requestable[][pick_up]'
135✔
125
          id = "requestable__pick_up_#{requestable.preferred_request_id}"
135✔
126
          if locs.size > 1
135✔
127
            select_tag name.to_s, options_for_select(locs.map { |loc| [loc[:label], { 'pick_up' => loc[:gfa_pickup], 'pick_up_location_code' => loc[:pick_up_location_code] }.to_json] }), prompt: I18n.t("requests.default.pick_up_placeholder"), id: id
539✔
128
          else
129
            single_pickup(requestable.charged?, name, id, locs[0])
77✔
130
          end
131
        end
132
    end
133

134
    def available_pick_ups(requestable, default_pick_ups)
1✔
135
      idx = (default_pick_ups.pluck(:label)).index(requestable.location.library_label)
127✔
136
      if idx.present?
127✔
137
        [default_pick_ups[idx]]
36✔
138
      elsif requestable.recap? || requestable.annex?
91✔
139
        locations = requestable.pick_up_locations || default_pick_ups
59✔
140
        # open libraries
141
        pick_ups = locations.select { |loc| ['PJ', 'PA', 'PL', 'PK', 'PM', 'PT', 'QX', 'PW', 'QA', 'QT', 'QC'].include?(loc[:gfa_pickup]) }
740✔
142
        pick_ups << default_pick_ups[0] if pick_ups.empty?
59✔
143
        pick_ups
59✔
144
      else
145
        [default_pick_ups[0]]
32✔
146
      end
147
    end
148

149
    # rubocop:disable Rails/OutputSafety
150
    def hidden_fields_mfhd(mfhd)
1✔
151
      hidden = ""
63✔
152
      return hidden if mfhd.nil?
63✔
153
      hidden += hidden_field_tag "mfhd[][call_number]", "", value: (mfhd['call_number']).to_s unless mfhd["call_number"].nil?
63✔
154
      hidden += hidden_field_tag "mfhd[][location]", "", value: (mfhd['location']).to_s unless mfhd["location"].nil?
63✔
155
      hidden += hidden_field_tag "mfhd[][library]", "", value: (mfhd['library']).to_s
63✔
156
      hidden.html_safe
63✔
157
    end
158
    # rubocop:enable Rails/OutputSafety
159

160
    def hidden_fields_item(requestable)
1✔
161
      request_id = requestable.preferred_request_id
515✔
162
      hidden = hidden_field_tag "requestable[][bibid]", "", value: requestable.bib[:id].to_s, id: "requestable_bibid_#{request_id}"
515✔
163
      hidden += hidden_field_tag "requestable[][mfhd]", "", value: requestable.holding.mfhd_id, id: "requestable_mfhd_#{request_id}"
515✔
164
      hidden += hidden_field_tag "requestable[][call_number]", "", value: requestable.holding.holding_data['call_number'].to_s, id: "requestable_call_number_#{request_id}" unless requestable.holding.holding_data["call_number"].nil?
515✔
165
      hidden += hidden_field_tag "requestable[][location_code]", "", value: requestable.item_location_code.to_s, id: "requestable_location_#{request_id}"
515✔
166
      hidden += if requestable.item?
515✔
167
                  hidden_fields_for_item(item: requestable.item, preferred_request_id: requestable.preferred_request_id)
503✔
168
                else
169
                  hidden_field_tag("requestable[][item_id]", "", value: requestable.preferred_request_id, id: "requestable_item_id_#{requestable.preferred_request_id}")
12✔
170
                end
171
      hidden += hidden_fields_for_scsb(item: requestable.item) if requestable.partner_holding?
515✔
172
      hidden
515✔
173
    end
174

175
    def isbn_string(array_of_isbns)
1✔
176
      array_of_isbns.join(',')
×
177
    end
178

179
    def suppress_login?(request)
1✔
180
      request.only_aeon?
68✔
181
    end
182

183
    def item_checkbox(requestable, single_item_form)
1✔
184
      disabled = !requestable.will_submit_via_form?
504✔
185
      check_box_tag "requestable[][selected]", true, check_box_selected?(disabled, single_item_form), class: 'request--select', disabled:, aria: { labelledby: "title enum_#{requestable.preferred_request_id}" }, id: "requestable_selected_#{requestable.preferred_request_id}"
504✔
186
    end
187

188
    ## If any requestable items have a temp location assume everything at the holding is in a temp loc?
189
    def current_location_label(holding_location_label, requestable_list)
1✔
190
      first_location = requestable_list.first.location
127✔
191
      location_label = first_location.short_label.blank? ? "" : "- #{first_location.short_label}"
127✔
192
      label = if requestable_list.first.temp_loc_other_than_resource_sharing?
127✔
193
                "#{first_location.library_label}#{location_label}"
4✔
194
              else
195
                holding_location_label
123✔
196
              end
197
      "#{label} #{requestable_list.first.call_number}"
127✔
198
    end
199

200
    def check_box_selected?(disabled, single_item_form)
1✔
201
      if single_item_form
504✔
202
        !disabled
32✔
203
      else
204
        false
472✔
205
      end
206
    end
207

208
    def submit_button_disabled?(requestable_list)
1✔
209
      # temporary chane issue 438 guest can no longer check out materials
210
      return true if @user.blank? || @user.guest
43✔
211
      return unsubmittable? requestable_list unless requestable_list.size == 1
43✔
212
      # temporary changes issue 438 do not disable the button for circulating items
213
      # requestable_list.first.services.empty? || requestable_list.first.on_reserve? || (requestable_list.first.services.include? 'on_shelf') || requestable_list.first.ask_me?
214
      requestable_list.first.services.empty? || requestable_list.first.on_reserve?
34✔
215
    end
216

217
    def unsubmittable?(requestable_list)
1✔
218
      !requestable_list.any? { |requestable| (requestable.services | submitable_services).present? }
18✔
219
    end
220

221
    def submitable_services
1✔
222
      ['on_shelf', 'in_process', 'on_order', 'annex', 'recap', 'recap_edd', 'paging', 'recap_no_items', 'ppl', 'lewis']
9✔
223
    end
224

225
    def submit_message(requestable_list)
1✔
226
      single_item = "Request this Item"
43✔
227
      multi_item = "Request Selected Items"
43✔
228
      no_item = "No Items Available"
43✔
229
      return multi_item unless requestable_list.size == 1
43✔
230
      if requestable_list.first.services.empty?
34✔
231
        no_item
×
232
      elsif requestable_list.first.annex?
34✔
233
        # Annex items have the potential to display the
234
        # use the fill-in form, where a user could potentially
235
        # request multiple volumes.  For that reason, we show
236
        # the plural form "Request Selected Items" in this case
237
        multi_item
3✔
238
      else
239
        single_item
31✔
240
      end
241
    end
242

243
    # only show the table sort if there are enough items
244
    # to make it worthwhile
245
    def show_tablesorter(requestable_list)
1✔
246
      return "tablesorter" if table_sorter_present?(requestable_list)
64✔
247
      ""
55✔
248
    end
249

250
    def table_sorter_present?(requestable_list)
1✔
251
      requestable_list.size > 5
97✔
252
    end
253

254
    def display_label
1✔
255
      {
×
256
        author: "Author/Artist",
257
        title: "Title",
258
        date: "Published/Created",
259
        id: "Bibliographic ID",
260
        mfhd: "Holding ID (mfhd)"
261
      }.with_indifferent_access
262
    end
263

264
    def display_status(requestable)
1✔
265
      content_tag(:span, requestable.item['status']) unless requestable.item.nil?
×
266
    end
267

268
    def system_status_label(requestable)
1✔
269
      return "" if requestable.item.blank?
×
270
      content_tag(:div, requestable.item[:status], class: 'system-status')
×
271
    end
272

273
    def display_urls(requestable)
1✔
274
      content_tag :ol do
×
275
        requestable.urls.each do |key, value|
×
276
          unless key == 'iiif_manifest_paths'
×
277
            value.reverse!
×
278
            concat content_tag(:li, link_to(value.join(": "), key), class: 'link')
×
279
          end
280
        end
281
      end
282
    end
283

284
    private
1✔
285

286
      def display_requestable_list(requestable)
1✔
287
        return if requestable.no_services?
135✔
288
        content_tag(:ul, class: "service-list") do
133✔
289
          if requestable.ill_eligible?
133✔
290
            concat content_tag(:li, sanitize(I18n.t("requests.ill.brief_msg")), class: "service-item")
1✔
291
          else
292
            # there are no instances where more than one actual service is available to an item, so we are going to take the first service that is not edd
293
            filtered_services = if requestable.services.size == 1 && requestable.services.first.include?("edd")
132✔
294
                                  requestable.services
×
295
                                else
296
                                  requestable.services.reject { |service_name| service_name.include?("edd") }
387✔
297
                                end
298
            brief_msg = I18n.t("requests.#{filtered_services.first}.brief_msg")
132✔
299
            concat content_tag(:li, sanitize(brief_msg), class: "service-item")
132✔
300
          end
301
        end
302
      end
303

304
      def display_on_shelf(requestable, _mfhd_id)
1✔
305
        content_tag(:div) do
66✔
306
          display_requestable_list(requestable)
66✔
307
        end
308
      end
309

310
      def pick_up_locations(requestable, default_pick_ups)
1✔
311
        return [default_pick_ups[0]] if requestable.ill_eligible?
135✔
312
        return available_pick_ups(requestable, default_pick_ups) unless requestable.pending?
134✔
313
        if requestable.delivery_location_label.present?
7✔
314
          [{ label: requestable.delivery_location_label, gfa_pickup: requestable.delivery_location_code, pick_up_location_code: requestable.pick_up_location_code, staff_only: false }]
5✔
315
        else
316
          # TODO: Why is this option here
317
          [{ label: requestable.location.library_label, gfa_pickup: gfa_lookup(requestable.location.library_code), staff_only: false }]
2✔
318
        end
319
      end
320

321
      def hidden_fields_for_item(item:, preferred_request_id:)
1✔
322
        hidden = hidden_field_tag("requestable[][item_id]", "", value: preferred_request_id.to_s, id: "requestable_item_id_#{preferred_request_id}")
503✔
323
        hidden += hidden_field_tag("requestable[][barcode]", "", value: item['barcode'].to_s, id: "requestable_barcode_#{preferred_request_id}") unless item["barcode"].nil?
503✔
324
        hidden += hidden_field_tag("requestable[][enum]", "", value: item.enum_value.to_s, id: "requestable_enum_#{preferred_request_id}") if item.enum_value.present?
503✔
325
        hidden += hidden_field_tag("requestable[][copy_number]", "", value: item.copy_number.to_s, id: "requestable_copy_number_#{preferred_request_id}")
503✔
326
        hidden + hidden_field_tag("requestable[][status]", "", value: item['status'].to_s, id: "requestable_status_#{preferred_request_id}")
503✔
327
      end
328

329
      def hidden_fields_for_scsb(item:)
1✔
330
        hidden = hidden_field_tag("requestable[][cgd]", "", value: item['cgd'].to_s, id: "requestable_cgd_#{item['id']}")
4✔
331
        hidden += hidden_field_tag("requestable[][cc]", "", value: item['collection_code'].to_s, id: "requestable_collection_code_#{item['id']}")
4✔
332
        hidden + hidden_field_tag("requestable[][use_statement]", "", value: item['use_statement'].to_s, id: "requestable_use_statement_#{item['id']}")
4✔
333
      end
334

335
      def single_pickup(is_charged, name, id, location)
1✔
336
        style = if is_charged
77✔
337
                  'margin-top:10px;'
×
338
                else
339
                  ''
77✔
340
                end
341
        hidden = hidden_field_tag name.to_s, "", value: { 'pick_up' => location[:gfa_pickup], 'pick_up_location_code' => location[:pick_up_location_code] }.to_json, class: 'single-pick-up-hidden', id: id
77✔
342
        label = label_tag id, "Pick-up location: #{location[:label]}", class: 'single-pick-up', style: style.to_s
77✔
343
        hidden + label
77✔
344
      end
345

346
      def aeon_base
1✔
347
        Requests.config[:aeon_base]
×
348
      end
349
  end
350
end
351
# rubocop:enable Metrics/ModuleLength
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