[Rt-commit] rt branch 4.4/create-user-default-name created. rt-4.4.6beta1-4-ge6e0528773
BPS Git Server
git at git.bestpractical.com
Thu Jun 16 14:01:16 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 4.4/create-user-default-name has been created
at e6e052877365f71976c5efa947775dbf79115bb2 (commit)
- Log -----------------------------------------------------------------
commit e6e052877365f71976c5efa947775dbf79115bb2
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 16 09:26:14 2022 -0400
Provide examples for CanonicalizeEmailAddress match and replace
The examples were in RT_Config.pm.in as comments. Move them into the
POD to make it easier for users to find.
Also remove the comment from code that mentions an example,
but didn't actually have one.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index d38b22b85f..152cf00540 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -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>
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 928f89006d..f7d28b09eb 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -842,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') )
{
commit dd9c193d505f5ba4c7b3d758de5acc8cdeee854f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 16 09:24:47 2022 -0400
Document default Name setting in RT::User
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 753ab99327..928f89006d 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -118,6 +118,8 @@ custom field.
EmailAddress => 'mycroft at example.com',
UserCF.Relationship => 'Brother' );
+If no Name is passed, it is set to the same value as EmailAddress.
+
=cut
commit d9fe500386c8f402645544ffb32170e72c154b89
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 16 09:05:53 2022 -0400
Don't default Name to EmailAddress in LoadOrCreateByEmail
RT::User::Create defaults Name to EmailAddress if no
Name is passed and it does so after EmailAddress has
been processed by CanonicalizeEmailAddress. EmailAddress
can be modified based on CanonicalizeEmailAddressMatch and
CanonicalizeEmailAddressReplace settings, so this makes sure
Name and EmailAddress get the same value.
When LoadOrCreateByEmail defaults Name to EmailAddress before
calling Create, Create uses the passed value. This can then
result in different values for Name and EmailAddress. Remove
the default setting from LoadOrCreateByEmail and let Create
set the correct default, if needed.
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 718b24f8fa..753ab99327 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -696,7 +696,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';
commit c4052e6e1845f80c79b2f1d32c7b15825553a98b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 16 09:05:40 2022 -0400
Add tests for LoadOrCreateByEmail
diff --git a/t/api/user.t b/t/api/user.t
index 06ef2bf681..0b1c76025a 100644
--- a/t/api/user.t
+++ b/t/api/user.t
@@ -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('create-test-1 at example.com');
+ ok ($id, $msg . ' - ' . $load_user1->EmailAddress);
+
+ my $load_user2 = RT::User->new(RT->SystemUser);
+ ($id, $msg) = $load_user2->LoadOrCreateByEmail('load-create-test-1 at example.com');
+ ok ($id, $msg . ' - ' . $load_user2->EmailAddress);
+ is ($load_user2->Name, 'load-create-test-1 at example.com', 'Name set to load-create-test-1 at example.com');
+ is ($load_user2->EmailAddress, 'load-create-test-1 at example.com', 'Email set to load-create-test-1 at example.com');
+
+ my $load_user3 = RT::User->new(RT->SystemUser);
+ ($id, $msg) = $load_user3->LoadOrCreateByEmail('load-create-test-2 at foo.example.com');
+ ok ($id, $msg . ' - ' . $load_user3->EmailAddress);
+ is ($load_user3->Name, 'load-create-test-2 at foo.example.com', 'Name set to load-create-test-2 at foo.example.com');
+ is ($load_user3->EmailAddress, 'load-create-test-2 at foo.example.com', 'Email set to load-create-test-2 at foo.example.com');
+
+ 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('load-create-test-3 at foo.example.com');
+ ok ($id, $msg . ' - ' . $load_user4->EmailAddress);
+ is ($load_user4->Name, 'load-create-test-3 at example.com', 'Name set to load-create-test-3 at example.com');
+ is ($load_user4->EmailAddress, 'load-create-test-3 at example.com', 'Email set to load-create-test-3 at example.com');
+}
+
done_testing();
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list