[Rt-commit] rt branch, 4.4/dash-organization-shredder, created. rt-4.4.4-48-ga821bfcf9

? sunnavy sunnavy at bestpractical.com
Mon Jun 10 14:05:22 EDT 2019


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

- Log -----------------------------------------------------------------
commit d0f2b70a14292615ff329dd9256f78e2c554ca9c
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 a92887b44..82ccb85bd 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 4526de5c6980956733e3a5c37760d283bdb3b611
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 82ccb85bd..41b5f79aa 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 {

commit 35236873a7abb91542256b8fa7e0a52941dcf81f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 11 01:04:09 2019 +0800

    Avoid errors in shredder when queue name have a hyphen
    
    Though it's not officially mentioned in document, we actually support
    queue name in shredder besides id(especially considering queue name is
    also unique and RT::Queue->Load supports both).
    
    When queue name contains hyphens, it confuses shredder and results in
    the following error:
    
        Can't wipeout remote object RT::Queue-foo-bar
    
    This commit fixes this issue by expanding the string with organization
    info to make things clear.

diff --git a/lib/RT/Shredder/Plugin/Objects.pm b/lib/RT/Shredder/Plugin/Objects.pm
index de9e5b01f..7495f6cc1 100644
--- a/lib/RT/Shredder/Plugin/Objects.pm
+++ b/lib/RT/Shredder/Plugin/Objects.pm
@@ -80,12 +80,13 @@ sub TestArgs
     my %args = @_;
 
     my @strings;
+    my $Organization = RT->Config->Get('Organization');
     foreach my $name( @RT::Shredder::SUPPORTED_OBJECTS ) {
         next unless $args{$name};
 
         my $list = $args{$name};
         $list = [$list] unless UNIVERSAL::isa( $list, 'ARRAY' );
-        push @strings, map "RT::$name\-$_", @$list;
+        push @strings, map "RT::$name-$Organization-$_", @$list;
     }
 
     my @objs = RT::Shredder->CastObjectsToRecords( Objects => \@strings );

commit a821bfcf92ec39ae657d19583860e7d4ae213218
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 11 02:00:21 2019 +0800

    Test shredder for Organization/User/Queue that contain hyphens

diff --git a/t/shredder/03plugin_objects.t b/t/shredder/03plugin_objects.t
new file mode 100644
index 000000000..11d8a2af5
--- /dev/null
+++ b/t/shredder/03plugin_objects.t
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use Test::Deep;
+use RT::Test::Shredder tests => undef;
+my $test = "RT::Test::Shredder";
+
+use_ok('RT::Shredder::Plugin::Objects');
+
+$test->create_savepoint('clean');
+
+diag "Shred a queue whose name contains a hyphen";
+{
+    my $queue = RT::Test->load_or_create_queue( Name => 'it-support' );
+    ok( $queue->id, 'created queue' );
+    my $plugin = RT::Shredder::Plugin::Objects->new;
+    my ( $status, $msg ) = $plugin->TestArgs( Queue => 'it-support' );
+    ok( $status, "plugin arguments are ok" ) or diag "error: $msg";
+
+    my $shredder = $test->shredder_new();
+
+    ( $status, my @objs ) = $plugin->Run;
+    ok( $status, "executed plugin successfully" );
+    is( scalar @objs,   1,            'found one queue' );
+    is( $objs[0]->Name, 'it-support', 'found the queue' );
+
+    $shredder->PutObjects( Objects => [ 'RT::Queue-' . RT->Config->Get('Organization') . '-it-support' ] );
+    $shredder->WipeoutAll;
+
+    cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+done_testing();
diff --git a/t/shredder/03plugin_users.t b/t/shredder/03plugin_users.t
index 75a920177..b43f8d516 100644
--- a/t/shredder/03plugin_users.t
+++ b/t/shredder/03plugin_users.t
@@ -140,4 +140,23 @@ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to sav
 }
 cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
 
+diag "Shred a user whose name contains a hyphen";
+{
+    my $user = RT::Test->load_or_create_user( Name => 'bilbo-bargins' );
+    my $plugin = RT::Shredder::Plugin::Users->new;
+    my ( $status, $msg ) = $plugin->TestArgs( status => 'any', name => 'bilbo-bargins' );
+    ok( $status, "plugin arguments are ok" ) or diag "error: $msg";
+
+    my $shredder = $test->shredder_new();
+
+    ( $status, my $users ) = $plugin->Run;
+    is( $users->Count, 1, 'found one user' );
+    is( $users->First->Name, 'bilbo-bargins', 'found the user' );
+    ok( $status, "executed plugin successfully" );
+
+    $shredder->PutObjects( Objects => ['RT::User-bilbo-bargins'] );
+    $shredder->WipeoutAll;
+}
+cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
+
 done_testing();
diff --git a/t/shredder/04organization.t b/t/shredder/04organization.t
new file mode 100644
index 000000000..113ea2da8
--- /dev/null
+++ b/t/shredder/04organization.t
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+
+use Test::Deep;
+use RT::Test::Shredder tests => undef, config => 'Set($Organization, "foo-bar");';
+my $test = "RT::Test::Shredder";
+
+use_ok('RT::Shredder::Plugin::Tickets');
+
+$test->create_savepoint('clean');
+
+diag "Shred a queue whose name contains a hyphen";
+{
+    my $ticket = RT::Test->create_ticket( Subject => 'Test organization with a hyphen', Queue => 1 );
+    $ticket->ApplyTransactionBatch;
+
+    my $plugin = RT::Shredder::Plugin::Tickets->new;
+    my ( $status, $msg ) = $plugin->TestArgs( query => 'id = ' . $ticket->id );
+    ok( $status, "plugin arguments are ok" ) or diag "error: $msg";
+
+    my $shredder = $test->shredder_new();
+
+    ( $status, my $tickets ) = $plugin->Run;
+    ok( $status, "executed plugin successfully" );
+    is( $tickets->Count,     1,           'found one ticket' );
+    is( $tickets->First->id, $ticket->id, 'found the ticket' );
+
+    $shredder->PutObjects( Objects => [ 'RT::Ticket-' . RT->Config->Get('Organization') . '-' . $ticket->id ] );
+    $shredder->WipeoutAll;
+
+    cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+done_testing();

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


More information about the rt-commit mailing list