34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/socialcast/net_ldap_ext.rb', line 34
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
contact_attributes = %w{email location cell_phone office_phone}
user.tag! 'contact-info' do |contact_info|
contact_attributes.each do |attribute|
next unless mappings.has_key?(attribute)
contact_info.tag! attribute, grab(mappings[attribute])
end
end
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|
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'
memberships = self[membership_attribute]
external_ldap_groups = Array.wrap(permission_mappings.fetch('account_types', {})['external'])
if external_ldap_groups.any? { |external_ldap_group| memberships.include?(external_ldap_group) }
user.tag! 'account-type', 'external'
else
user.tag! 'account-type', 'member'
if permission_roles_mappings = permission_mappings['roles']
user.tag! 'roles', :type => 'array' do |roles|
permission_roles_mappings.each_pair do |socialcast_role, ldap_groups|
Array.wrap(ldap_groups).each do |ldap_group|
if memberships.include?(ldap_group)
roles.role socialcast_role
break
end
end
end
end
end
end
end
|