ucb_ldap 2.0.0.pre1 → 2.0.0.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/CHANGELOG +137 -135
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/{README → README.md} +82 -80
  7. data/Rakefile +38 -20
  8. data/lib/ucb_ldap.rb +238 -204
  9. data/lib/{ucb_ldap_address.rb → ucb_ldap/address.rb} +106 -106
  10. data/lib/{ucb_ldap_affiliation.rb → ucb_ldap/affiliation.rb} +16 -16
  11. data/lib/{ucb_ldap_entry.rb → ucb_ldap/entry.rb} +455 -448
  12. data/lib/{ucb_ldap_person_job_appointment.rb → ucb_ldap/job_appointment.rb} +77 -79
  13. data/lib/{ucb_ldap_namespace.rb → ucb_ldap/namespace.rb} +40 -50
  14. data/lib/{ucb_ldap_org.rb → ucb_ldap/org.rb} +427 -429
  15. data/lib/{ucb_ldap_person.rb → ucb_ldap/person.rb} +157 -148
  16. data/lib/{person → ucb_ldap/person}/affiliation_methods.rb +23 -22
  17. data/lib/ucb_ldap/person/common_attributes.rb +63 -0
  18. data/lib/{ucb_ldap_schema.rb → ucb_ldap/schema.rb} +28 -28
  19. data/lib/{ucb_ldap_schema_attribute.rb → ucb_ldap/schema_attribute.rb} +152 -153
  20. data/lib/{ucb_ldap_service.rb → ucb_ldap/service.rb} +17 -19
  21. data/lib/{ucb_ldap_student_term.rb → ucb_ldap/student_term.rb} +29 -31
  22. data/lib/ucb_ldap/version.rb +3 -0
  23. data/spec/rails_binds.yml +9 -0
  24. data/spec/spec_helper.rb +43 -0
  25. data/spec/ucb_ldap/address_spec.rb +54 -0
  26. data/spec/ucb_ldap/affiliation_spec.rb +85 -0
  27. data/spec/ucb_ldap/entry_spec.rb +241 -0
  28. data/spec/ucb_ldap/job_appointment_spec.rb +65 -0
  29. data/spec/ucb_ldap/namespace_spec.rb +72 -0
  30. data/spec/ucb_ldap/org_spec.rb +217 -0
  31. data/spec/ucb_ldap/person_spec.rb +225 -0
  32. data/spec/ucb_ldap/schema_attribute_spec.rb +122 -0
  33. data/spec/ucb_ldap/schema_spec.rb +104 -0
  34. data/spec/ucb_ldap/service_spec.rb +127 -0
  35. data/spec/ucb_ldap/student_term_spec.rb +121 -0
  36. data/spec/ucb_ldap_spec.rb +182 -0
  37. data/ucb_ldap.gemspec +20 -27
  38. metadata +113 -64
  39. data/Manifest +0 -23
  40. data/TODO +0 -2
  41. data/lib/person/adv_con_person.rb +0 -0
  42. data/lib/person/generic_attributes.rb +0 -68
  43. data/lib/ucb_ldap_exceptions.rb +0 -27
  44. data/version.yml +0 -1
