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

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 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