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

pulibrary / tigerdata-app / 4277060f-79e9-4139-b221-2c2d75d1f822

17 Sep 2025 05:53PM UTC coverage: 88.85% (+0.06%) from 88.792%
4277060f-79e9-4139-b221-2c2d75d1f822

push

circleci

web-flow
Removed table headers from visibility, still accessible for screenreaders (#1853)

2534 of 2852 relevant lines covered (88.85%)

783.84 hits per line

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

81.4
/app/services/princeton_users.rb
1
# frozen_string_literal: true
2
class PrincetonUsers
2✔
3
  CHARS_AND_NUMS =  ('a'..'z').to_a + (0..9).to_a + ['-']
2✔
4
  RDSS_DEVELOPERS = %w[bs3097 jrg5 cac9 hc8719 rl3667 kl37 pp9425 jh6441].freeze
2✔
5

6
  class << self
2✔
7

8

9
    # Returns a list of Users that match the given query
10
    def user_list_query(query)
2✔
11
      tokens = query.downcase.strip.split(/[^a-zA-Z\d]/).compact_blank
37✔
12
      return [] if tokens.count == 0
37✔
13

14
      user_query = tokens.inject(User.all) do |partial_query, token| 
35✔
15
                     search_token = '%'+User.sanitize_sql_like(token)+'%'
47✔
16
                     partial_query.where("(LOWER(display_name) like ?) OR (LOWER(uid) like ?)", search_token, search_token)
47✔
17
                   end
18
      user_query.map{|user| { uid: user.uid, name: user.display_name } }
68✔
19
    end
20

21
    def load_rdss_developers
2✔
22
      RDSS_DEVELOPERS.each do |netid|
2✔
23
        create_user_from_ldap_by_uid(netid)
16✔
24
        rescue TigerData::LdapError
25
        raise TigerData::LdapError, "Unable to create user from LDAP. Are you connected to VPN?"
×
26
      end
27
    end
28

29
    # Creates users from LDAP data, starting with the given uid prefix.
30
    def create_users_from_ldap(current_uid_start: "", ldap_connection: default_ldap_connection)
2✔
31
      CHARS_AND_NUMS.each do |char|
10✔
32
        filter =(~ Net::LDAP::Filter.eq( "pustatus", "guest" )) & Net::LDAP::Filter.eq("uid", "#{current_uid_start}#{char}*")
370✔
33
        people = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
370✔
34
        if ldap_connection.get_operation_result.message == "Success"
370✔
35
          people.each{|person| user_from_ldap(person)}
376✔
36
        else
37
          create_users_from_ldap(current_uid_start: "#{current_uid_start}#{char}", ldap_connection:)
2✔
38
        end
39
      end
40
    end
41

42
    def create_user_from_ldap_by_uid(uid, ldap_connection: default_ldap_connection)
2✔
43
      filter = Net::LDAP::Filter.eq('uid', uid)
16✔
44
      person = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
16✔
45
      raise TigerData::LdapError, "More than one user matches supplied uid: #{uid}" if person.length > 1
16✔
46
      raise TigerData::LdapError, "No user with uid #{uid} found" if person.empty?
16✔
47
      user_from_ldap(person.first)
16✔
48
    end
49

50
    def user_from_ldap(ldap_person)
2✔
51
      return if ldap_person[:edupersonprincipalname].blank?
24✔
52
      uid = ldap_person[:uid].first.downcase
22✔
53
      current_entries = User.where(uid:)
22✔
54
      if current_entries.empty?
22✔
55
        User.create(uid: , display_name: ldap_person[:pudisplayname].first,
22✔
56
                    family_name: ldap_person[:sn].first, given_name: ldap_person[:givenname].first,
57
                    email: ldap_person[:edupersonprincipalname].first, provider: "cas")
58
      else
59
        user = current_entries.first
×
60
        if user.display_name.blank?
×
61
          user.display_name = ldap_person[:pudisplayname].first
×
62
          user.family_name = ldap_person[:sn].first
×
63
          user.given_name = ldap_person[:givenname].first
×
64
          user.provider = "cas"
×
65
          user.save
×
66
        end
67
      end
68
    end
69

70
    def default_ldap_connection
2✔
71
      @default_ldap_connection ||= Net::LDAP.new host: "ldap.princeton.edu", base: "o=Princeton University,c=US", port: 636,
18✔
72
                                                  encryption: {
73
                                                    method: :simple_tls,
74
                                                    tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
75
                                                  }
76
    end
77
  end
78
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