[Rt-commit] rt branch 5.0/strip-group-name-spaces created. rt-5.0.2-26-g4f851124f5
BPS Git Server
git at git.bestpractical.com
Fri Oct 8 20:10:08 UTC 2021
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, 5.0/strip-group-name-spaces has been created
at 4f851124f5e9aff02a061143b4454a65339924a3 (commit)
- Log -----------------------------------------------------------------
commit 4f851124f5e9aff02a061143b4454a65339924a3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Oct 9 03:28:27 2021 +0800
Test group name's leading/trailing spaces removal behavior on create/update
diff --git a/t/api/group.t b/t/api/group.t
index 7ec3a341ef..81bdd290c7 100644
--- a/t/api/group.t
+++ b/t/api/group.t
@@ -114,6 +114,16 @@ is($u->PrincipalObj->PrincipalType , 'Group' , "Principal 4 is a group");
ok( !$id, "can't create duplicated group: $msg" );
( $id, $msg ) = $u2->CreateUserDefinedGroup( Name => 'testgroup' );
ok( !$id, "can't create duplicated group even case is different: $msg" );
+
+ my $group = RT::Group->new( RT->SystemUser );
+ ( $id, $msg ) = $group->CreateUserDefinedGroup( Name => ' Engineers ' );
+ ok( $group->id, 'loaded Engineers' );
+ is( $group->Name, 'Engineers', 'leading/trailing spaces are removed on create' );
+ ( my $ret, $msg ) = $group->SetName(' Engineers ');
+ ok( !$ret, "Can't update to the same name but with leading/trailing spaces" );
+ ( $ret, $msg ) = $group->SetName(' Coders ');
+ ok( $ret, "Update to the a new name" );
+ is( $group->Name, 'Coders', 'leading/trailing spaces are removed on update' );
}
diag "Ticket role group members";
commit 3a3ac6e3414f5c420f99901ad4227a7d03d9d99c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Oct 9 03:20:02 2021 +0800
Strip leading/trailing spaces from Group name automatically on create/update
diff --git a/lib/RT/Group.pm b/lib/RT/Group.pm
index a8e799091b..44cfa2426b 100644
--- a/lib/RT/Group.pm
+++ b/lib/RT/Group.pm
@@ -305,6 +305,8 @@ sub _Create {
@_
);
+ $args{'Name'} = $self->CanonicalizeName( $args{'Name'} );
+
if ($args{'Domain'}) {
# Enforce uniqueness on user defined group names
if ($args{'Domain'} eq 'UserDefined') {
@@ -647,7 +649,7 @@ sub SetName {
my $self = shift;
my $value = shift;
- my ($status, $msg) = $self->_Set( Field => 'Name', Value => $value );
+ my ($status, $msg) = $self->_Set( Field => 'Name', Value => $self->CanonicalizeName($value) );
return ($status, $msg);
}
@@ -1790,6 +1792,20 @@ sub URI {
return $uri->URIForObject($self);
}
+=head2 CanonicalizeName NAME
+
+Strip leading/trailing spaces and returns the updated name.
+
+=cut
+
+sub CanonicalizeName {
+ my $self = shift;
+ my $name = shift // return undef;
+ $name =~ s!^\s+!!;
+ $name =~ s!\s+$!!;
+ return $name;
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/share/html/Admin/Groups/Modify.html b/share/html/Admin/Groups/Modify.html
index dc447bfa5b..839371275c 100644
--- a/share/html/Admin/Groups/Modify.html
+++ b/share/html/Admin/Groups/Modify.html
@@ -114,6 +114,7 @@ if ($Create) {
my ($create_id, $create_msg) = $Group->CreateUserDefinedGroup(Name => $Name );
if ($create_id) {
$id = $Group->Id;
+ $Name = $Group->Name; # In case original $Name has leading/trailing spaces
push @results, $create_msg;
} else {
push @results, loc("Group could not be created: [_1]", $create_msg);
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list