[Rt-commit] rt branch 5.0/rest2-canonicalize-principal-exception created. rt-5.0.4-20-gdb9997dc63

BPS Git Server git at git.bestpractical.com
Fri Jun 9 19:49:42 UTC 2023


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/rest2-canonicalize-principal-exception has been created
        at  db9997dc63194079b650ff70dc43033283f46746 (commit)

- Log -----------------------------------------------------------------
commit db9997dc63194079b650ff70dc43033283f46746
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 10 03:37:27 2023 +0800

    Check return value of CanonicalizePrincipal in case username/email is invaild
    
    This is to get rid of the possible error like:
    
        Can't locate object method "Id" via package "0"
    
    This could happen if you try to add an invalid user/email to ticket watchers.
    
    With this commit, user will also be able to see the error message which
    helps debug.

diff --git a/lib/RT/REST2/Util.pm b/lib/RT/REST2/Util.pm
index 5317384652..f903f03231 100644
--- a/lib/RT/REST2/Util.pm
+++ b/lib/RT/REST2/Util.pm
@@ -563,8 +563,13 @@ sub update_role_members {
                     $principal_id = $_;
                 }
                 elsif ($record->can('CanonicalizePrincipal')) {
-                    ((my $principal), $msg) = $record->CanonicalizePrincipal(User => $_);
-                    $principal_id = $principal->Id;
+                    ((my $principal), $msg) = $record->CanonicalizePrincipal(User => $_, Type => $role);
+                    if ($principal) {
+                        $principal_id = $principal->Id;
+                    }
+                    else {
+                        RT->Logger->error($msg);
+                    }
                 }
                 else {
                     my $user = RT::User->new($record->CurrentUser);

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list