Skip to content

Commit

Permalink
Test HideSuperUserOwners config
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Nov 9, 2023
1 parent d437599 commit 46e929d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
37 changes: 36 additions & 1 deletion t/web/ticket_owner.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ my $user_c = RT::Test->load_or_create_user(
);
ok $user_c && $user_c->id, 'loaded or created user: ' . $user_c->Name;

my ($baseurl, $agent_a) = RT::Test->started_ok;
my $user_super = RT::Test->load_or_create_user(
Name => 'user_super', Password => 'password',
);
ok $user_super && $user_super->id, 'loaded or created user: ' . $user_super->Name;

my ($baseurl, $agent_a) = RT::Test->started_ok( disable_config_cache => 1 );

ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
{ Principal => $user_super, Right => [qw(SuperUser)] },
), 'set rights');

ok $agent_a->login('user_a', 'password'), 'logged in as user A';
Expand All @@ -40,6 +46,8 @@ diag "current user has no right to own, nobody selected as owner on create";
is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
ok !grep($_ == $user_a->id, $form->find_input('Owner')->possible_values),
'user A can not own tickets';
ok !grep($_ == $user_super->id, $form->find_input('Owner')->possible_values),
'user Super is not shown on Owner input for normal users';
$agent_a->click('SubmitTicket');

$agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
Expand Down Expand Up @@ -509,4 +517,31 @@ diag "user can take/steal ticket with ReassignTicket+OwnTicket right";
ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
}

diag 'Hide super users';
{
my $agent_super = RT::Test::Web->new;
ok $agent_super->login('user_super', 'password'), 'logged in as user Super';

$agent_super->get_ok('/Ticket/Create.html?Queue=' . $queue->id, 'open ticket create page');
$agent_super->content_contains('Create a new ticket', 'opened create ticket page');
my $form = $agent_super->form_name('TicketCreate');
ok grep($_ == $user_super->id, $form->find_input('Owner')->possible_values),
'user Super is shown on Owner input';

my $config = RT::Configuration->new( RT->SystemUser );
my ( $ret, $msg ) = $config->Create( Name => 'HideSuperUserOwners', Content => 1 );
ok( $ret, 'Updated config' );

$agent_super->reload;
$form = $agent_super->form_name('TicketCreate');
ok !grep($_ == $user_super->id, $form->find_input('Owner')->possible_values),
'user Super is not shown on Owner input';

ok( $user_super->PrincipalObj->GrantRight( Object => RT->System, Right => 'OwnTicket' ) );
$agent_super->reload;
$form = $agent_super->form_name('TicketCreate');
ok grep($_ == $user_super->id, $form->find_input('Owner')->possible_values),
'user Super is shown on Owner input with additional OwnTicket granted';
}

done_testing;
37 changes: 35 additions & 2 deletions t/web/ticket_owner_autocomplete.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use strict;
use warnings;

use RT::Test nodata => 1, tests => 43;
use RT::Test nodata => 1, tests => undef;
use JSON qw(from_json);

my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
Expand All @@ -18,12 +18,18 @@ my $user_b = RT::Test->load_or_create_user(
);
ok $user_b && $user_b->id, 'loaded or created user';

my $user_super = RT::Test->load_or_create_user(
Name => 'user_super', Password => 'password',
);
ok $user_super && $user_super->id, 'loaded or created user: ' . $user_super->Name;

RT->Config->Set( AutocompleteOwners => 1 );
my ($baseurl, $agent_a) = RT::Test->started_ok;
my ($baseurl, $agent_a) = RT::Test->started_ok( disable_config_cache => 1 );

ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
{ Principal => $user_super, Right => [qw(SuperUser)] },
), 'set rights');

ok $agent_a->login('user_a', 'password'), 'logged in as user A';
Expand All @@ -35,6 +41,7 @@ diag "current user has no right to own, nobody selected as owner on create";
my $form = $agent_a->form_name('TicketCreate');
is $form->value('Owner'), RT->Nobody->Name, 'correct owner selected';
autocomplete_lacks( 'RT::Queue-'.$queue->id, 'user_a' );
autocomplete_lacks( 'RT::Queue-'.$queue->id, 'user_super' );
$agent_a->click('SubmitTicket');

$agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
Expand Down Expand Up @@ -131,6 +138,31 @@ diag "on reply correct owner is selected";
is $ticket->Owner, $user_b->id, 'correct owner';
}

diag 'Hide super users';
{
my $agent_super = RT::Test::Web->new;
ok $agent_super->login('user_super', 'password'), 'logged in as user Super';

$agent_super->get_ok('/Ticket/Create.html?Queue=' . $queue->id, 'open ticket create page');
$agent_super->content_contains('Create a new ticket', 'opened create ticket page');
my $form = $agent_super->form_name('TicketCreate');
autocomplete_contains( 'RT::Queue-'.$queue->id, 'user_super', $agent_super );

my $config = RT::Configuration->new( RT->SystemUser );
my ( $ret, $msg ) = $config->Create( Name => 'HideSuperUserOwners', Content => 1 );
ok( $ret, 'Updated config' );

$agent_super->reload;
$form = $agent_super->form_name('TicketCreate');
autocomplete_lacks( 'RT::Queue-'.$queue->id, 'user_super', $agent_super );

ok( $user_super->PrincipalObj->GrantRight( Object => RT->System, Right => 'OwnTicket' ) );
$agent_super->reload;
$form = $agent_super->form_name('TicketCreate');
autocomplete_contains( 'RT::Queue-'.$queue->id, 'user_super', $agent_super );

}

sub autocomplete {
my $limit = shift;
my $agent = shift;
Expand Down Expand Up @@ -174,3 +206,4 @@ sub autocomplete_lacks {
is((scalar grep { $seen{$_} } @$lacks), 0, "didn't get any unexpected values");
}

done_testing;

0 comments on commit 46e929d

Please sign in to comment.