@@ -1,148 +1,157 @@
1
-
2
- module UCB::LDAP
3
- ##
4
- # =UCB::LDAP::Person
5
- #
6
- # Class for accessing the People tree of the UCB LDAP directory.
7
- #
8
- # You can search by specifying your own filter:
9
- #
10
- # e = Person.search(:filter => {:uid => 123})
11
- #
12
- # Or you can use a convenience search method:
13
- #
14
- # e = Person.find_by_uid("123")
15
- #
16
- # Access attributes as if they were instance methods:
17
- #
18
- # e = Person.find_by_uid("123")
19
- #
20
- # e.givenname #=> "John"
21
- # e.sn #=> "Doe"
22
- #
23
- # Methods with friendly names are provided for accessing attribute values:
24
- #
25
- # e = Person.person_by_uid("123")
26
- #
27
- # e.firstname #=> "John"
28
- # e.lastname #=> "Doe"
29
- #
30
- # There are other convenience methods:
31
- #
32
- # e = Person.person_by_uid("123")
33
- #
34
- # e.affiliations #=> ["EMPLOYEE-TYPE-STAFF"]
35
- # e.employee? #=> true
36
- # e.employee_staff? #=> true
37
- # e.employee_academic? #=> false
38
- # e.student? #=> false
39
- #
40
- # == Other Parts of the Tree
41
- #
42
- # You can access other parts of the LDAP directory through Person
43
- # instances:
44
- #
45
- # p = Person.find_by_uid("123")
46
- #
47
- # p.org_node #=> Org
48
- # p.affiliations #=> Array of Affiliation
49
- # p.addresses #=> Array of Address
50
- # p.job_appointments #=> Array of JobAppointment
51
- # p.namespaces #=> Array of Namespace
52
- # p.student_terms #=> Array of StudentTerm
53
- #
54
- # ==Attributes
55
- #
56
- # See Ldap::Entry for general information on accessing attribute values.
57
- #
58
- class Person < Entry
59
- class RecordNotFound < StandardError; end
60
-
61
- include AffiliationMethods
62
- include GenericAttributes
63
-
64
- @entity_name = 'person'
65
- @tree_base = 'ou=people,dc=berkeley,dc=edu'
66
-
67
- class << self
68
- ##
69
- # Returns an instance of Person for given _uid_.
70
- #
71
- def find_by_uid(uid)
72
- uid = uid.to_s
73
- find_by_uids([uid]).first
74
- end
75
- alias :person_by_uid :find_by_uid
76
-
77
- ##
78
- # Returns an +Array+ of Person for given _uids_.
79
- #
80
- def find_by_uids(uids)
81
- return [] if uids.size == 0
82
- filters = uids.map{|uid| Net::LDAP::Filter.eq("uid", uid)}
83
- search(:filter => self.combine_filters(filters, '|'))
84
- end
85
- alias :persons_by_uids :find_by_uids
86
-
87
- ##
88
- # Exclude test entries from search results unless told otherwise.
89
- #
90
- def search(args) #:nodoc:
91
- results = super
92
- include_test_entries? ? results : results.reject { |person| person.test? }
93
- end
94
-
95
- ##
96
- # If <tt>true</tt> test entries are included in search results
97
- # (defalut is <tt>false</tt>).
98
- #
99
- def include_test_entries?
100
- @include_test_entries ? true : false
101
- end
102
-
103
- ##
104
- # Setter for include_test_entries?
105
- #
106
- def include_test_entries=(include_test_entries)
107
- @include_test_entries = include_test_entries
108
- end
109
- end
110
-
111
-
112
- def deptid
113
- berkeleyEduPrimaryDeptUnit
114
- end
115
- alias :dept_code :deptid
116
-
117
- def dept_name
118
- berkeleyEduUnitCalNetDeptName
119
- end
120
-
121
- ##
122
- # Returns +Array+ of JobAppointment for this Person.
123
- # Requires a bind with access to job appointments.
124
- # See UCB::LDAP.authenticate().
125
- #
126
- def job_appointments
127
- @job_appointments ||= JobAppointment.find_by_uid(uid)
128
- end
129
-
130
- ##
131
- # Returns +Array+ of StudentTerm for this Person.
132
- # Requires a bind with access to student terms.
133
- # See UCB::LDAP.authenticate().
134
- #
135
- def student_terms
136
- @student_terms ||= StudentTerm.find_by_uid(uid)
137
- end
138
-
139
- ##
140
- # Returns instance of UCB::LDAP::Org corresponding to
141
- # primary department.
142
- #
143
- def org_node
144
- @org_node ||= UCB::LDAP::Org.find_by_ou(deptid)
145
- end
146
-
147
- end
148
- end
1
+ require_relative 'person/affiliation_methods'
2
+ require_relative 'person/common_attributes'
3
+
4
+ module UCB::LDAP
5
+ ##
6
+ # =UCB::LDAP::Person
7
+ #
8
+ # Class for accessing the People tree of the UCB LDAP directory.
9
+ #
10
+ # You can search by specifying your own filter:
11
+ #
12
+ # e = Person.search(:filter => {:uid => 123})
13
+ #
14
+ # Or you can use a convenience search method:
15
+ #
16
+ # e = Person.find_by_uid("123")
17
+ #
18
+ # Access attributes as if they were instance methods:
19
+ #
20
+ # e = Person.find_by_uid("123")
21
+ #
22
+ # e.givenname #=> "John"
23
+ # e.sn #=> "Doe"
24
+ #
25
+ # Methods with friendly names are provided for accessing attribute values:
26
+ #
27
+ # e = Person.person_by_uid("123")
28
+ #
29
+ # e.firstname #=> "John"
30
+ # e.lastname #=> "Doe"
31
+ #
32
+ # There are other convenience methods:
33
+ #
34
+ # e = Person.person_by_uid("123")
35
+ #
36
+ # e.affiliations #=> ["EMPLOYEE-TYPE-STAFF"]
37
+ # e.employee? #=> true
38
+ # e.employee_staff? #=> true
39
+ # e.employee_academic? #=> false
40
+ # e.student? #=> false
41
+ #
42
+ # == Other Parts of the Tree
43
+ #
44
+ # You can access other parts of the LDAP directory through Person
45
+ # instances:
46
+ #
47
+ # p = Person.find_by_uid("123")
48
+ #
49
+ # p.org_node #=> Org
50
+ # p.affiliations #=> Array of Affiliation
51
+ # p.addresses #=> Array of Address
52
+ # p.job_appointments #=> Array of JobAppointment
53
+ # p.namespaces #=> Array of Namespace
54
+ # p.student_terms #=> Array of StudentTerm
55
+ #
56
+ # ==Attributes
57
+ #
58
+ # See Ldap::Entry for general information on accessing attribute values.
59
+ #
60
+ class Person < Entry
61
+ class RecordNotFound < StandardError;
62
+ end
63
+
64
+ include UCB::LDAP::AffiliationMethods
65
+ include UCB::LDAP::CommonAttributes
66
+
67
+ @entity_name = 'person'
68
+ @tree_base = 'ou=people,dc=berkeley,dc=edu'
69
+
70
+
71
+ ##
72
+ # Returns an instance of Person for given _uid_.
73
+ #
74
+ def self.find_by_uid(uid)
75
+ uid = uid.to_s
76
+ find_by_uids([uid]).first
77
+ end
78
+
79
+ def self.person_by_uid(uid)
80
+ find_by_uid(uid)
81
+ end
82
+
83
+ ##
84
+ # Returns an +Array+ of Person for given _uids_.
85
+ #
86
+ def self.find_by_uids(uids)
87
+ return [] if uids.size == 0
88
+ filters = uids.map { |uid| Net::LDAP::Filter.eq("uid", uid) }
89
+ search(:filter => self.combine_filters(filters, '|'))
90
+ end
91
+
92
+ def self.persons_by_uids(uids)
93
+ find_by_uids(uids)
94
+ end
95
+
96
+ ##
97
+ # Exclude test entries from search results unless told otherwise.
98
+ #
99
+ def self.search(args) #:nodoc:
100
+ results = super
101
+ include_test_entries? ? results : results.reject { |person| person.test? }
102
+ end
103
+
104
+ ##
105
+ # If <tt>true</tt> test entries are included in search results
106
+ # (defalut is <tt>false</tt>).
107
+ #
108
+ def self.include_test_entries?
109
+ @include_test_entries ? true : false
110
+ end
111
+
112
+ ##
113
+ # Setter for include_test_entries?
114
+ #
115
+ def self.include_test_entries=(include_test_entries)
116
+ @include_test_entries = include_test_entries
117
+ end
118
+
119
+
120
+ def deptid
121
+ berkeleyEduPrimaryDeptUnit
122
+ end
123
+
124
+ alias :dept_code :deptid
125
+
126
+ def dept_name
127
+ berkeleyEduUnitCalNetDeptName
128
+ end
129
+
130
+ ##
131
+ # Returns +Array+ of JobAppointment for this Person.
132
+ # Requires a bind with access to job appointments.
133
+ # See UCB::LDAP.authenticate().
134
+ #
135
+ def job_appointments
136
+ @job_appointments ||= JobAppointment.find_by_uid(uid)
137
+ end
138
+
139
+ ##
140
+ # Returns +Array+ of StudentTerm for this Person.
141
+ # Requires a bind with access to student terms.
142
+ # See UCB::LDAP.authenticate().
143
+ #
144
+ def student_terms
145
+ @student_terms ||= StudentTerm.find_by_uid(uid)
146
+ end
147
+
148
+ ##
149
+ # Returns instance of UCB::LDAP::Org corresponding to
150
+ # primary department.
151
+ #
152
+ def org_node
153
+ @org_node ||= UCB::LDAP::Org.find_by_ou(deptid)
154
+ end
155
+
156
+ end
157
+ end
@@ -1,24 +1,23 @@
1
-
2
-
3
- module UCB::LDAP
1
+ module UCB
2
+ module LDAP
4
3
  module AffiliationMethods
