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

pulibrary / tigerdata-app / 08c0f2d4-d9d2-405e-8877-48785d70651c

01 Aug 2025 05:24PM UTC coverage: 75.569% (-2.4%) from 77.946%
08c0f2d4-d9d2-405e-8877-48785d70651c

Pull #1670

circleci

kelynch
Added rake tasks for user privilege assignments and updated README
Pull Request #1670: 1610 remove load users registration

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

34 existing lines in 2 files now uncovered.

2224 of 2943 relevant lines covered (75.57%)

312.03 hits per line

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

63.64
/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

5
  class << self
1✔
6

7
    def user_list
1✔
8
      Rails.cache.fetch("princeton_user_list", expires_in: 6.hours) do
55✔
9
        @user_list = User.all.map { |user| { uid: user.uid, name: user.display_name } }
112✔
10
      end
11
    end
12

13
    def create_users_from_ldap(current_uid_start: "", ldap_connection: default_ldap_connection)
1✔
14
      CHARS_AND_NUMS.each do |char|
4✔
15
        filter =(~ Net::LDAP::Filter.eq( "pustatus", "guest" )) & Net::LDAP::Filter.eq("uid", "#{current_uid_start}#{char}*")
148✔
16
        people = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
148✔
17
        if ldap_connection.get_operation_result.message == "Success"
148✔
18
          people.each{|person| user_from_ldap(person)}
150✔
19
        else
20
          create_users_from_ldap(current_uid_start: "#{current_uid_start}#{char}", ldap_connection:)
1✔
21
        end
22
      end
23
    end
24

25
    def create_user_from_ldap_by_uid(uid, ldap_connection: default_ldap_connection)
1✔
NEW
26
      filter = Net::LDAP::Filter.eq('uid', uid)
×
NEW
27
      person = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
×
NEW
28
      raise StandardError "More than one user matches supplied uid: #{uid}" if person.length > 1
×
NEW
29
      raise StandardError "No user with uid #{uid} found" if person.empty?
×
NEW
30
      user_from_ldap(person.first)
×
31
    end
32

33
    def user_from_ldap(ldap_person)
1✔
34
      return if ldap_person[:edupersonprincipalname].blank?
3✔
35
      uid = ldap_person[:uid].first.downcase
2✔
36
      current_entries = User.where(uid:)
2✔
37
      if current_entries.empty?
2✔
38
        User.create(uid: , display_name: ldap_person[:pudisplayname].first, 
2✔
39
                    family_name: ldap_person[:sn].first, given_name: ldap_person[:givenname].first, 
40
                    email: ldap_person[:edupersonprincipalname].first)
41
      else
42
        user = current_entries.first
×
43
        if user.display_name.blank?
×
44
          user.display_name = ldap_person[:pudisplayname].first
×
45
          user.family_name = ldap_person[:sn].first
×
46
          user.given_name = ldap_person[:givenname].first
×
47
          user.save
×
48
        end
49
      end
50
    end
51

52
    def default_ldap_connection
1✔
53
      @default_ldap_connection ||= Net::LDAP.new host: "ldap.princeton.edu", base: "o=Princeton University,c=US", port: 636,
×
54
                                                  encryption: {
55
                                                    method: :simple_tls,
56
                                                    tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
57
                                                  }
58
    end
59
  end
60
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