Class: UCB::LDAP::Person

Inherits:
Entry
  • Object
show all
Includes:
AffiliationMethods, CommonAttributes
Defined in:
lib/ucb_ldap/person.rb

Overview

UCB::LDAP::Person

Class for accessing the People tree of the UCB LDAP directory.

You can search by specifying your own filter:

e = Person.search(:filter => {:uid => 123})

Or you can use a convenience search method:

e = Person.find_by_uid("123")

Access attributes as if they were instance methods:

e = Person.find_by_uid("123")

e.givenname    #=> "John"
e.sn           #=> "Doe"

Methods with friendly names are provided for accessing attribute values:

e = Person.person_by_uid("123")

e.firstname    #=> "John"
e.lastname     #=> "Doe"

There are other convenience methods:

e = Person.person_by_uid("123")

e.affiliations        #=> ["EMPLOYEE-TYPE-STAFF"]
e.employee?           #=> true
e.employee_staff?     #=> true
e.employee_academic?  #=> false
e.student?            #=> false

Other Parts of the Tree

You can access other parts of the LDAP directory through Person instances:

p = Person.find_by_uid("123")

p.org_node          #=> Org
p.affiliations      #=> Array of Affiliation

Attributes

See Ldap::Entry for general information on accessing attribute values.

Direct Known Subclasses

ExpiredPerson

Defined Under Namespace

Classes: RecordNotFound

Constant Summary

Constants inherited from Entry

Entry::TESTING

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonAttributes

#addresses, #affiliate_affiliations, #email, #firstname, #lastname, #namespaces, #officialemail, #phone, #services, #test?, #uid

Methods included from AffiliationMethods

#affiliate?, #affiliate_academic_case_tracking?, #affiliate_advcon_alumnus?, #affiliate_advcon_attendee?, #affiliate_advcon_caa_member?, #affiliate_advcon_friend?, #affiliate_advcon_i_house_resident?, #affiliate_advcon_student?, #affiliate_advcon_trustee?, #affiliate_aws_only?, #affiliate_billing_only?, #affiliate_committee_member?, #affiliate_concurrent_enrollment?, #affiliate_consultant?, #affiliate_contractor?, #affiliate_departmental?, #affiliate_directory_only?, #affiliate_emeritus?, #affiliate_expiration_date, #affiliate_expired?, #affiliate_hhmi_researcher?, #affiliate_lbl_doe_postdoc?, #affiliate_lbl_op_staff?, #affiliate_maintenance?, #affiliate_staff_affiliate?, #affiliate_staff_retiree?, #affiliate_temp_agency?, #affiliate_test?, #affiliate_visiting?, #affiliate_volunteer?, #affiliations, #employee?, #employee_academic?, #employee_expiration_date, #employee_expired?, #employee_staff?, #has_affiliation?, #has_affiliation_of_type?, #student?, #student_expiration_date, #student_expired?, #student_not_registered?, #student_registered?

Methods inherited from Entry

#assigned_attributes, #attributes, canonical, #canonical, combine_filters, create, create!, #dn, entity_name, filter_in, find_by_dn, #initialize, make_search_filter, #method_missing, net_ldap, #net_ldap, object_classes, required_attributes, required_schema_attributes, schema_attribute, schema_attributes_array, schema_attributes_hash, set_schema_attributes, tree_base, tree_base=, unique_object_class

Constructor Details

This class inherits a constructor from UCB::LDAP::Entry

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UCB::LDAP::Entry

Class Method Details

.find_by_uid(uid) ⇒ Object

Returns an instance of Person for given uid.



70
71
72
73
# File 'lib/ucb_ldap/person.rb', line 70

def self.find_by_uid(uid)
  uid = uid.to_s
  find_by_uids([uid]).first
end

.find_by_uids(uids) ⇒ Object

Returns an Array of Person for given uids.



82
83
84
85
86
# File 'lib/ucb_ldap/person.rb', line 82

def self.find_by_uids(uids)
  return [] if uids.size == 0
  filters = uids.map { |uid| Net::LDAP::Filter.eq("uid", uid) }
  search(:filter => self.combine_filters(filters, '|'))
end

.include_test_entries=(include_test_entries) ⇒ Object

Setter for include_test_entries?



111
112
113
# File 'lib/ucb_ldap/person.rb', line 111

def self.include_test_entries=(include_test_entries)
  @include_test_entries = include_test_entries
end

.include_test_entries?Boolean

If true test entries are included in search results (defalut is false).

Returns:

  • (Boolean)


104
105
106
# File 'lib/ucb_ldap/person.rb', line 104

def self.include_test_entries?
  @include_test_entries ? true : false
end

.person_by_uid(uid) ⇒ Object



75
76
77
# File 'lib/ucb_ldap/person.rb', line 75

def self.person_by_uid(uid)
  find_by_uid(uid)
end

.persons_by_uids(uids) ⇒ Object



88
89
90
# File 'lib/ucb_ldap/person.rb', line 88

def self.persons_by_uids(uids)
  find_by_uids(uids)
end

.search(args) ⇒ Object

Exclude test entries from search results unless told otherwise.



95
96
97
98
# File 'lib/ucb_ldap/person.rb', line 95

def self.search(args) #:nodoc:
  results = super
  include_test_entries? ? results : results.reject { |person| person.test? }
end

Instance Method Details

#departmentsObject



127
128
129
# File 'lib/ucb_ldap/person.rb', line 127

def departments
  departmentNumber
end

#dept_nameObject



122
123
124
125
# File 'lib/ucb_ldap/person.rb', line 122

def dept_name
  warn "DEPRECATED: LDAP no longer returns department names for person records. You'll need to look up the department code in the org tree. The ucb_orgs gem can help with this"
  deptid
end

#deptidObject Also known as: dept_code



116
117
118
# File 'lib/ucb_ldap/person.rb', line 116

def deptid
  berkeleyEduPrimaryDeptUnit
end

#expired?Boolean

Returns expired status

False by definition for normal users, overridable by subclasses

Returns:

  • (Boolean)


163
164
165
# File 'lib/ucb_ldap/person.rb', line 163

def expired?
  false
end

#job_appointmentsObject

Returns Array of JobAppointment for this Person. Requires a bind with access to job appointments. See UCB::LDAP.authenticate().



136
137
138
139
# File 'lib/ucb_ldap/person.rb', line 136

def job_appointments
  warn "DEPRECATED: LDAP no longer contains job appointment data - you now need to go through HCM. This method will always return an empty Array"
  []
end

#org_nodeObject

Returns instance of UCB::LDAP::Org corresponding to primary department.



154
155
156
# File 'lib/ucb_ldap/person.rb', line 154

def org_node
  @org_node ||= UCB::LDAP::Org.find_by_ou(deptid)
end

#student_termsObject

Returns Array of StudentTerm for this Person. Requires a bind with access to student terms. See UCB::LDAP.authenticate().



146
147
148
# File 'lib/ucb_ldap/person.rb', line 146

def student_terms
  @student_terms ||= StudentTerm.find_by_uid(uid)
end