Class: LdapDisambiguate::LdapUser

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap_disambiguate/ldap_user.rb

Overview

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

Class Method Summary collapse

Class Method Details

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



7
8
9
10
# File 'lib/ldap_disambiguate/ldap_user.rb', line 7

def directory_attributes(, attrs = [])
  filter = Net::LDAP::Filter.eq('uid', )
  get_ldap_response(:get_user, filter, attrs)
end

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



33
34
35
36
37
38
# File 'lib/ldap_disambiguate/ldap_user.rb', line 33

def get_users(name_filter, attrs = [])
  attrs = (attrs + default_attributes).uniq
  person_filter = '(| (eduPersonPrimaryAffiliation=STUDENT) (eduPersonPrimaryAffiliation=FACULTY) (eduPersonPrimaryAffiliation=STAFF) (eduPersonPrimaryAffiliation=EMPLOYEE) (eduPersonPrimaryAffiliation=RETIREE) (eduPersonPrimaryAffiliation=EMERITUS) (eduPersonPrimaryAffiliation=MEMBER)))'
  filter = Net::LDAP::Filter.construct("(& (& #{name_filter}) #{person_filter})")
  get_ldap_response(:get_user, filter, attrs)
end

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



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ldap_disambiguate/ldap_user.rb', line 21

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_users(filter, attrs)
    break if users.count > 0 # stop running through the filters if we get results
  end
  format_users(users, attrs)
end

.query_ldap_by_name_or_id(id_or_name_part) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ldap_disambiguate/ldap_user.rb', line 12

def query_ldap_by_name_or_id(id_or_name_part)
  filter = Net::LDAP::Filter.construct("(& (| (uid=#{id_or_name_part}* ) (givenname=#{id_or_name_part}*) (sn=#{id_or_name_part}*)) #{person_filter})")
  users  = get_ldap_response(:get_user, filter, %w(uid displayname))

  # handle the issue that searching with a few letters returns more than 1000 items wich causes an error in the system
  users = get_user_by_partial_id(id_or_name_part) if size_limit_exceeded?
  users.map { |u| { id: u[:uid].first, text: "#{u[:displayname].first} (#{u[:uid].first})" } }
end