[Rt-commit] rt branch, 4.4/validator-create-missing-ticket-role-groups, created. rt-4.4.2-240-gc7cce5dbf

? sunnavy sunnavy at bestpractical.com
Wed Jul 18 09:56:33 EDT 2018


The branch, 4.4/validator-create-missing-ticket-role-groups has been created
        at  c7cce5dbf66c8d7070cd03f12fc93324958e701f (commit)

- Log -----------------------------------------------------------------
commit 5de5307a9d68e4dc1b5ba42c45b8e268af1628ac
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed May 30 04:00:21 2018 +0800

    Create related role groups if rt-validator finds tickets that don't have any
    
    Note that we intentionally skip merged tickets because it's unnecessary
    and also not trivial to create related role groups for them.

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index 30ab1d2c5..3f6f653ed 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -165,6 +165,7 @@ $redo_on{'Create'} = {
     Groups => ['User <-> ACL equivalence group', 'GMs -> Groups, Members', 'CGM vs. GM' ],
     GroupMembers => [ 'CGM vs. GM' ],
     CachedGroupMembers => [ 'CGM vs. GM' ],
+    Tickets => [ 'Tickets <-> Role Groups' ],
 };
 $redo_on{'Update'} = {
     Groups => ['User Defined Group Name uniqueness'],
@@ -319,9 +320,24 @@ push @CHECKS, 'Tickets <-> Role Groups' => sub {
     # from queue to group
     my $res = 1;
     $res *= check_integrity(
-        'Tickets', 'id' => 'Groups', 'Instance',
+        'Tickets', 'EffectiveId' => 'Groups', 'Instance',
         join_condition   => 't.Domain = ?',
         bind_values => [ 'RT::Ticket-Role' ],
+        action => sub {
+            my $id = shift;
+            return unless prompt(
+                'Create', "Found a ticket that has no role groups."
+            );
+
+            my $ticket = RT::Ticket->new( RT->SystemUser );
+            $ticket->Load( $id );
+            die "Couldn't load ticket #$id" unless $ticket->id;
+
+            print "Creating role groups for ticket #$id\n" if $opt{ 'verbose' };
+            $redo_check{ $_ } = 1 foreach @{ $redo_on{ 'Create' }{ 'Tickets' } };
+            my $ret = $ticket->_CreateRoleGroups();
+            die "Couldn't create role groups for ticket $id" unless $ret;
+        },
     );
     # from group to ticket
     $res *= check_integrity(

commit c7cce5dbf66c8d7070cd03f12fc93324958e701f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 1 23:26:44 2018 +0800

    Test validator for creating missing role groups

diff --git a/t/validator/role_groups.t b/t/validator/role_groups.t
new file mode 100644
index 000000000..2e4692e4b
--- /dev/null
+++ b/t/validator/role_groups.t
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $ticket = RT::Test->create_ticket( Queue => 'General', Subject => 'test ticket' );
+
+RT::Test->db_is_valid;
+
+$RT::Handle->dbh->do( "DELETE FROM Groups where Domain='RT::Ticket-Role' AND Instance=" . $ticket->id );
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+for my $type ( qw/Requestor AdminCc Cc Owner/ ) {
+    ok( !$ticket->RoleGroup( $type )->id, "Deleted group $type" );
+}
+
+my ( $ecode, $res ) = RT::Test->run_validator( resolve => 1 );
+isnt( $ecode, 0, 'non-zero exit code' );
+
+like( $res, qr/Tickets references a nonexistent record in Groups/, 'Found/Fixed error of Tickets <-> Role Groups' );
+
+RT::Test->db_is_valid;
+
+for my $type ( qw/Requestor AdminCc Cc Owner/ ) {
+    ok( $ticket->RoleGroup( $type )->id, "Recreated group $type" );
+}
+
+done_testing;

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


More information about the rt-commit mailing list