4 use RT::Test tests => undef;
9 my $to = ref $_[0] ? +shift->Id : shift;
10 my $from = $obj->$col;
13 my ($ok, $msg) = $obj->$meth($to);
14 ok !$ok, "$meth denied: $msg";
15 is $obj->$col, $from, "$col left alone";
21 my $to = ref $_[0] ? +shift->Id : shift;
22 my $from = $obj->$col;
25 my ($ok, $msg) = $obj->$meth($to);
26 ok $ok, "$meth allowed: $msg";
27 is $obj->$col, $to, "$col updated";
30 my $qa = RT::Test->load_or_create_queue( Name => 'Queue A' );
31 my $qb = RT::Test->load_or_create_queue( Name => 'Queue B' );
32 ok $qa->id, "created Queue A";
33 ok $qb->id, "created Queue B";
35 my $user = RT::Test->load_or_create_user( Name => 'testuser' );
36 my $cu = RT::CurrentUser->new( $user );
37 ok $user->id, "created testuser";
41 my $scrip = RT::Scrip->new( RT->SystemUser );
42 my ($scrip_id, $msg) = $scrip->Create(
43 Description => 'Testing',
45 ScripCondition => 'User Defined',
46 ScripAction => 'User Defined',
48 CustomIsApplicableCode => 'if ($self->TicketObj->Subject =~ /fire/) { return (1);} else { return(0)}',
49 CustomPrepareCode => '1;',
50 CustomCommitCode => 'warn "scrip fired!";',
55 { Principal => $user, Right => 'ShowScrips' },
56 { Principal => $user, Right => 'ModifyScrips', Object => $qa },
59 $scrip = RT::Scrip->new( $cu );
60 $scrip->Load( $scrip_id );
61 ok $scrip->id, "loaded scrip as test user";
62 ok $scrip->IsAdded( $qa->Id ), 'queue is A';
64 ok +($scrip->SetName('Testing ModifyScrips'));
66 for my $value ($qb->id, 0, undef, '') {
67 my ($ok, $why) = $scrip->AddToObject( $value );
68 my $disp = (defined($value) ? "'$value'" : "undef");
69 ok( !$ok, "Correctly not added to $disp: $why" );
72 RT::Test->add_rights( Principal => $user, Right => 'ModifyScrips', Object => $qb );
74 for my $value ($qb->id, 0, undef, '') {
75 my ($ok, $why) = $scrip->AddToObject( $value );
76 my $disp = (defined($value) ? "'$value'" : "undef");
78 ok( $ok, "Correctly added to $disp: $why" );
80 ok( !$ok, "Correctly not added to $disp: $why" );
84 RT::Test->add_rights( Principal => $user, Right => 'ModifyScrips' );
86 my ($ok, $why) = $scrip->AddToObject( 0 );
87 ok( $ok, "Correctly added globally: $why" );
89 set_fails( Template => $scrip => "Autoreply" );
91 RT::Test->add_rights( Principal => $user, Right => 'ShowTemplate' );
93 set_ok( Template => $scrip => "Autoreply" );
94 is $scrip->Template, 'Autoreply', 'template name is right';
97 diag "ModifyTemplate";
100 { Principal => $user, Right => 'ShowTemplate' },
101 { Principal => $user, Right => 'ModifyTemplate', Object => $qa },
104 my $template = RT::Template->new( RT->SystemUser );
105 my ($id, $msg) = $template->Create(
109 Content => "\n\nThis is a test template.\n",
113 $template = RT::Template->new( $cu );
114 $template->Load( $id );
115 ok $template->id, "loaded template as test user";
116 is $template->Queue, $qa->Id, 'queue is A';
118 ok +($template->SetName('Testing ModifyTemplate'));
120 set_fails( Queue => $template => $qb );
121 set_fails( Queue => $template => 0 );
123 RT::Test->add_rights( Principal => $user, Right => 'ModifyTemplate', Object => $qb );
125 set_fails( Queue => $template => $qb );
126 set_fails( Queue => $template => 0 );
128 RT::Test->add_rights( Principal => $user, Right => 'ModifyTemplate' );
130 set_fails( Queue => $template => 0 );