Commit e9733525 authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Support multiple alternate address attributes

parent f180b553
......@@ -19,20 +19,28 @@ sub _import_user {
my $user = $self->SUPER::_import_user(@_);
return unless $user;
my $attrname = RT->Config->Get('LDAPMultiEmail');
return unless $attrname;
my $secondary_attrs = RT->Config->Get('LDAPMultiEmail');
return unless $secondary_attrs;
$secondary_attrs = [ $secondary_attrs ] unless ref $secondary_attrs;
$self->{seen}{$user->id}++;
my $ldap = $args{ldap_entry};
my $uid = $ldap->get_value('uid');
my $email = $ldap->get_value('mail');
my @secondary = grep {/\S/ and $_ ne $email} $ldap->get_value($attrname);
my %original_secondary;
my @secondary;
for my $attr (@{$secondary_attrs}) {
$original_secondary{$attr} = [ $ldap->get_value($attr) ];
push @secondary, map {[$attr, $_]} grep {/\S/ and $_ ne $email} @{$original_secondary{$attr}};
}
my(@users, @merge);
for my $address (@secondary) {
for my $val (@secondary) {
my ($attrname, $address) = @{$val};
my ($parsed) = Email::Address->parse($address);
unless ($parsed) {
$self->_debug("Skipping alternate address $address, as it is invalid");
$self->_debug("Skipping alternate address $address in $attrname of $email, as it is invalid");
next;
}
......@@ -51,7 +59,7 @@ sub _import_user {
my $other = RT::User->new( RT->SystemUser );
$other->Load( $effective_id->Content );
$self->_warn($user->EmailAddress." lists $address".
" as a secondary, which is already merged into ".
" in $attrname as a secondary, which is already merged into ".
$other->EmailAddress
);
next;
......@@ -63,7 +71,7 @@ sub _import_user {
# values in the remote LDAP store.
$ldap->replace( uid => $address );
$ldap->replace( mail => $address );
$ldap->replace( $attrname => [] );
$ldap->replace( $_ => [] ) for @{$secondary_attrs};
# Build and import the secondary user
my $data = $self->_build_user_object( ldap_entry => $ldap );
......@@ -99,7 +107,7 @@ sub _import_user {
# scope shortly without being used again, but better safe than sorry.
$ldap->replace( uid => $uid );
$ldap->replace( mail => $email );
$ldap->replace( $attrname => \@secondary );
$ldap->replace( $_ => $original_secondary{$_} ) for @{$secondary_attrs};
return $user;
}
......@@ -133,6 +141,11 @@ addresses, via:
Set( $LDAPMultiEmail, 'alternateEmail' );
Multiple alternate email address attributes can be specified using an
array reference:
Set( $LDAPMultiEmail, ['alternateEmail', 'homeEmail'] );
=back
=head1 AUTHOR
......
......@@ -46,6 +46,7 @@ $ldap->add( "uid=testing,ou=People,dc=example,dc=com", attr => [
mail => 'tim@example.com',
alternateEmail => 'timmy@example.com',
alternateEmail => 'testing@example.com',
moreEmail => 'more@example.com',
other => 'Some value',
] );
......@@ -62,7 +63,7 @@ RT->Config->Set('LDAPMapping', {
RT->Config->Set('LDAPBase','ou=People,dc=example,dc=com');
RT->Config->Set('LDAPFilter','(objectClass=User)');
RT->Config->Set('LDAPSkipAutogeneratedGroup',1);
RT->Config->Set('LDAPMultiEmail', 'alternateEmail');
RT->Config->Set('LDAPMultiEmail', ['alternateEmail', 'moreEmail']);
ok($importer->import_users( import => 1 ));
......@@ -71,7 +72,7 @@ user_is( 'testing',
RealName => "Timmy Testing", "RealName is right",
EmailAddress => 'tim@example.com', "Email is right",
'CF.SomeCF' => 'Some value', "Set the CF",
Merged => ['timmy@example.com', 'testing@example.com'],
Merged => ['timmy@example.com', 'testing@example.com', 'more@example.com'],
"Merged users check out",
);
user_is( 'timmy@example.com',
......@@ -82,7 +83,7 @@ user_is( 'timmy@example.com',
# Ensure that this is idempotent
ok($importer->import_users( import => 1 ));
user_is( 'testing',
Merged => ['timmy@example.com', 'testing@example.com'],
Merged => ['timmy@example.com', 'testing@example.com', 'more@example.com'],
"Still properly merged",
);
......@@ -94,7 +95,16 @@ $ldap->modify( "uid=testing,ou=People,dc=example,dc=com",
);
ok($importer->import_users( import => 1 ));
user_is( 'testing',
Merged => ['timmy@example.com']
Merged => ['timmy@example.com', 'more@example.com'],
"Removing alternate unmerges the user",
);
# Changing the set of attributes un-merges the user
RT->Config->Set('LDAPMultiEmail', 'alternateEmail');
ok($importer->import_users( import => 1 ));
user_is( 'testing',
Merged => ['timmy@example.com'],
"No longer merged into other",
);
# Test when alternate email addresses collide
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment