4 use RT::Test nodata => 1, tests => undef;
8 my $tester = RT::Test->load_or_create_user(
9 EmailAddress => 'tester@localhost',
11 ok $tester && $tester->id, 'loaded or created user';
13 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
14 ok $queue && $queue->id, 'loaded or created queue';
16 my $owner_role_group = $queue->RoleGroup( 'Owner' );
17 ok $owner_role_group->id, 'loaded owners role group of the queue';
19 diag "check that deffering owner doesn't regress";
22 { Principal => $tester->PrincipalObj,
23 Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
25 { Principal => $owner_role_group->PrincipalObj,
27 Right => [qw(ModifyTicket)],
30 my $ticket = RT::Ticket->new( $tester );
31 # tester is owner, owner has right to modify owned tickets,
32 # this right is required to set somebody as AdminCc
33 my ($tid, $txn_id, $msg) = $ticket->Create(
36 AdminCc => 'root@localhost',
39 ok $tid, "created a ticket";
40 is $ticket->Owner, $tester->id, 'correct owner';
41 like $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there';
44 diag "check that previous trick doesn't work without sufficient rights";
47 { Principal => $tester->PrincipalObj,
48 Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
51 my $ticket = RT::Ticket->new( $tester );
52 # tester is owner, owner has right to modify owned tickets,
53 # this right is required to set somebody as AdminCc
54 my ($tid, $txn_id, $msg) = $ticket->Create(
57 AdminCc => 'root@localhost',
60 ok $tid, "created a ticket";
61 is $ticket->Owner, $tester->id, 'correct owner';
62 unlike $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is not there';
65 diag "check that deffering owner really works";
68 { Principal => $tester->PrincipalObj,
69 Right => [qw(SeeQueue ShowTicket CreateTicket)],
71 { Principal => $queue->Cc->PrincipalObj,
73 Right => [qw(OwnTicket TakeTicket)],
76 my $ticket = RT::Ticket->new( $tester );
77 # set tester as Cc, Cc role group has right to own and take tickets
78 my ($tid, $txn_id, $msg) = $ticket->Create(
81 Cc => 'tester@localhost',
84 ok $tid, "created a ticket";
85 like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
86 is $ticket->Owner, $tester->id, 'tester is also owner';
87 my $owners = $ticket->OwnerGroup->MembersObj;
88 is $owners->Count, 1, 'one record in owner group';
89 is $owners->First->MemberObj->Id, $tester->id, 'and it is tester';
92 diag "check that deffering doesn't work without correct rights";
95 { Principal => $tester->PrincipalObj,
96 Right => [qw(SeeQueue ShowTicket CreateTicket)],
100 my $ticket = RT::Ticket->new( $tester );
101 # set tester as Cc, Cc role group has right to own and take tickets
102 my ($tid, $txn_id, $msg);
104 ($tid, $txn_id, $msg) = $ticket->Create(
106 Owner => $tester->id,
107 Cc => 'tester@localhost',
109 } qr/User .* was proposed as a ticket owner but has no rights to own tickets in General/;
112 ok $tid, "created a ticket";
113 like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
114 is $ticket->Owner, RT->Nobody->id, 'nobody is the owner';
115 my $owners = $ticket->OwnerGroup->MembersObj;
116 is $owners->Count, 1, 'one record in owner group';
117 is $owners->First->MemberObj->Id, RT->Nobody->id, 'and it is nobody';