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

pulibrary / orangelight / 2944ef25-40a3-4aa4-b558-b6cda61adc66

23 Jan 2025 07:54PM UTC coverage: 95.661% (-0.2%) from 95.82%
2944ef25-40a3-4aa4-b558-b6cda61adc66

Pull #4721

circleci

sandbergja
Queue request emails with data in a hash

Then, once it has been queued, turn the hash back into a
Requests::Submission object.

This helps with #4609, since sidekiq only allows us to queue
emails with data in a very specific list of data types.
Pull Request #4721: Queue requests emails with data in a hash

27 of 29 new or added lines in 6 files covered. (93.1%)

10 existing lines in 2 files now uncovered.

5997 of 6269 relevant lines covered (95.66%)

1518.6 hits per line

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

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

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

6
  # Connects this user object to Blacklights Bookmarks.
7
  include Blacklight::User
3✔
8
  # Include default devise modules. Others available are:
9
  # :confirmable, :lockable, :timeoutable and :omniauthable
10
  devise :database_authenticatable, :rememberable,
3✔
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
3✔
18
    username || 'User'
108✔
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?
3✔
24
    provider == 'alma'
2,786✔
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?
3✔
30
    provider == 'cas'
7,664✔
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)
3✔
37
    access_token.uid = access_token.uid.downcase
6✔
38
    User.where(provider: access_token.provider, uid: access_token.uid).first_or_create do |user|
6✔
39
      user.uid = access_token.uid
6✔
40
      user.username = access_token.uid
6✔
41
      user.email = "#{access_token.uid}@princeton.edu"
6✔
42
      user.password = SecureRandom.urlsafe_base64
6✔
43
      user.provider = access_token.provider
6✔
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)
3✔
51
    User.where(provider: access_token.provider, uid: access_token.uid).first_or_initialize do |user|
4✔
52
      user.uid = access_token.uid
1✔
53
      user.username = access_token.uid
1✔
54
      user.guest = false
1✔
55
      user.provider = access_token.provider
1✔
56
    end
57
  end
58

59
  def self.from_hash(user_hash)
3✔
UNCOV
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
3✔
67
    User
2✔
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?
3✔
73
    netids.include? uid
184✔
74
  end
75

76
  private
3✔
77

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