5 use RT::Test tests => 14;
7 my ($baseurl, $m) = RT::Test->started_ok;
8 ok $m->login, "logged in";
10 $m->follow_link_ok({ text => 'Configuration' });
11 $m->follow_link_ok({ text => 'Global' });
12 $m->follow_link_ok({ text => 'Group Rights' });
17 my $principal_id = shift;
19 $agent->form_number(3);
20 my @inputs = $agent->current_form->find_input("RevokeRight-$principal_id-$object");
21 my @rights = sort grep $_, map $_->possible_values, grep $_, @inputs;
25 diag "load Everyone group" if $ENV{'TEST_VERBOSE'};
26 my ($everyone, $everyone_gid);
28 $everyone = RT::Group->new( $RT::SystemUser );
29 $everyone->LoadSystemInternalGroup('Everyone');
30 ok($everyone_gid = $everyone->id, "loaded 'everyone' group");
33 diag "revoke all global rights from Everyone group" if $ENV{'TEST_VERBOSE'};
34 my @has = get_rights( $m, $everyone_gid, 'RT::System-1' );
37 $m->tick("RevokeRight-$everyone_gid-RT::System-1", $_) foreach @has;
40 is_deeply([get_rights( $m, $everyone_gid, 'RT::System-1' )], [], 'deleted all rights' );
42 ok(1, 'the group has no global rights');
45 diag "grant SuperUser right to everyone" if $ENV{'TEST_VERBOSE'};
48 $m->select("GrantRight-$everyone_gid-RT::System-1", ['SuperUser']);
51 $m->content_contains('Right Granted', 'got message');
52 RT::Principal::InvalidateACLCache();
53 ok($everyone->PrincipalObj->HasRight( Right => 'SuperUser', Object => $RT::System ), 'group has right');
54 is_deeply( [get_rights( $m, $everyone_gid, 'RT::System-1' )], ['SuperUser'], 'granted SuperUser right' );
57 diag "revoke the right" if $ENV{'TEST_VERBOSE'};
60 $m->tick("RevokeRight-$everyone_gid-RT::System-1", 'SuperUser');
63 $m->content_contains('Right revoked', 'got message');
64 RT::Principal::InvalidateACLCache();
65 ok(!$everyone->PrincipalObj->HasRight( Right => 'SuperUser', Object => $RT::System ), 'group has no right');
66 is_deeply( [get_rights( $m, $everyone_gid, 'RT::System-1' )], [], 'revoked SuperUser right' );
70 diag "return rights the group had in the beginning" if $ENV{'TEST_VERBOSE'};
73 $m->select("GrantRight-$everyone_gid-RT::System-1", \@has);
76 $m->content_contains('Right Granted', 'got message');
78 [ get_rights( $m, $everyone_gid, 'RT::System-1' ) ],
80 'returned back all rights'
83 ok(1, 'the group had no global rights, so nothing to return');