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 is $scrip->Queue, $qa->Id, 'queue is A';
64 ok +($scrip->SetName('Testing ModifyScrips'));
66 set_fails( Queue => $scrip => $qb );
67 set_fails( Queue => $scrip => 0 );
68 set_fails( Queue => $scrip => undef );
69 set_fails( Queue => $scrip => '' );
71 RT::Test->add_rights( Principal => $user, Right => 'ModifyScrips', Object => $qb );
73 set_ok( Queue => $scrip => $qb );
74 set_fails( Queue => $scrip => 0 );
75 set_fails( Queue => $scrip => undef );
76 set_fails( Queue => $scrip => '' );
78 RT::Test->add_rights( Principal => $user, Right => 'ModifyScrips' );
80 set_ok( Queue => $scrip => 0 );
82 set_fails( Template => $scrip => 2 );
84 RT::Test->add_rights( Principal => $user, Right => 'ShowTemplate' );
86 set_ok( Template => $scrip => 2 );
87 is $scrip->TemplateObj->Name, 'Autoreply', 'template name is right';
90 diag "ModifyTemplate";
93 { Principal => $user, Right => 'ShowTemplate' },
94 { Principal => $user, Right => 'ModifyTemplate', Object => $qa },
97 my $template = RT::Template->new( RT->SystemUser );
98 my ($id, $msg) = $template->Create(
102 Content => "\n\nThis is a test template.\n",
106 $template = RT::Template->new( $cu );
107 $template->Load( $id );
108 ok $template->id, "loaded template as test user";
109 is $template->Queue, $qa->Id, 'queue is A';
111 ok +($template->SetName('Testing ModifyTemplate'));
113 set_fails( Queue => $template => $qb );
114 set_fails( Queue => $template => 0 );
116 RT::Test->add_rights( Principal => $user, Right => 'ModifyTemplate', Object => $qb );
118 set_ok( Queue => $template => $qb );
119 set_fails( Queue => $template => 0 );
121 RT::Test->add_rights( Principal => $user, Right => 'ModifyTemplate' );
123 set_ok( Queue => $template => 0 );