lib/socialcast/net_ldap_ext.rb in socialcast-1.1.4 vs lib/socialcast/net_ldap_ext.rb in socialcast-1.1.5
- old
+ new
@@ -11,12 +11,19 @@
value % Hash[attribute.map {|k,v| [k, grab(v)]}].symbolize_keys
else
Array.wrap(self[attribute]).compact.first
end
end
+
+ def dereference_mail(ldap_connection, dn_field, mail_attribute)
+ dn = grab(dn_field)
+ ldap_connection.search(:base => dn, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
+ return entry.grab(mail_attribute)
+ end
+ end
- def build_xml_from_mappings(user, mappings = {}, permission_mappings = {})
+ def build_xml_from_mappings(user, ldap_connection, mappings = {}, permission_mappings = {})
primary_attributes = %w{unique_identifier first_name last_name employee_number}
primary_attributes.each do |attribute|
next unless mappings.has_key?(attribute)
user.tag! attribute, grab(mappings[attribute])
end
@@ -31,12 +38,18 @@
custom_attributes = mappings.keys - (primary_attributes + contact_attributes)
user.tag! 'custom-fields', :type => "array" do |custom_fields|
custom_attributes.each do |attribute|
custom_fields.tag! 'custom-field' do |custom_field|
- custom_field.id attribute
- custom_field.label attribute
- custom_field.value grab(mappings[attribute])
+ if attribute == 'manager'
+ custom_field.id 'manager_email'
+ custom_field.label 'manager_email'
+ custom_field.value dereference_mail(ldap_connection, mappings[attribute], mappings['email'])
+ else
+ custom_field.id attribute
+ custom_field.label attribute
+ custom_field.value grab(mappings[attribute])
+ end
end
end
end
membership_attribute = permission_mappings.fetch 'attribute_name', 'memberof'