1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
use strict;
use warnings;
use RT::Test nodata => 1, tests => undef;
my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $queue && $queue->id, 'loaded or created queue';
my $user_a = RT::Test->load_or_create_user(
Name => 'user_a', Password => 'password',
);
ok $user_a && $user_a->id, 'loaded or created user: ' . $user_a->Name;
my $user_b = RT::Test->load_or_create_user(
Name => 'user_b', Password => 'password',
);
ok $user_b && $user_b->id, 'loaded or created user: ' . $user_b->Name;
# To give ReassignTicket
my $user_c = RT::Test->load_or_create_user(
Name => 'user_c', Password => 'password',
);
ok $user_c && $user_c->id, 'loaded or created user: ' . $user_c->Name;
my ($baseurl, $agent_a) = RT::Test->started_ok;
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
ok $agent_a->login('user_a', 'password'), 'logged in as user A';
diag "current user has no right to own, nobody selected as owner on create";
{
$agent_a->get_ok('/', 'open home page');
$agent_a->form_name('CreateTicketInQueue');
$agent_a->select( 'Queue', $queue->id );
$agent_a->submit;
$agent_a->content_contains('Create a new ticket', 'opened create ticket page');
my $form = $agent_a->form_name('TicketCreate');
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';
$agent_a->submit;
$agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
ok $id, 'found id of the ticket';
my $ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, RT->Nobody->id, 'correct owner';
}
diag "user can chose owner of a new ticket";
{
$agent_a->get_ok('/', 'open home page');
$agent_a->form_name('CreateTicketInQueue');
$agent_a->select( 'Queue', $queue->id );
$agent_a->submit;
$agent_a->content_contains('Create a new ticket', 'opened create ticket page');
my $form = $agent_a->form_name('TicketCreate');
is $form->value('Owner'), RT->Nobody->id, 'correct owner selected';
ok grep($_ == $user_b->id, $form->find_input('Owner')->possible_values),
'user B is listed as potential owner';
$agent_a->select('Owner', $user_b->id);
$agent_a->submit;
$agent_a->content_like(qr/Ticket \d+ created in queue/i, 'created ticket');
my ($id) = ($agent_a->content =~ /Ticket (\d+) created in queue/);
ok $id, 'found id of the ticket';
my $ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, $user_b->id, 'correct owner';
}
my $agent_b = RT::Test::Web->new;
ok $agent_b->login('user_b', 'password'), 'logged in as user B';
diag "user A can not change owner after create";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
# try the following group of tests twice with different agents(logins)
my $test_cb = sub {
my $agent = shift;
$agent->get("/Ticket/Modify.html?id=$id");
my $form = $agent->form_name('TicketModify');
is $form->value('Owner'), $user_b->id, 'correct owner selected';
$agent->select('Owner', RT->Nobody->id);
$agent->submit;
$agent->content_contains(
'Permission Denied',
'no way to change owner after create if you have no rights'
);
my $ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, $user_b->id, 'correct owner';
};
$test_cb->($agent_a);
diag "even owner(user B) can not change owner";
$test_cb->($agent_b);
}
diag "on reply correct owner is selected";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
$agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
my $form = $agent_a->form_name('TicketUpdate');
is $form->value('Owner'), '', 'empty value selected';
$agent_a->submit;
$ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, $user_b->id, 'correct owner';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
diag "Couldn't take without coresponding right";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link';
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link as well';
}
diag "Couldn't steal without coresponding right";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link';
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link as well';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket TakeTicket)] },
), 'set rights');
diag "TakeTicket require OwnTicket to work";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link';
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link as well';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
diag "TakeTicket+OwnTicket work";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link';
$agent_a->follow_link_ok({text => 'Take'}, 'Ticket -> Take');
$ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, $user_a->id, 'correct owner';
}
diag "TakeTicket+OwnTicket don't work when owner is not nobody";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link';
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link too';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket StealTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
diag "StealTicket require OwnTicket to work";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link';
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link too';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket StealTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
diag "StealTicket+OwnTicket work";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'but no Take link';
$agent_a->follow_link_ok({text => 'Steal'}, 'Ticket -> Steal');
$ticket = RT::Ticket->new( RT->SystemUser );
$ticket->Load( $id );
ok $ticket->id, 'loaded the ticket';
is $ticket->Owner, $user_a->id, 'correct owner';
}
diag "StealTicket+OwnTicket don't work when owner is nobody";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link';
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link as well (no right)';
}
ok( RT::Test->set_rights(
{ Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket TakeTicket StealTicket)] },
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
), 'set rights');
diag "no Steal link when owner nobody";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Steal' ))[0],
'no Steal link';
ok( ($agent_a->find_all_links( text => 'Take' ))[0],
'but have Take link');
}
diag "no Take link when owner is not nobody";
{
my $ticket = RT::Ticket->new( $user_a );
my ($id, $txn, $msg) = $ticket->Create(
Queue => $queue->id,
Owner => $user_b->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, $user_b->id, 'correct owner';
$agent_a->goto_ticket( $id );
ok !($agent_a->find_all_links( text => 'Take' ))[0],
'no Take link';
ok( ($agent_a->find_all_links( text => 'Steal' ))[0],
'but have Steal link');
}
ok(
RT::Test->set_rights(
{
Principal => $user_a,
Right => [
qw(SeeQueue ShowTicket CreateTicket ReplyToTicket OwnTicket TakeTicket StealTicket)
]
},
{ Principal => $user_b, Right => [qw(SeeQueue ShowTicket OwnTicket)] },
{ Principal => $user_c, Right => [qw(SeeQueue ShowTicket ReassignTicket)] },
),
'set rights'
);
diag
"action is Take if old owner is nobody and new owner is current user in update page";
{
my $ticket = RT::Ticket->new( $user_a );
my ( $id, $txn, $msg ) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #'. $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket( $id );
$agent_a->content_lacks('Taken', 'no Taken');
$agent_a->follow_link_ok({text => 'Reply'}, 'Ticket -> Reply');
$agent_a->submit_form(
form_name => 'TicketUpdate',
fields => { Owner => $user_a->id },
button => 'SubmitTicket',
);
like($agent_a->dom->at('.transaction.people .description')->all_text,
qr/user_a\s*-\s*Taken/, 'got user_a Taken message' );
$agent_b->goto_ticket($id);
like($agent_b->dom->at('.transaction.people .description')->all_text,
qr/user_a\s*-\s*Taken/, 'got user_a Taken message for user b' );
}
diag
"action is Take if old owner is nobody and new owner is current user in basics page";
{
my $ticket = RT::Ticket->new($user_a);
my ( $id, $txn, $msg ) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #' . $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_a->goto_ticket($id);
$agent_a->content_lacks('Taken', 'no Taken');
$agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
$agent_a->submit_form(
form_name => 'TicketModify',
fields => { Owner => $user_a->id },
);
$agent_a->content_contains( 'Owner changed from Nobody to user_a',
'got set message in Basics' );
$agent_a->goto_ticket($id);
like($agent_a->dom->at('.transaction.people .description')->all_text,
qr/user_a\s*-\s*Taken/, 'got user_a Taken message' );
$agent_b->goto_ticket($id);
like($agent_b->dom->at('.transaction.people .description')->all_text,
qr/user_a\s*-\s*Taken/, 'got user_a Taken message for user b' );
}
my $agent_c = RT::Test::Web->new;
ok $agent_c->login('user_c', 'password'), 'logged in as user C';
diag "user can assign ticket to new owner with ReassignTicket right";
{
my $ticket = RT::Ticket->new($user_a);
my ( $id, $txn, $msg ) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #' . $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_c->goto_ticket($id);
ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
$agent_a->goto_ticket($id);
$agent_a->content_lacks('Taken', 'no Taken');
$agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
$agent_a->submit_form(
form_name => 'TicketModify',
fields => { Owner => $user_a->id },
);
$agent_a->content_contains( 'Owner changed from Nobody to user_a',
'got set message in Basics' );
$agent_a->goto_ticket($id);
like($agent_a->dom->at('.transaction.people .description')->all_text,
qr{user_a\s*-\s*Taken}, 'got user_a Taken message' );
$agent_c->goto_ticket($id);
ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
$agent_c->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
my $form = $agent_c->form_name('TicketModify');
is $form->value('Owner'), $user_a->id, 'correct owner selected';
ok grep($_ == $user_b->id, $form->find_input('Owner')->possible_values),
'user B is listed as potential owner';
$agent_c->select('Owner', $user_b->id);
$agent_c->submit;
$agent_c->content_contains( 'Owner changed from user_a to user_b',
'got set message in Basics' );
$agent_c->goto_ticket($id);
$agent_c->content_like( qr{Owner forcibly changed}, 'got owner forcibly changed message' );
ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
}
ok(
RT::Test->add_rights(
{ Principal => $user_c, Right => [qw(OwnTicket)] },
),
'add rights'
);
diag "user can take/steal ticket with ReassignTicket+OwnTicket right";
{
my $ticket = RT::Ticket->new($user_a);
my ( $id, $txn, $msg ) = $ticket->Create(
Queue => $queue->id,
Subject => 'test',
);
ok $id, 'created a ticket #' . $id or diag "error: $msg";
is $ticket->Owner, RT->Nobody->id, 'correct owner';
$agent_c->goto_ticket($id);
ok( ($agent_c->find_all_links( text => 'Take' ))[0], 'has Take link' );
ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
$agent_a->goto_ticket($id);
$agent_a->content_lacks('Taken', 'no Taken');
$agent_a->follow_link_ok( { text => 'Basics' }, 'Ticket -> Basics' );
$agent_a->submit_form(
form_name => 'TicketModify',
fields => { Owner => $user_a->id },
);
$agent_a->content_contains( 'Owner changed from Nobody to user_a',
'got set message in Basics' );
$agent_a->goto_ticket($id);
like($agent_a->dom->at('.transaction.people .description')->all_text,
qr{user_a\s*-\s*Taken}, 'got user_a Taken message' );
$agent_c->goto_ticket($id);
ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
ok( ($agent_c->find_all_links( text => 'Steal' ))[0], 'has Steal link' );
$agent_c->follow_link_ok( { text => 'Steal' }, 'Ticket -> Steal' );
$agent_c->content_contains( 'Owner changed from user_a to user_c', 'steal message' );
ok !($agent_c->find_all_links( text => 'Take' ))[0], 'no Take link';
ok !($agent_c->find_all_links( text => 'Steal' ))[0], 'no Steal link';
}
undef $agent_a;
undef $agent_b;
undef $agent_c;
done_testing;
|