[Rt-commit] rt branch, 4.4/tweak-groups-in-ticket-roles, updated. rt-4.4.4-11-gd1fbdcde2

? sunnavy sunnavy at bestpractical.com
Fri Mar 8 16:51:24 EST 2019


The branch, 4.4/tweak-groups-in-ticket-roles has been updated
       via  d1fbdcde20b2dc429d32a74fbb42db098bd2258b (commit)
      from  2509f50a93cbbcc5ce060d9996e90459a51152e2 (commit)

Summary of changes:
 t/api/group.t               | 65 ++++++++++++++++++++++++++++++++++++
 t/api/rights.t              | 80 ++++++++++++++++++++++++++++++++++++++++++++-
 t/validator/group_members.t | 17 ++++++++++
 3 files changed, 161 insertions(+), 1 deletion(-)

- Log -----------------------------------------------------------------
commit d1fbdcde20b2dc429d32a74fbb42db098bd2258b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Mar 9 05:44:28 2019 +0800

    Add tests for CGM changes of ticket role groups
    
    As we no longer create indirect member rows in CachedGroupMembers for
    ticket role groups, here are the tests to confirm RT still behaves
    correctly.

diff --git a/t/api/group.t b/t/api/group.t
index f82dfc57e..7ec3a341e 100644
--- a/t/api/group.t
+++ b/t/api/group.t
@@ -116,4 +116,69 @@ is($u->PrincipalObj->PrincipalType , 'Group' , "Principal 4 is a group");
     ok( !$id, "can't create duplicated group even case is different: $msg" );
 }
 
+diag "Ticket role group members";
+{
+    RT::Test->load_or_create_queue( Name => 'General' );
+    my $ticket    = RT::Test->create_ticket( Queue => 'General', Subject => 'test ticket role group' );
+    my $admincc   = $ticket->RoleGroup('AdminCc');
+    my $delegates = RT::Test->load_or_create_group('delegates');
+    my $core      = RT::Test->load_or_create_group('core team');
+    my $alice     = RT::Test->load_or_create_user( Name => 'alice' );
+    my $bob       = RT::Test->load_or_create_user( Name => 'bob' );
+
+    ok( $admincc->AddMember( $delegates->PrincipalId ), 'Add delegates to AdminCc' );
+    ok( $delegates->AddMember( $core->PrincipalId ),    'Add core team to delegates' );
+    ok( $delegates->AddMember( $bob->PrincipalId ),     'Add bob to delegates' );
+    ok( $core->AddMember( $alice->PrincipalId ),        'Add alice to core team' );
+
+    ok( $admincc->HasMember( $delegates->PrincipalId ),        'AdminCc has direct member of delegates' );
+    ok( !$admincc->HasMember( $core->PrincipalId ),            "AdminCc doesn't have member of core" );
+    ok( !$admincc->HasMember( $bob->PrincipalId ),             "AdminCc doesn't have member of bob" );
+    ok( !$admincc->HasMember( $alice->PrincipalId ),           "AdminCc doesn't have member of bob" );
+    ok( $admincc->HasMemberRecursively( $core->PrincipalId ),  "AdminCc recursively has member of core" );
+    ok( $admincc->HasMemberRecursively( $bob->PrincipalId ),   "AdminCc recursively has member of bob" );
+    ok( $admincc->HasMemberRecursively( $alice->PrincipalId ), "AdminCc recursively has member of alice" );
+
+    my $CGM = RT::CachedGroupMember->new( RT->SystemUser );
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $delegates->PrincipalId );
+    ok( $CGM->id, 'CGM record for admincc <-> delegates' );
+
+    $CGM->LoadByCols( GroupId => $delegates->PrincipalId, MemberId => $core->PrincipalId );
+    ok( $CGM->id, 'CGM record for delegates <-> core' );
+
+    $CGM->LoadByCols( GroupId => $core->PrincipalId, MemberId => $alice->PrincipalId );
+    ok( $CGM->id, 'CGM record for core <-> alice' );
+
+    $CGM->LoadByCols( GroupId => $delegates->PrincipalId, MemberId => $alice->PrincipalId );
+    ok( $CGM->id, 'CGM record for delegates <-> alice' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $core->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> core' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $alice->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> alice' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $bob->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> bob' );
+
+    ok( $admincc->DeleteMember( $delegates->PrincipalId ), 'Delete delegates from AdminCc' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $delegates->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> delegates' );
+
+    ok( $admincc->AddMember( $delegates->PrincipalId ), 'Add delegates to AdminCc again' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $delegates->PrincipalId );
+    ok( $CGM->id, 'CGM record for admincc <-> delegates again' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $core->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> corei still' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $alice->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> alice still' );
+
+    $CGM->LoadByCols( GroupId => $admincc->PrincipalId, MemberId => $bob->PrincipalId );
+    ok( !$CGM->id, 'No CGM record for admincc <-> bob still' );
+}
+
 done_testing;
diff --git a/t/api/rights.t b/t/api/rights.t
index a6346a737..def221dc0 100644
--- a/t/api/rights.t
+++ b/t/api/rights.t
@@ -1,4 +1,4 @@
-use RT::Test nodata => 1, tests => 38;
+use RT::Test nodata => 1, tests => undef;
 
 use strict;
 use warnings;
@@ -174,3 +174,81 @@ note "Right name canonicalization";
     ok $ok, "Granted ShowTicket: $msg";
     ok $user->HasRight( Right => "showticket", Object => RT->System ), "HasRight showticket";
 }
