Skip to content

Commit

Permalink
Merge branch '4.4/create-user-default-name' into 4.4-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Jul 15, 2022
2 parents 8faf4b6 + e6e0528 commit e0324db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
10 changes: 5 additions & 5 deletions etc/RT_Config.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,13 @@ default implementation replaces all occurrences of the regular
expression in C<CanonicalizeEmailAddressMatch> with
C<CanonicalizeEmailAddressReplace>, via C<s/$Match/$Replace/gi>. The
most common use of this is to replace C<@something.example.com> with
C<@example.com>. If more complex noramlization is required,
L<RT::User/CanonicalizeEmailAddress> can be overridden to provide it.
C<@example.com>, as shown below:

=cut
Set($CanonicalizeEmailAddressMatch, '@subdomain\.example\.com$');
Set($CanonicalizeEmailAddressReplace, '@example.com');

# Set($CanonicalizeEmailAddressMatch, '@subdomain\.example\.com$');
# Set($CanonicalizeEmailAddressReplace, '@example.com');
If more complex noramlization is required,
L<RT::User/CanonicalizeEmailAddress> can be overridden to provide it.

=item C<$ValidateUserEmailAddresses>

Expand Down
7 changes: 3 additions & 4 deletions lib/RT/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ custom field.
EmailAddress => '[email protected]',
UserCF.Relationship => 'Brother' );
If no Name is passed, it is set to the same value as EmailAddress.
=cut


Expand Down Expand Up @@ -696,7 +698,6 @@ sub LoadOrCreateByEmail {
return wantarray ? ($self->Id, $self->loc("User loaded")) : $self->Id
if $self->Id;

$create{Name} ||= $create{EmailAddress};
$create{Privileged} ||= 0;
$create{Comments} //= 'Autocreated when added as a watcher';

Expand Down Expand Up @@ -841,9 +842,7 @@ is class name not an object.
sub CanonicalizeEmailAddress {
my $self = shift;
my $email = shift;
# Example: the following rule would treat all email
# coming from a subdomain as coming from second level domain
# foo.com

if ( my $match = RT->Config->Get('CanonicalizeEmailAddressMatch') and
my $replace = RT->Config->Get('CanonicalizeEmailAddressReplace') )
{
Expand Down
28 changes: 28 additions & 0 deletions t/api/user.t
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,32 @@ ok($rqv, "Revoked the right successfully - $rqm");
is $marks[0], $b_ticket->id;
}

diag 'Test LoadOrCreateByEmail';
{
my $load_user1 = RT::User->new(RT->SystemUser);
my ($id, $msg) = $load_user1->LoadOrCreateByEmail('[email protected]');
ok ($id, $msg . ' - ' . $load_user1->EmailAddress);

my $load_user2 = RT::User->new(RT->SystemUser);
($id, $msg) = $load_user2->LoadOrCreateByEmail('[email protected]');
ok ($id, $msg . ' - ' . $load_user2->EmailAddress);
is ($load_user2->Name, '[email protected]', 'Name set to [email protected]');
is ($load_user2->EmailAddress, '[email protected]', 'Email set to [email protected]');

my $load_user3 = RT::User->new(RT->SystemUser);
($id, $msg) = $load_user3->LoadOrCreateByEmail('[email protected]');
ok ($id, $msg . ' - ' . $load_user3->EmailAddress);
is ($load_user3->Name, '[email protected]', 'Name set to [email protected]');
is ($load_user3->EmailAddress, '[email protected]', 'Email set to [email protected]');

RT->Config->Set( CanonicalizeEmailAddressMatch => '@.+\.example\.com' );
RT->Config->Set( CanonicalizeEmailAddressReplace => '@example.com' );

my $load_user4 = RT::User->new(RT->SystemUser);
($id, $msg) = $load_user4->LoadOrCreateByEmail('[email protected]');
ok ($id, $msg . ' - ' . $load_user4->EmailAddress);
is ($load_user4->Name, '[email protected]', 'Name set to [email protected]');
is ($load_user4->EmailAddress, '[email protected]', 'Email set to [email protected]');
}

done_testing();

0 comments on commit e0324db

Please sign in to comment.