4 use RT::Test tests => undef;
6 my $queue = RT::Test->load_or_create_queue( Name => 'Test' );
7 ok $queue && $queue->id, 'loaded or created queue';
9 my $user = RT::Test->load_or_create_user(
13 ok $user && $user->id, 'loaded or created user';
15 my $group = RT::Group->new(RT->SystemUser);
16 my ($ok, $msg) = $group->CreateUserDefinedGroup(Name => 'Disabled Group');
19 ($ok, $msg) = $group->AddMember( $user->PrincipalId );
22 ok( RT::Test->set_rights({
25 Right => [qw(OwnTicket)]
28 RT->Config->Set( AutocompleteOwners => 0 );
29 my ($base, $m) = RT::Test->started_ok;
30 ok $m->login, 'logged in';
32 diag "user from group shows up in create form";
34 $m->get_ok('/', 'open home page');
35 $m->form_name('CreateTicketInQueue');
36 $m->select( 'Queue', $queue->id );
39 $m->content_contains('Create a new ticket', 'opened create ticket page');
40 my $form = $m->form_name('TicketCreate');
41 my $input = $form->find_input('Owner');
42 is $input->value, RT->Nobody->Id, 'correct owner selected';
43 ok((scalar grep { $_ == $user->Id } $input->possible_values), 'user from group is in dropdown');
46 diag "user from disabled group DOESN'T shows up in create form";
48 ($ok, $msg) = $group->SetDisabled(1);
51 $m->get_ok('/', 'open home page');
52 $m->form_name('CreateTicketInQueue');
53 $m->select( 'Queue', $queue->id );
56 $m->content_contains('Create a new ticket', 'opened create ticket page');
57 my $form = $m->form_name('TicketCreate');
58 my $input = $form->find_input('Owner');
59 is $input->value, RT->Nobody->Id, 'correct owner selected';
60 ok((not scalar grep { $_ == $user->Id } $input->possible_values), 'user from disabled group is NOT in dropdown');
61 ($ok, $msg) = $group->SetDisabled(0);
67 diag "Put us in a nested group";
68 my $super = RT::Group->new(RT->SystemUser);
69 ($ok, $msg) = $super->CreateUserDefinedGroup(Name => 'Supergroup');
72 ($ok, $msg) = $super->AddMember( $group->PrincipalId );
75 ok( RT::Test->set_rights({
78 Right => [qw(OwnTicket)]
82 diag "Disable the middle group";
84 ($ok, $msg) = $group->SetDisabled(1);
85 ok($ok, "Disabled group: $msg");
87 $m->get_ok('/', 'open home page');
88 $m->form_name('CreateTicketInQueue');
89 $m->select( 'Queue', $queue->id );
92 $m->content_contains('Create a new ticket', 'opened create ticket page');
93 my $form = $m->form_name('TicketCreate');
94 my $input = $form->find_input('Owner');
95 is $input->value, RT->Nobody->Id, 'correct owner selected';
96 ok((not scalar grep { $_ == $user->Id } $input->possible_values), 'user from disabled group is NOT in dropdown');
97 ($ok, $msg) = $group->SetDisabled(0);
98 ok($ok, "Re-enabled group: $msg");
101 diag "Disable the top group";
103 ($ok, $msg) = $super->SetDisabled(1);
104 ok($ok, "Disabled supergroup: $msg");
106 $m->get_ok('/', 'open home page');
107 $m->form_name('CreateTicketInQueue');
108 $m->select( 'Queue', $queue->id );
111 $m->content_contains('Create a new ticket', 'opened create ticket page');
112 my $form = $m->form_name('TicketCreate');
113 my $input = $form->find_input('Owner');
114 is $input->value, RT->Nobody->Id, 'correct owner selected';
115 ok((not scalar grep { $_ == $user->Id } $input->possible_values), 'user from disabled group is NOT in dropdown');
116 ($ok, $msg) = $super->SetDisabled(0);
117 ok($ok, "Re-enabled supergroup: $msg");
121 diag "Check WithMember and WithoutMember recursively";
123 my $with = RT::Groups->new( RT->SystemUser );
124 $with->WithMember( PrincipalId => $user->PrincipalObj->Id, Recursively => 1 );
125 $with->Limit( FIELD => 'domain', OPERATOR => '=', VALUE => 'UserDefined' );
127 [map {$_->Name} @{$with->ItemsArrayRef}],
128 ['Disabled Group','Supergroup'],
129 "Get expected recursive memberships",
132 my $without = RT::Groups->new( RT->SystemUser );
133 $without->WithoutMember( PrincipalId => $user->PrincipalObj->Id, Recursively => 1 );
134 $without->Limit( FIELD => 'domain', OPERATOR => '=', VALUE => 'UserDefined' );
136 [map {$_->Name} @{$without->ItemsArrayRef}],
138 "And not a member of no groups",
141 ($ok, $msg) = $super->SetDisabled(1);
142 ok($ok, "Disabled supergroup: $msg");
144 $without->RedoSearch;
146 [map {$_->Name} @{$with->ItemsArrayRef}],
148 "Recursive check only contains subgroup",
151 [map {$_->Name} @{$without->ItemsArrayRef}],
153 "Doesn't find the currently disabled group",
155 ($ok, $msg) = $super->SetDisabled(0);
156 ok($ok, "Re-enabled supergroup: $msg");
158 ($ok, $msg) = $group->SetDisabled(1);
159 ok($ok, "Disabled intermediate group: $msg");
161 $without->RedoSearch;
163 [map {$_->Name} @{$with->ItemsArrayRef}],
165 "Recursive check finds no groups",
168 [map {$_->Name} @{$without->ItemsArrayRef}],
170 "Now not a member of the supergroup",
172 ($ok, $msg) = $group->SetDisabled(0);
173 ok($ok, "Re-enabled intermediate group: $msg");
176 diag "Check MemberOfGroup";
178 ($ok, $msg) = $group->SetDisabled(1);
179 ok($ok, "Disabled intermediate group: $msg");
180 my $users = RT::Users->new(RT->SystemUser);
181 $users->MemberOfGroup($super->PrincipalObj->id);
182 is($users->Count, 0, "Supergroup claims no members");
183 ($ok, $msg) = $group->SetDisabled(0);
184 ok($ok, "Re-enabled intermediate group: $msg");