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

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

0.01 hits per line

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

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

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

6
  # Connects this user object to Blacklights Bookmarks.
7
  include Blacklight::User
×
8
  # Include default devise modules. Others available are:
9
  # :confirmable, :lockable, :timeoutable and :omniauthable
10
  devise :database_authenticatable, :rememberable,
×
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
×
18
    username || 'User'
×
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?
×
24
    provider == 'alma'
×
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?
×
30
    provider == 'cas'
×
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)
×
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)
×
51
    User.where(provider: access_token.provider, uid: access_token.uid).first_or_initialize do |user|
×
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)
×
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
×
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?
×
73
    netids.include? uid
×
74
  end
×
75

76
  private
×
77

78
    def netids
×
79
      @netids ||= ENV['ORANGELIGHT_ADMIN_NETIDS']&.split(" ") || ""
×
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