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

pulibrary / tigerdata-app / 4174731a-1fbc-41e9-98e7-dcf30b6a3cd3

03 Sep 2025 05:55PM UTC coverage: 87.885% (-1.2%) from 89.044%
4174731a-1fbc-41e9-98e7-dcf30b6a3cd3

Pull #1810

circleci

leefaisonr
adjust user views
Pull Request #1810: allow users to see sponsored and managed projects

2 of 2 new or added lines in 1 file covered. (100.0%)

19 existing lines in 5 files now uncovered.

2452 of 2790 relevant lines covered (87.89%)

328.97 hits per line

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

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

6
  class << self
1✔
7

8
    # Return the list of Users who are already in the database.
9
    def user_list
1✔
10
      Rails.cache.fetch("princeton_user_list", expires_in: 6.hours) do
79✔
11
        @user_list = User.all.map { |user| { uid: user.uid, name: user.display_name } }
168✔
12
      end
13
    end
14

15
    def user_list_query(query)
1✔
16
      return [] if query == ""
26✔
17
      user_list.select { |user| user[:uid].downcase.include?(query) || user[:name]&.downcase&.include?(query) }
52✔
18
    end
19

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

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

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

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

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