• 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

60.61
/app/models/user.rb
1
# frozen_string_literal: true
2

3
class User < ApplicationRecord
1✔
4
  validates :username, presence: true
1✔
5

6
  # Connects this user object to Blacklights Bookmarks.
7
  include Blacklight::User
1✔
8
  # Include default devise modules. Others available are:
9
  # :confirmable, :lockable, :timeoutable and :omniauthable
10
  devise :database_authenticatable, :rememberable,
1✔
11
         :trackable, :omniauthable
12

13
  # Method added by Blacklight; Blacklight uses #to_s on your
14
  # user class to get a user-displayable login/identifier for
15
  # the account.
16
  # @return [String] the user name
17
  def to_s
1✔
18
    username || 'User'
73✔
19
  end
20

21
  # Determines whether or not this is a user which is identifiable by alma
22
  # @return [TrueClass, FalseClass]
23
  def alma_provider?
1✔
24
    provider == 'alma'
2,612✔
25
  end
26

27
  # Determines whether or not this is a user which is identifiable by cas
28
  # @return [TrueClass, FalseClass]
29
  def cas_provider?
1✔
30
    provider == 'cas'
6,802✔
31
  end
32

33
  # Retrieves a user authenticated using the CAS
34
  # @param access_token []
35
  # @return [User,nil]
36
  def self.from_cas(access_token)
1✔
37
    access_token.uid = access_token.uid.downcase
×
38
    User.where(provider: access_token.provider, uid: access_token.uid).first_or_create do |user|
×
39
      user.uid = access_token.uid
×
40
      user.username = access_token.uid
×
41
      user.email = "#{access_token.uid}@princeton.edu"
×
42
      user.password = SecureRandom.urlsafe_base64
×
43
      user.provider = access_token.provider
×
44
    end
45
  end
46

47
  # Retrieves a user authenticated using an Alma account
48
  # @param access_token [] access token containing the barcode accessed using #uid
49
  # @return [User,nil]
50
  def self.from_alma(access_token)
1✔
51
    User.where(provider: access_token.provider, uid: access_token.uid).first_or_initialize do |user|
3✔
52
      user.uid = access_token.uid
×
53
      user.username = access_token.uid
×
54
      user.guest = false
×
55
      user.provider = access_token.provider
×
56
    end
57
  end
58

59
  def self.from_hash(user_hash)
1✔
60
    User.where(provider: user_hash['provider'], uid: user_hash['uid']).first
×
61
  end
62

63
  # Alternative to the implementation used in devise-guests, due to memory use
64
  # problems when running that task
65
  # https://github.com/cbeer/devise-guests/blob/7ab8c55d7a2b677ce61cc83486d6e3723d8795b2/lib/railties/devise_guests.rake
66
  def self.expire_guest_accounts
1✔
67
    User
×
68
      .where("guest = ? and updated_at < ?", true, Time.now.utc - 3.days)
69
      .find_each(batch_size: 25_000, &:destroy)
70
  end
71

72
  def admin?
1✔
73
    netids.include? uid
121✔
74
  end
75

76
  private
1✔
77

78
    def netids
1✔
79
      @netids ||= ENV['ORANGELIGHT_ADMIN_NETIDS']&.split(" ") || ""
121✔
80
    end
81
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