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

pulibrary / bibdata / f04bc944-f9b4-4a42-8b26-dcacd0e3e688

11 Mar 2025 10:27PM UTC coverage: 34.017% (-58.1%) from 92.162%
f04bc944-f9b4-4a42-8b26-dcacd0e3e688

Pull #2653

circleci

christinach
Add new lc_subject_facet field.
Helps with the vocabulary work https://github.com/pulibrary/orangelight/pull/3386
In this new field we index only the lc subject heading and the subdivisions
So that when the user searches using the Details section, they can query solr for
all the subject headings and their divisions.

This is needed for the Subject browse Vocabulary work.
example: "lc_subject_facet": [
             "Booksellers and bookselling—Italy—Directories",
             "Booksellers and bookselling-Italy",
             "Booksellers and bookselling"
              ]
Pull Request #2653: Add new lc_subject_facet field.

1 of 3 new or added lines in 1 file covered. (33.33%)

2215 existing lines in 93 files now uncovered.

1294 of 3804 relevant lines covered (34.02%)

0.99 hits per line

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

34.09
/app/controllers/patron_controller.rb
1
class PatronController < ApplicationController
1✔
2
  before_action :protect
1✔
3

4
  attr_accessor :patron_id
1✔
5

6
  # Client: This endpoint is used by requests and orangelight for auth and by figgy
7
  #   to log patron types on CDL use
8
  def patron_info
1✔
UNCOV
9
    @patron_id = sanitize(params[:patron_id])
×
UNCOV
10
    info = parse_data
×
UNCOV
11
    info[:ldap] = Ldap.find_by_netid(patron_id) if params[:ldap].present? && sanitize(params[:ldap]) == 'true'
×
UNCOV
12
    respond_to do |wants|
×
UNCOV
13
      wants.json  { render json: MultiJson.dump(info) }
×
14
    end
15
  rescue StandardError => e
UNCOV
16
    handle_alma_exception(exception: e, message: "Error fetching patron: #{@patron_id}")
×
17
  end
18

19
  private
1✔
20

21
    def sanitize(str)
1✔
UNCOV
22
      str.gsub(/[^A-Za-z0-9.]/, '')
×
23
    end
24

25
    def parse_data
1✔
26
      {
UNCOV
27
        netid:,
×
28
        first_name: data['first_name'],
29
        last_name: data['last_name'],
30
        barcode:,
31
        university_id: data['primary_id'],
32
        patron_id: data['primary_id'],
33
        patron_group:,
34
        patron_group_desc: data['user_group']['desc'],
35
        active_email: primary_email
36
      }
37
    end
38

39
    def primary_email
1✔
UNCOV
40
      data['contact_info']['email'].find do |email|
×
UNCOV
41
        email['preferred'] == true
×
42
      end&.fetch('email_address', nil)
43
    end
44

45
    def data
1✔
UNCOV
46
      @data ||= AlmaAdapter.new.find_user(patron_id)
×
47
    end
48

49
    def identifiers
1✔
UNCOV
50
      @identifiers ||= data['user_identifier']
×
51
    end
52

53
    def barcode
1✔
UNCOV
54
      identifiers.find { |id| id['id_type']['value'] == 'BARCODE' && id['status'] == 'ACTIVE' }['value']
×
55
    end
56

57
    def netid
1✔
UNCOV
58
      identifier = identifiers.find { |id| id['id_type']['value'] == 'NET_ID' } || {}
×
UNCOV
59
      identifier['value']
×
60
    end
61

62
    def patron_group
1✔
UNCOV
63
      data['user_group']['value']
×
64
    end
65

66
    def protect
1✔
UNCOV
67
      Rails.logger.info("Incoming patron request: IP is #{request.remote_ip}, User signed in is #{user_signed_in?}")
×
UNCOV
68
      if user_signed_in?
×
UNCOV
69
        deny_access unless current_user.catalog_admin?
×
70
      else
UNCOV
71
        ips = Rails.application.config.ip_allowlist
×
UNCOV
72
        Rails.logger.info("Is IP address excluded from the allow list?: #{ips.exclude?(request.remote_ip)}")
×
UNCOV
73
        if ips.exclude?(request.remote_ip)
×
UNCOV
74
          deny_access
×
UNCOV
75
          Rails.logger.info("Denied patron request: IP #{request.remote_ip} is not in the list: #{ips.join(', ')}")
×
UNCOV
76
          headers = {}.tap do |envs|
×
UNCOV
77
            request.headers.each do |key, value|
×
UNCOV
78
              envs[key] = value if key.downcase.starts_with?('http')
×
79
            end
80
          end
UNCOV
81
          Rails.logger.info("Headers of the request: #{headers}")
×
82
        end
83
      end
84
    end
85

86
    def deny_access
1✔
UNCOV
87
      render plain: 'You are unauthorized', status: :forbidden
×
88
    end
89
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