[Rt-commit] rt branch, 4.4/dash-organization-shredder, created. rt-4.4.1-2-g856e26f

Shawn Moore shawn at bestpractical.com
Fri Aug 4 12:56:27 EDT 2017


The branch, 4.4/dash-organization-shredder has been created
        at  856e26f97c57a5389888be9d0e9816fb718779a8 (commit)

- Log -----------------------------------------------------------------
commit ed007dae34aa1332f7af778681da89c524f223dc
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri Aug 4 16:33:55 2017 +0000

    Avoid errors in shredder when Organization has a hyphen
    
    Previously, when you shredded RT::Ticket 1 with an $Organization of
    "Organ-Ization", then this faulty line of code:
    
        ($class, $org, $id) = split /-/, $targets;
    
    would leave you with a $class of RT::Ticket, an $org of "Organ", an $id
    of "Ization", and the id of 1 being dropped. Since $org "Organ" !=
    $Organization "Organ-Ization", you'd get the spurious error:
    
        Can't wipeout remote object RT::Ticket-Organ-Ization-1
    
    Instead, since what we care about is whether the target is local or
    remote by way of checking $Organization, just put $Organization into the
    regular expression.
    
    Fixes: I#32406

diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 9590edb..08c7ffe 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -344,11 +344,12 @@ sub CastObjectsToRecords
         }
     } elsif ( UNIVERSAL::isa( $targets, 'SCALAR' ) || !ref $targets ) {
         $targets = $$targets if ref $targets;
-        my ($class, $org, $id);
-        if ($targets =~ /-.*-/) {
-            ($class, $org, $id) = split /-/, $targets;
-            RT::Shredder::Exception->throw( "Can't wipeout remote object $targets" )
-                  unless $org eq RT->Config->Get('Organization');
+        my $Organization = RT->Config->Get('Organization');
+        my ($class, $id);
+        if ($targets =~ /^([\w:]+)-\Q$Organization\E-(.+)$/) {
+            ($class, $id) = ($1, $2);
+        } elsif ($targets =~ /-.*-/) {
+            RT::Shredder::Exception->throw( "Can't wipeout remote object $targets" );
         } else {
             ($class, $id) = split /-/, $targets;
         }

commit 856e26f97c57a5389888be9d0e9816fb718779a8
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri Aug 4 16:42:56 2017 +0000

    Avoid errors in shredder when username has a hyphen
    
    Shredder uses username instead of user ID internally (due to
    RT::User->UID being overridden to include the username).
    But if there's a hyphen in the username, e.g. user-name, then shredder
    misinterprets the target "RT::User-user-name" as having an organization of
    "user" and an id of "name", leading to this spurious error:
    
        Can't wipeout remote object RT::User-user-name
    
    RT::User's override of the UID method was introduced without comment in
    eb81069b, almost immediately after RT::Record->UID was first added.
    However it is difficult to determine whether or not the intent was
    _only_ to use the username instead of the id and that Organization was
    left off by mistake. Regardless, the new special case here in Shredder
    matches the existing special case in RT::User->UID.

diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 08c7ffe..95f3f31 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -348,6 +348,8 @@ sub CastObjectsToRecords
         my ($class, $id);
         if ($targets =~ /^([\w:]+)-\Q$Organization\E-(.+)$/) {
             ($class, $id) = ($1, $2);
+        } elsif ($targets =~ /^(RT::User)-(.*)$/) {
+            ($class, $id) = ($1, $2);
         } elsif ($targets =~ /-.*-/) {
             RT::Shredder::Exception->throw( "Can't wipeout remote object $targets" );
         } else {

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


More information about the rt-commit mailing list