[Rt-commit] rt branch, 4.4/validate-default-roles, created. rt-4.4.3-90-g5ed396095

? sunnavy sunnavy at bestpractical.com
Thu Dec 13 13:28:25 EST 2018


The branch, 4.4/validate-default-roles has been created
        at  5ed396095275a5e94e4cc86969a2da438f564e40 (commit)

- Log -----------------------------------------------------------------
commit 547eee59572d71ddc525ef80c2ad580c1df1e713
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jul 9 19:51:37 2014 -0400

    Ensure tickets and queues have all of their default role groups, individually

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index 30ab1d2c5..c2b59b843 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -288,14 +288,15 @@ push @CHECKS, 'User <-> ACL equivalence group' => sub {
 
 # check integrity of Queue role groups
 push @CHECKS, 'Queues <-> Role Groups' => sub {
-    # XXX: we check only that there is at least one group for a queue
     # from queue to group
     my $res = 1;
-    $res *= check_integrity(
-        'Queues', 'id' => 'Groups', 'Instance',
-        join_condition   => 't.Domain = ?',
-        bind_values => [ 'RT::Queue-Role' ],
-    );
+    for my $role (qw/Requestor Owner Cc AdminCc/ ) {
+        $res *= check_integrity(
+            'Queues', 'id' => 'Groups', 'Instance',
+            join_condition   => 't.Domain = ? AND t.Name = ?',
+            bind_values => [ 'RT::Queue-Role', $role ],
+        );
+    }
     # from group to queue
     $res *= check_integrity(
         'Groups', 'Instance' => 'Queues', 'id',
@@ -315,14 +316,15 @@ push @CHECKS, 'Queues <-> Role Groups' => sub {
 
 # check integrity of Ticket role groups
 push @CHECKS, 'Tickets <-> Role Groups' => sub {
-    # XXX: we check only that there is at least one group for a queue
     # from queue to group
     my $res = 1;
-    $res *= check_integrity(
-        'Tickets', 'id' => 'Groups', 'Instance',
-        join_condition   => 't.Domain = ?',
-        bind_values => [ 'RT::Ticket-Role' ],
-    );
+    for my $role (qw/Requestor Owner Cc AdminCc/ ) {
+        $res *= check_integrity(
+            'Tickets', 'id' => 'Groups', 'Instance',
+            join_condition   => 't.Domain = ? AND t.Name = ?',
+            bind_values => [ 'RT::Ticket-Role', $role ],
+        );
+    }
     # from group to ticket
     $res *= check_integrity(
         'Groups', 'Instance' => 'Tickets', 'id',

commit 9ae1fc046a4c3ff766e6e650e7f98c5fdc6f885b
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jul 9 19:52:25 2014 -0400

    Prompt to create missing default role groups

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index c2b59b843..855ee7a59 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -295,6 +295,22 @@ push @CHECKS, 'Queues <-> Role Groups' => sub {
             'Queues', 'id' => 'Groups', 'Instance',
             join_condition   => 't.Domain = ? AND t.Name = ?',
             bind_values => [ 'RT::Queue-Role', $role ],
+            action => sub {
+                my $id = shift;
+                return unless prompt(
+                    'Create', "Found a queue missing a $role role group"
+                );
+
+                my $group = RT::Group->new( RT->SystemUser );
+                $group->_Create(
+                    Domain   => 'RT::Queue-Role',
+                    Name     => $role,
+                    Instance => $id,
+                );
+                $redo_check{ $_ } = 1 for
+                    @{ $redo_on{'Create'}{ Principals } || [] },
+                    @{ $redo_on{'Create'}{ Groups } || [] };
+            },
         );
     }
     # from group to queue
@@ -323,6 +339,22 @@ push @CHECKS, 'Tickets <-> Role Groups' => sub {
             'Tickets', 'id' => 'Groups', 'Instance',
             join_condition   => 't.Domain = ? AND t.Name = ?',
             bind_values => [ 'RT::Ticket-Role', $role ],
+            action => sub {
+                my $id = shift;
+                return unless prompt(
+                    'Create', "Found a ticket missing a $role role group"
+                );
+
+                my $group = RT::Group->new( RT->SystemUser );
+                $group->_Create(
+                    Domain   => 'RT::Ticket-Role',
+                    Name     => $role,
+                    Instance => $id,
+                );
+                $redo_check{ $_ } = 1 for
+                    @{ $redo_on{'Create'}{ Principals } || [] },
+                    @{ $redo_on{'Create'}{ Groups } || [] };
+            },
         );
     }
     # from group to ticket

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

    Test validator for creating missing default role groups

diff --git a/t/validator/role_groups.t b/t/validator/role_groups.t
new file mode 100644
index 000000000..a32ddcf13
--- /dev/null
+++ b/t/validator/role_groups.t
@@ -0,0 +1,33 @@
+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 IN ('RT::Queue-Role', 'RT::Ticket-Role')");
+DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+for my $object ( $ticket, $ticket->QueueObj ) {
+    for my $type (qw/Requestor AdminCc Cc Owner/) {
+        ok( !$object->RoleGroup($type)->id, "Deleted group $type for " . ref $object );
+    }
+}
+
+my ( $ecode, $res ) = RT::Test->run_validator( resolve => 1 );
+isnt( $ecode, 0, 'non-zero exit code' );
+
+like( $res, qr/Queues references a nonexistent record in Groups/,  'Found/Fixed error of Queues <-> Role Groups' );
+like( $res, qr/Tickets references a nonexistent record in Groups/, 'Found/Fixed error of Tickets <-> Role Groups' );
+
+RT::Test->db_is_valid;
+
+for my $object ( $ticket, $ticket->QueueObj ) {
+    for my $type (qw/Requestor AdminCc Cc Owner/) {
+        ok( $object->RoleGroup($type)->id, "Recreated group $type for " . ref $object );
+    }
+}
+
+done_testing;

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


More information about the rt-commit mailing list