5
-
4
+
6
5
  ##
7
6
  # Returns an <tt>Array</tt> of Person's affiliations.
8
7
  #
9
8
  def affiliations
10
9
  @affiliations ||= berkeleyEduAffiliations.map { |a| a.upcase }
11
10
  end
12
-
11
+
13
12
  ##
14
13
  # Returns <tt>true</tt> if entry's affiliations contain _affiliation_.
15
- #
14
+ #
16
15
  # Case-insensitive.
17
16
  #
18
17
  def has_affiliation?(affiliation)
19
18
  affiliations.include?(affiliation.upcase)
20
19
  end
21
-
20
+
22
21
  ##
23
22
  # Returns <tt>true</tt> if Person's affiliations contain at least one affiliation of a particular type.
24
23
  #
@@ -29,14 +28,14 @@ module UCB::LDAP
29
28
  #
30
29
  def has_affiliation_of_type?(affiliation_type)
31
30
  aff_type_string = affiliation_type.to_s.upcase
32
- affiliations.find{|a| a =~ /^#{aff_type_string}-TYPE-/} ? true : false
31
+ affiliations.find { |a| a =~ /^#{aff_type_string}-TYPE-/ } ? true : false
33
32
  end
34
33
 
35
34
 
36
35
  ############################################
37
36
  # Determine if the person is an EMPLOYEE #
38
37
  ############################################
39
-
38
+
40
39
  ##
41
40
  # Returns <tt>true</tt> if entry has the "staff" affiliation.
42
41
  #
@@ -60,11 +59,11 @@ module UCB::LDAP
60
59
  has_affiliation_of_type?(:employee) && !employee_expired?
61
60
  end
62
61
 
63
-
62
+
64
63
  ##########################################
65
64
  # Determine if the person is a STUDENT #
66
65
  ##########################################
67
-
66
+
68
67
  ##
69
68
  # Returns +true+ if is an expired student.
70
69
  #
@@ -83,7 +82,7 @@ module UCB::LDAP
83
82
  def student_not_registered?
84
83
  has_affiliation? 'STUDENT-TYPE-NOT REGISTERED'
85
84
  end
86
-
85
+
87
86
  ##
88
87
  # Returns <tt>true</tt> if entry has a studend affiliation and
89
88
  # is not expired.
@@ -93,7 +92,7 @@ module UCB::LDAP
93
92
  end
94
93
 
95
94
 
96
- ##############################################
95
+ ##############################################
97
96
  # Determine if the persone is an AFFILIATE #
98
97
  ##############################################
99
98
 
@@ -102,7 +101,7 @@ module UCB::LDAP
102
101
  end
103
102
 
104
103
  def affiliate_staff_retiree?
105
- has_affiliation? 'AFFILIATE-TYPE-STAFF RETIREE'
104
+ has_affiliation? 'AFFILIATE-TYPE-STAFF RETIREE'
106
105
  end
107
106
 
108
107
  def affiliate_emeritus?
@@ -112,9 +111,9 @@ module UCB::LDAP
112
111
  def affiliate_directory_only?
113
112
  has_affiliation? 'AFFILIATE-TYPE-DIRECTORY ONLY'
114
113
  end
115
-
114
+
116
115
  ##
117
- # Note: there are actually 2 types of visting affiliaties, visiting student and
116
+ # Note: there are actually 2 types of visting affiliaties, visiting student and
118
117
  # visiting scholars. But for now we will generalize.
119
118
  #
120
119
  def affiliate_visiting?
@@ -132,7 +131,7 @@ module UCB::LDAP
132
131
  def affiliate_lbl_op_staff?
133
132
  has_affiliation? 'AFFILIATE-TYPE-LBLOP STAFF'
134
133
  end
135
-
134
+
136
135
  def affiliate_committee_member?
137
136
  has_affiliation? 'AFFILIATE-TYPE-COMMITTEE MEMBER'
138
137
  end
@@ -148,13 +147,13 @@ module UCB::LDAP
148
147
  def affiliate_hhmi_researcher?
149
148
  has_affiliation? 'AFFILIATE-TYPE-HHMI RESEARCHER'
150
149
  end
151
-
150
+
152
151
  def affiliate_concurrent_enrollment?
153
152
  has_affiliation? 'AFFILIATE-TYPE-CONCURR ENROLL'
154
153
  end
155
154
 
156
155
  def affiliate_temp_agency?
157
- has_affiliation? 'AFFILIATE-TYPE-TEMP AGENCY'
156
+ has_affiliation? 'AFFILIATE-TYPE-TEMP AGENCY'
158
157
  end
159
158
 
160
159
  def affiliate_departmental?
@@ -198,7 +197,7 @@ module UCB::LDAP
198
197
  end
199
198
 
200
199
  def affiliate_advcon_i_house_resident?
201
- has_affiliation? 'AFFILIATE-TYPE-ADVCON-I-HOUSE-RESIDENT'
200
+ has_affiliation? 'AFFILIATE-TYPE-ADVCON-I-HOUSE-RESIDENT'
202
201
  end
203
202
 
204
203
  def affiliate_advcon_student?
@@ -220,6 +219,8 @@ module UCB::LDAP
220
219
  def affiliate_expiration_date
221
220
  Date.parse(berkeleyEduAffExpDate.to_s)
222
221
  end
223
-
224
- end
222
+
223
+ end
224
+
225
+ end
225
226
  end
@@ -0,0 +1,63 @@
1
+ module UCB
2
+ module LDAP
3
+ module CommonAttributes
4
+
5
+ # Returns +true+ if the entry represents a test entry.
6
+ def test?
7
+ berkeleyEduTestIDFlag
8
+ end
9
+
10
+ def uid
11
+ super.first
12
+ end
13
+
14
+ def firstname
15
+ givenname.first
16
+ end
17
+
18
+ alias :first_name :firstname
19
+
20
+ def lastname
21
+ sn.first
22
+ end
23
+
24
+ alias :last_name :lastname
25
+
26
+ def email
27
+ mail.first
28
+ end
29
+
30
+ def phone
31
+ telephoneNumber.first
32
+ end
33
+
34
+ # Returns +Array+ of Affiliation for this Person. Requires a bind with access to affiliations.
35
+ # See UCB::LDAP.authenticate().
36
+ def affiliate_affiliations
37
+ @affiliate_affiliations ||= Affiliation.find_by_uid(uid)
38
+ end
39
+
40
+ # Returns +Array+ of Namespace for this Person.
41
+ # Requires a bind with access to namespaces.
42
+ # See UCB::LDAP.authenticate().
43
+ def namespaces
44
+ @namespaces ||= Namespace.find_by_uid(uid)
45
+ end
46
+
47
+ # Returns +Array+ of Service for this Person.
48
+ # Requires a bind with access to services.
49
+ # See UCB::LDAP.authenticate().
50
+ def services
51
+ @services ||= Service.find_by_uid(uid)
52
+ end
53
+
54
+ # Returns +Array+ of Address for this Person.
55
+ # Requires a bind with access to addresses.
56
+ # See UCB::LDAP.authenticate().
57
+ def addresses
58
+ @addresses ||= Address.find_by_uid(uid)
59
+ end
60
+
61
+ end
62
+ end
63
+ end