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

pulibrary / tigerdata-app / 2e85105d-f9c8-41e9-8b05-fe438b698516

26 Nov 2025 12:16PM UTC coverage: 71.597% (-8.0%) from 79.623%
2e85105d-f9c8-41e9-8b05-fe438b698516

push

circleci

web-flow
Display the data sponsor and data manager in the dashboard listing (#2247)

Closes #2236 

<img width="1036" height="675" alt="Screenshot 2025-11-25 at 3 07 41 PM"
src="https://github.com/user-attachments/assets/3b6a2189-7f71-4b17-97e5-e66c8fed3cb3"
/>

1 of 3 new or added lines in 1 file covered. (33.33%)

346 existing lines in 26 files now uncovered.

2367 of 3306 relevant lines covered (71.6%)

147.24 hits per line

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

0.0
/app/services/princeton_users.rb
1
# frozen_string_literal: true
UNCOV
2
class PrincetonUsers
×
UNCOV
3
  CHARS_AND_NUMS =  ('a'..'z').to_a + (0..9).to_a + ['-']
×
4

5
  # `cbentler` and `az3007` are required because they come as data manager and data sponsor
6
  # in the default project in the Mediaflux in our Docker image.
UNCOV
7
  RDSS_DEVELOPERS = %w[bs3097 jrg5 cac9 hc8719 rl3667 kl37 pp9425 jh6441 cbentler az3007].freeze
×
8

UNCOV
9
  class << self
×
10

11

12
    # Returns a list of Users that match the given query
UNCOV
13
    def user_list_query(query)
×
UNCOV
14
      tokens = query.downcase.strip.split(/[^a-zA-Z\d]/).compact_blank
×
UNCOV
15
      return [] if tokens.count == 0
×
UNCOV
16
      if (tokens.count == 1)
×
17
        # if I have a single token I might be trying a uid search, so put all the uid matches at the top
UNCOV
18
        uid_query(tokens[0]) | name_query(tokens)
×
UNCOV
19
      else
×
UNCOV
20
        name_query(tokens)
×
UNCOV
21
      end.map{|user| { uid: user.uid, name: user.display_name, display_name: user.display_name_safe } }
×
UNCOV
22
    end
×
23

UNCOV
24
    def uid_query(token)
×
UNCOV
25
      order_sql = User.sanitize_sql_for_order("LENGTH(uid)-LENGTH('#{token}')")
×
UNCOV
26
      search_token = User.sanitize_sql_like(token)+'%'
×
UNCOV
27
      User.where("(uid like ?)",search_token).order(Arel.sql(order_sql)).order(:uid)
×
UNCOV
28
    end
×
29

UNCOV
30
    def name_query(tokens)
×
UNCOV
31
      tokens.inject(User.all) do |partial_query, token|
×
UNCOV
32
        search_token = '%'+User.sanitize_sql_like(token)+'%'
×
UNCOV
33
        partial_query.where("(LOWER(display_name) like ?) OR (LOWER(uid) like ?)", search_token, search_token)
×
UNCOV
34
      end.order(:given_name).order(:family_name)
×
UNCOV
35
    end
×
36

UNCOV
37
    def load_rdss_developers
×
UNCOV
38
      RDSS_DEVELOPERS.each do |netid|
×
UNCOV
39
        create_user_from_ldap_by_uid(netid)
×
UNCOV
40
        rescue TigerData::LdapError
×
UNCOV
41
        raise TigerData::LdapError, "Unable to create user from LDAP. Are you connected to VPN?"
×
UNCOV
42
      end
×
UNCOV
43
    end
×
44

45
    # Creates users from LDAP data, starting with the given uid prefix.
UNCOV
46
    def create_users_from_ldap(current_uid_start: "", ldap_connection: default_ldap_connection)
×
UNCOV
47
      CHARS_AND_NUMS.each do |char|
×
UNCOV
48
        filter =(~ Net::LDAP::Filter.eq( "pustatus", "guest" )) & Net::LDAP::Filter.eq("uid", "#{current_uid_start}#{char}*")
×
UNCOV
49
        people = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
×
UNCOV
50
        if ldap_connection.get_operation_result.message == "Success"
×
UNCOV
51
          people.each{|person| user_from_ldap(person)}
×
UNCOV
52
        else
×
UNCOV
53
          create_users_from_ldap(current_uid_start: "#{current_uid_start}#{char}", ldap_connection:)
×
UNCOV
54
        end
×
UNCOV
55
      end
×
UNCOV
56
    end
×
57

UNCOV
58
    def create_user_from_ldap_by_uid(uid, ldap_connection: default_ldap_connection)
×
UNCOV
59
      filter = Net::LDAP::Filter.eq('uid', uid)
×
UNCOV
60
      person = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
×
UNCOV
61
      raise TigerData::LdapError, "More than one user matches supplied uid: #{uid}" if person.length > 1
×
UNCOV
62
      raise TigerData::LdapError, "No user with uid #{uid} found" if person.empty?
×
UNCOV
63
      user_from_ldap(person.first)
×
UNCOV
64
    end
×
65

66
  # Creates or updates a User from an LDAP entry.
67
  # @param ldap_person [Net::LDAP::Entry] an LDAP entry representing a person
68
  # @return [User, nil] the created or updated User, or nil if the LDAP entry is missing a edupersonprincipalname
UNCOV
69
    def user_from_ldap(ldap_person)
×
UNCOV
70
      return if check_for_malformed_ldap_entries(ldap_person)
×
UNCOV
71
      uid = ldap_person[:uid].first.downcase
×
UNCOV
72
      current_entries = User.where(uid:)
×
UNCOV
73
      if current_entries.empty?
×
UNCOV
74
        User.create(uid: , display_name: ldap_person[:pudisplayname].first,
×
UNCOV
75
                    family_name: ldap_person[:sn].first, given_name: ldap_person[:givenname].first,
×
UNCOV
76
                    email: ldap_person[:edupersonprincipalname].first, provider: "cas")
×
UNCOV
77
      else
×
UNCOV
78
        user = current_entries.first
×
UNCOV
79
        if user.display_name.blank?
×
UNCOV
80
          user.display_name = ldap_person[:pudisplayname].first
×
UNCOV
81
          user.family_name = ldap_person[:sn].first
×
UNCOV
82
          user.given_name = ldap_person[:givenname].first
×
UNCOV
83
          user.provider = "cas"
×
UNCOV
84
          user.save
×
UNCOV
85
        end
×
UNCOV
86
        user
×
UNCOV
87
      end
×
UNCOV
88
    end
×
89

90
    # If any required LDAP fields are missing, return true
91
    # @param ldap_person [Net::LDAP::Entry] an LDAP entry representing a person
92
    # @return [Boolean] true if the LDAP entry is missing required fields, false otherwise
UNCOV
93
    def check_for_malformed_ldap_entries(ldap_person)
×
UNCOV
94
      uid_blank = ldap_person[:uid].blank?
×
UNCOV
95
      edupersonprincipalname_blank = ldap_person[:edupersonprincipalname].blank?
×
UNCOV
96
      malformed = uid_blank || edupersonprincipalname_blank
×
UNCOV
97
      malformed
×
UNCOV
98
    end
×
99

UNCOV
100
    def default_ldap_connection
×
UNCOV
101
      @default_ldap_connection ||= Net::LDAP.new host: "ldap.princeton.edu", base: "o=Princeton University,c=US", port: 636,
×
UNCOV
102
                                                  encryption: {
×
UNCOV
103
                                                    method: :simple_tls,
×
UNCOV
104
                                                    tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
×
UNCOV
105
                                                  }
×
UNCOV
106
    end
×
UNCOV
107
  end
×
UNCOV
108
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