[Rt-commit] rt branch, 4.4/group-membership-canonicalize-principal, created. rt-4.4.4-34-gdad0a00b5
Jim Brandt
jbrandt at bestpractical.com
Thu May 2 10:38:34 EDT 2019
The branch, 4.4/group-membership-canonicalize-principal has been created
at dad0a00b591f4fb4f0ede64367f0aedf7cf73fe2 (commit)
- Log -----------------------------------------------------------------
commit 0280dedf509159d3295d9cb2849e633fc6654e61
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Wed May 1 15:31:18 2019 -0400
Use CanonicalizePrincipal to attempt to load users
Leverage the processing in CanonicalizePrincipal to try to
load users when adding group members. This adds additional
checks, allows loading with an email address, and also will
autocreate users by email address if needed.
diff --git a/share/html/Admin/Groups/Members.html b/share/html/Admin/Groups/Members.html
index e52c44a6b..ec6849568 100644
--- a/share/html/Admin/Groups/Members.html
+++ b/share/html/Admin/Groups/Members.html
@@ -131,18 +131,33 @@ foreach my $key (keys %ARGS) {
# Process new users
foreach my $member (grep $_, @AddMembersUsers) {
- my $principal = RT::User->new($session{'CurrentUser'});
+ my $principal;
+ my $user = RT::User->new($session{'CurrentUser'});
if ($member =~ /^User-(\d+)$/) {
# Old style, using id
- $principal->Load($1);
- } else {
- # New style, just a username
- $principal->Load($member);
+ my ($ret, $msg) = $user->Load($1);
+ if ( $ret ){
+ $principal = $user->PrincipalObj;
+ }
+ else {
+ RT::Logger->error("Unable to load user with id $1: $msg");
+ }
+ }
+ else {
+ # Accept username or email address
+ my $msg;
+ ($principal, $msg) = RT->System->CanonicalizePrincipal( User => $member );
+ RT::Logger->error("Unable to load principal: $msg") unless $principal;
}
- my ($val, $msg) = $Group->AddMember($principal->PrincipalId);
- push (@results, $msg);
+ if ( $principal and $principal->Id ){
+ my ($val, $msg) = $Group->AddMember($principal->Id);
+ push (@results, $msg);
+ }
+ else {
+ push (@results, "Unable to load user $member");
+ }
}
# Process new groups
commit dad0a00b591f4fb4f0ede64367f0aedf7cf73fe2
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu May 2 10:38:14 2019 -0400
Add tests for adding group members by email address
diff --git a/t/web/admin_groups.t b/t/web/admin_groups.t
index 04c742d8c..4abd17f2c 100644
--- a/t/web/admin_groups.t
+++ b/t/web/admin_groups.t
@@ -18,6 +18,28 @@ ok( $m->login(), 'logged in' );
$m->content_contains('Modify the group test group', 'found title');
}
+{
+ diag "Add group members" if $ENV{TEST_VERBOSE};
+ my $group = RT::Group->new( RT->SystemUser );
+ my ($ret, $msg) = $group->LoadUserDefinedGroup('test group');
+
+ $m->get_ok( $url . '/Admin/Groups/Members.html?id=' . $group->Id );
+ $m->content_contains('Editing membership for group test group', 'Loaded group members page');
+ $m->submit_form_ok({
+ form_number => 3,
+ fields => { AddMembersUsers => 'root' },
+ });
+ $m->content_contains('Member added: root', 'Added root to group');
+
+ $m->get_ok( $url . '/Admin/Groups/Members.html?id=' . $group->Id );
+ $m->content_contains('Editing membership for group test group', 'Loaded group members page');
+ $m->submit_form_ok({
+ form_number => 3,
+ fields => { AddMembersUsers => 'user1 at example.com' },
+ });
+ $m->content_contains('Member added: user1 at example.com', 'Added user1 at example.com to group');
+}
+
{
diag "test creating another group" if $ENV{TEST_VERBOSE};
$m->get_ok( $url . '/Admin/Groups/Modify.html?Create=1' );
-----------------------------------------------------------------------
More information about the rt-commit
mailing list