Class: PsuDir::Disambiguate::User

Inherits:
Ldap
  • Object
show all
Defined in:
lib/psu_dir/disambiguate/user.rb

Overview

This class provides an api for querying LDAP with different portions of the user’s information (name parts or id)

Class Method Summary collapse

Methods inherited from Ldap

get_users, ldap_error_message, retry_if, tries, unwilling?

Class Method Details

.directory_attributes(login, attrs = []) ⇒ Object



8
9
10
11
12
# File 'lib/psu_dir/disambiguate/user.rb', line 8

def directory_attributes(, attrs = [])
  filter = Net::LDAP::Filter.eq('uid', )
  result = get_users(filter, attrs)
  format_users(result, attrs)
end

.get_filtered_users(name_filter, attrs = []) ⇒ Object



32
33
34
35
36
# File 'lib/psu_dir/disambiguate/user.rb', line 32

def get_filtered_users(name_filter, attrs = [])
  attrs = (attrs + default_attributes).uniq
  filter = Net::LDAP::Filter.construct("(& (& #{name_filter}) #{person_filter})")
  get_users(filter, attrs)
end

.query_ldap_by_mail(email, attrs = []) ⇒ Object



14
15
16
17
18
# File 'lib/psu_dir/disambiguate/user.rb', line 14

def query_ldap_by_mail(email, attrs = [])
  filter = Net::LDAP::Filter.construct(email_filter(email))
  users  = get_filtered_users(filter, attrs)
  format_users(users, attrs)
end

.query_ldap_by_name(given_name, surname, attrs = []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/psu_dir/disambiguate/user.rb', line 20

def query_ldap_by_name(given_name, surname, attrs = [])
  return [] if given_name.blank? # this method only work if we have a first name to play with

  first_names = given_name.split(/[\s.]+/)
  users = []
  name_filters(first_names[0], first_names[1], surname).each do |filter|
    users = get_filtered_users(filter, attrs)
    break if users.count.positive? # stop running through the filters if we get results
  end
  format_users(users, attrs)
end

.results_hash(opts) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/psu_dir/disambiguate/user.rb', line 38

def results_hash(opts)
  {
    id:          fetch(opts, :uid).first,
    given_name:  fetch(opts, :givenname).first,
    surname:     fetch(opts, :sn).first,
    email:       fetch(opts, :mail).first,
    affiliation: fetch(opts, :eduPersonPrimaryAffiliation, []),
    displayname: fetch(opts, :displayname).first
  }
end