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

pulibrary / orangelight / b4033a01-cc31-437d-91fc-e98f0e1a7f31

22 Nov 2023 03:16PM UTC coverage: 95.408% (-0.07%) from 95.475%
b4033a01-cc31-437d-91fc-e98f0e1a7f31

Pull #3848

circleci

christinach
Allow Alma guest users to request all - In Library Use - from ReCAP
Pull Request #3848: Allow Alma guest users to request all - In Library Use - from ReCAP

5714 of 5989 relevant lines covered (95.41%)

1412.01 hits per line

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

98.8
/app/models/requests/request_decorator.rb
1
# frozen_string_literal: true
2
module Requests
3✔
3
  class RequestDecorator
3✔
4
    delegate :patron,
3✔
5
             :ctx, :system_id, :language, :mfhd, :source, :holdings, :default_pick_ups,
6
             :serial?, :any_loanable_copies?, :requestable?, :all_items_online?,
7
             :thesis?, :numismatics?, :single_aeon_requestable?, :eligible_for_library_services?, :off_site?,
8
             :user_name, :email, # passed to request as login options on the request form
9
             to: :request
10
    delegate :content_tag, :hidden_field_tag, :concat, to: :view_context
3✔
11

12
    alias bib_id system_id
3✔
13

14
    attr_reader :request, :view_context, :first_filtered_requestable, :non_requestable_mesage
3✔
15
    def initialize(request, view_context)
3✔
16
      @request = request
132✔
17
      @view_context = view_context
132✔
18
      @requestable_list = request.requestable.map { |req| RequestableDecorator.new(req, view_context) }
759✔
19
      @first_filtered_requestable = RequestableDecorator.new(request.first_filtered_requestable, view_context)
132✔
20
      @non_requestable_mesage = "See Circulation Desk, there are no requestable items for this record"
132✔
21
    end
22

23
    def requestable
3✔
24
      @requestable_list
3,770✔
25
    end
26

27
    def catalog_url
3✔
28
      "/catalog/#{system_id}"
97✔
29
    end
30

31
    # rubocop:disable Rails/OutputSafety
32
    def patron_message
3✔
33
      return '' if patron.guest?
96✔
34
      return '' if eligible_for_library_services?
94✔
35
      "<div class='alert alert-warning'>#{I18n.t('requests.account.cas_user_no_barcode_msg')}</div>".html_safe
23✔
36
    end
37

38
    def hidden_fields
3✔
39
      hidden_request_tags = ''
92✔
40
      hidden_request_tags += hidden_field_tag "bib[id]", "", value: bib_id
92✔
41
      request.display_metadata.each do |key, value|
92✔
42
        hidden_request_tags += hidden_field_tag "bib[#{key}]", "", value:
368✔
43
      end
44
      hidden_request_tags.html_safe
92✔
45
    end
46
    # rubocop:enable Rails/OutputSafety
47

48
    def format_brief_record_display
3✔
49
      params = request.display_metadata
97✔
50
      content_tag(:dl, class: "dl-horizontal") do
97✔
51
        params.each do |key, value|
97✔
52
          if value.present? && display_label[key].present?
387✔
53
            concat content_tag(:dt, display_label[key].to_s)
269✔
54
            concat content_tag(:dd, value.first.to_s, lang: request.language.to_s, id: display_label[key].gsub(/[^0-9a-z ]/i, '').downcase.to_s)
269✔
55
          end
56
        end
57
      end
58
    end
59

60
    def any_will_submit_via_form?
3✔
61
      return false if requestable.compact_blank.blank? || !eligible_for_library_services?
90✔
62
      requestable.map(&:will_submit_via_form?).any? || any_fill_in_eligible?
67✔
63
    end
64

65
    def any_fill_in_eligible?
3✔
66
      return false unless eligible_for_library_services?
152✔
67
      return false if patron.alma_provider?
127✔
68

69
      fill_in = false
114✔
70
      unless (requestable.count == 1) && (requestable.first.services & ["on_order", "online"]).present?
114✔
71
        if requestable.any? { |r| !(r.services & fill_in_services).empty? }
271✔
72
          if any_items?
42✔
73
            fill_in = true if any_enumerated?
32✔
74
          elsif request.too_many_items?
10✔
75
            fill_in = true
1✔
76
          else
77
            fill_in = any_circulate?
9✔
78
          end
79
        end
80
      end
81
      fill_in
114✔
82
    end
83

84
    def single_item_request?
3✔
85
      requestable.size == 1 && !any_fill_in_eligible?
553✔
86
    end
87

88
    def only_aeon?
3✔
89
      requestable.map(&:aeon?).all?
181✔
90
    end
91

92
    def location_label
3✔
93
      return "" if holding.blank?
176✔
94
      if any_items? && requestable.first.item.temp_loc? && !requestable.first.item.in_resource_sharing?
175✔
95
        label = holding["current_library"]
8✔
96
        label += " - #{holding['current_location']}" if holding["current_location"].present?
8✔
97
      else
98
        label = holding["library"]
167✔
99
        label += " - #{holding['location']}" if holding["location"].present?
167✔
100
      end
101
      label
175✔
102
    end
103

104
    def holding
3✔
105
      if any_items? && requestable.first.item.temp_loc? && !requestable.first.item.in_resource_sharing?
948✔
106
        holdings[requestable.first.item["temp_location_code"]]
44✔
107
      else
108
        holdings[mfhd]
904✔
109
      end
110
    end
111

112
    def alma_provider_on_shelf_item_available?
3✔
113
      patron.alma_provider?  && !off_site? && any_available?
×
114
    end
115

116
    def alma_provider_item_unavailable?
3✔
117
      patron.alma_provider?  && !(any_available? || any_in_process?)
91✔
118
    end
119

120
    private
3✔
121

122
      def display_label
3✔
123
        {
863✔
124
          author: "Author/Artist",
125
          title: "Title",
126
          date: "Published/Created",
127
          id: "Bibliographic ID",
128
          mfhd: "Holding ID (mfhd)"
129
        }.with_indifferent_access
130
      end
131

132
      def fill_in_services
3✔
133
        ["annex", "recap_no_items", "on_shelf"]
162✔
134
      end
135

136
      def any_circulate?
3✔
137
        requestable.any?(&:circulates?)
9✔
138
      end
139

140
      def any_enumerated?
3✔
141
        requestable.any?(&:enumerated?)
32✔
142
      end
143

144
      def any_items?
3✔
145
        requestable.any?(&:item_data?)
1,165✔
146
      end
147

148
      def any_available?
3✔
149
        requestable.any?(&:available?)
11✔
150
      end
151

152
      def any_in_process?
3✔
153
        requestable.any?(&:in_process?)
5✔
154
      end
155
  end
156
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