+
+diag "Ticket role rights for users in groups that are added in ticket roles";
+{
+    RT::Test->load_or_create_queue( Name => 'General' );
+    my $ticket = RT::Test->create_ticket( Queue => 'General', Subject => 'test ticket role group' );
+    my $admincc = $ticket->RoleGroup('AdminCc');
+    ok( $admincc->PrincipalObj->GrantRight( Right => 'ShowTicket', Object => $ticket->QueueObj ),
+        'Grant AdminCc ShowTicket right' );
+
+    my $delegates = RT::Test->load_or_create_group('delegates');
+    my $core      = RT::Test->load_or_create_group('core team');
+    my $alice     = RT::Test->load_or_create_user( Name => 'alice' );
+    my $bob       = RT::Test->load_or_create_user( Name => 'bob' );
+    ok( $delegates->AddMember( $core->PrincipalId ), 'Add core team to delegates' );
+    ok( $delegates->AddMember( $bob->PrincipalId ),  'Add bob to delegates' );
+    ok( $core->AddMember( $alice->PrincipalId ),     'Add alice to core team' );
+
+    my $current_alice = RT::CurrentUser->new( RT->SystemUser );
+    $current_alice->Load( $alice->id );
+    my $current_bob = RT::CurrentUser->new( RT->SystemUser );
+    $current_bob->Load( $bob->id );
+
+    for my $current_user ( $current_alice, $current_bob ) {
+        ok( !$current_user->HasRight( Object => $ticket, Right => 'ShowTicket' ),
+            'No ShowTicket right for ' . $current_user->Name );
+        my $tickets = RT::Tickets->new($current_user);
+        $tickets->FromSQL("Subject = 'test ticket role group'");
+        ok( !$tickets->Count, 'No tickets found for user ' . $current_user->Name );
+    }
+
+    ok( $admincc->AddMember( $delegates->PrincipalId ), 'Add delegates to AdminCc' );
+
+    for my $current_user ( $current_alice, $current_bob ) {
+        ok( $current_user->HasRight( Object => $ticket, Right => 'ShowTicket' ),
+            'Has ShowTicket right for ' . $current_user->Name );
+        my $tickets = RT::Tickets->new($current_user);
+        $tickets->FromSQL("Subject = 'test ticket role group'");
+        is( $tickets->Count,     1,           'Found 1 ticket for ' . $current_user->Name );
+        is( $tickets->First->id, $ticket->id, 'Found the ticket for ' . $current_user->Name );
+    }
+
+    ok( $admincc->DeleteMember( $delegates->PrincipalId ), 'Delete delegates from AdminCc' );
+    for my $current_user ( $current_alice, $current_bob ) {
+        ok( !$current_user->HasRight( Object => $ticket, Right => 'ShowTicket' ),
+            'No ShowTicket right any more for ' . $current_user->Name
+        );
+        my $tickets = RT::Tickets->new($current_user);
+        $tickets->FromSQL("Subject = 'test ticket role group'");
+        ok( !$tickets->Count, 'No tickets found any more for ' . $current_user->Name );
+    }
+
+
+    ok( $admincc->AddMember( $delegates->PrincipalId ), 'Add delegates to AdminCc again' );
+
+    for my $current_user ( $current_alice, $current_bob ) {
+        ok( $current_user->HasRight( Object => $ticket, Right => 'ShowTicket' ),
+            'Has ShowTicket right again for ' . $current_user->Name
+        );
+        my $tickets = RT::Tickets->new($current_user);
+        $tickets->FromSQL("Subject = 'test ticket role group'");
+        is( $tickets->Count,     1,           'Found 1 ticket again for ' . $current_user->Name );
+        is( $tickets->First->id, $ticket->id, 'Found the ticket again for ' . $current_user->Name );
+    }
+
+    ok( $admincc->PrincipalObj->RevokeRight( Right => 'ShowTicket', Object => $ticket->QueueObj ),
+        'Revoke AdminCc ShowTicket right' );
+
+    for my $current_user ( $current_alice, $current_bob ) {
+        ok( !$current_user->HasRight( Object => $ticket, Right => 'ShowTicket' ),
+            'No ShowTicket right any more for ' . $current_user->Name
+        );
+        my $tickets = RT::Tickets->new($current_user);
+        $tickets->FromSQL("Subject = 'test ticket role group'");
+        ok( !$tickets->Count, 'No tickets found any more for ' . $current_user->Name );
+    }
+}
+
+done_testing;
diff --git a/t/validator/group_members.t b/t/validator/group_members.t
index 0fd1a749a..ada0815a1 100644
--- a/t/validator/group_members.t
+++ b/t/validator/group_members.t
@@ -125,4 +125,21 @@ RT::Test->db_is_valid;
     RT::Test->db_is_valid;
 }
 
+diag "CGM recurisve check for ticket role groups";
+{
+    my $ticket    = RT::Test->create_ticket( Queue => 'General', Subject => 'test ticket role group' );
+    my $admincc   = $ticket->RoleGroup('AdminCc');
+    my $delegates = RT::Test->load_or_create_group('delegates');
+    my $core      = RT::Test->load_or_create_group('core team');
+    my $alice     = RT::Test->load_or_create_user( Name => 'alice' );
+    my $bob       = RT::Test->load_or_create_user( Name => 'bob' );
+
+    ok( $admincc->AddMember( $delegates->PrincipalId ), 'Add delegates to AdminCc' );
+    ok( $delegates->AddMember( $core->PrincipalId ),    'Add core team to delegates' );
+    ok( $delegates->AddMember( $bob->PrincipalId ),     'Add bob to delegates' );
+    ok( $core->AddMember( $alice->PrincipalId ),        'Add alice to core team' );
+
+    RT::Test->db_is_valid;
+}
+
 done_testing;

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


More information about the rt-commit mailing list