import rt 3.8.11
[freeside.git] / rt / etc / upgrade / 2.1.71
1 @Queues = ( {
2         Name        => '___Approvals',
3     Description => 'A system-internal queue for the approvals system',
4         Disabled    => 2,
5         }
6 );
7
8
9
10
11
12 # {{{ Templates
13 @Templates = (
14     {
15         Queue       => '___Approvals',
16         Name        => "New Pending Approval", # loc
17         Description => "Notify Owners and AdminCcs of new items pending their approval", # loc
18         Content     => 'Subject: New Pending Approval: {$Ticket->Subject}
19
20 Greetings,
21
22 There is a new item pending your approval: "{$Ticket->Subject()}", 
23 a summary of which appears below.
24
25 Please visit {$RT::WebURL}Approvals/Display.html?id={$Ticket->id}
26 to approve or reject this ticket, or {$RT::WebURL}Approvals/ to
27 batch-process all your pending approvals.
28
29 -------------------------------------------------------------------------
30 {$Transaction->Content()}
31 '
32     },
33 );
34
35 # }}}
36
37 1;
38
39 @ScripActions = (
40      { Name => 'Open Tickets',
41        Description => 'Open tickets on correspondence',
42         ExecModule => 'AutoOpen' },
43
44 );
45
46  @Scrips = (
47         { ScripCondition => 'On Correspond',
48           ScripAction => 'Open Tickets',
49           Template => 'Blank',
50           Queue => '0'
51         }, 
52     {  ScripCondition => 'On Create',
53        ScripAction    => 'AutoReply To Requestors',
54        Template       => 'AutoReply' },
55     {  ScripCondition => 'On Create',
56        ScripAction    => 'Notify AdminCcs',
57        Template       => 'Transaction' },
58     {  ScripCondition => 'On Correspond',
59        ScripAction    => 'Notify AdminCcs',
60        Template       => 'Admin Correspondence' },
61     {  ScripCondition => 'On Correspond',
62        ScripAction    => 'Notify Requestors And Ccs',
63        Template       => 'Correspondence' },
64     {  ScripCondition => 'On Correspond',
65        ScripAction    => 'Notify Other Recipients',
66        Template       => 'Correspondence' },
67     {  ScripCondition => 'On Comment',
68        ScripAction    => 'Notify AdminCcs As Comment',
69        Template       => 'Admin Comment' },
70     {  ScripCondition => 'On Comment',
71        ScripAction    => 'Notify Other Recipients As Comment',
72        Template       => 'Correspondence' },
73     {  ScripCondition => 'On Resolve',
74        ScripAction    => 'Notify Requestors',
75        Template       => 'Resolved' },
76
77
78     {
79         Description    => "When an approval ticket is created, notify the Owner and AdminCc of the item awaiting their approval", # loc
80         Queue          => '___Approvals',
81         ScripCondition => 'On Create',
82         ScripAction    => 'Notify AdminCcs',
83         Template       => 'New Pending Approval'
84     },
85     {
86         Description            => "If an approval is rejected, reject the original and delete pending approvals",       # loc
87         Queue                  => '___Approvals',
88         ScripCondition         => 'On Status Change',
89         ScripAction            => 'User Defined',
90         CustomCommitCode       => q[
91 # ------------------------------------------------------------------- #
92 return(1) unless ( lc($self->TransactionObj->NewValue) eq "rejected" or
93                    lc($self->TransactionObj->NewValue) eq "deleted" );
94
95 my $links = $self->TicketObj->DependedOnBy;
96 foreach my $link (@{ $links->ItemsArrayRef }) {
97     my $obj = $link->BaseObj;
98     if ($obj->QueueObj->IsActiveStatus($obj->Status)) {
99         if ($obj->Type eq 'ticket') {
100             $obj->Correspond(
101                 Content => $self->loc("Your request was rejected."),
102             );
103             $obj->SetStatus(
104                 Status  => 'rejected',
105                 Force   => 1,
106             );
107         }
108         else {
109             $obj->SetStatus(
110                 Status  => 'deleted',
111                 Force   => 1,
112             );
113         }
114     }
115 }
116
117 $links = $self->TicketObj->DependsOn;
118 foreach my $link (@{ $links->ItemsArrayRef }) {
119     my $obj = $link->TargetObj;
120     if ($obj->QueueObj->IsActiveStatus($obj->Status)) {
121         $obj->SetStatus(
122             Status      => 'deleted',
123             Force       => 1,
124         );
125     }
126 }
127
128 return 1;
129 # ------------------------------------------------------------------- #
130         ],
131         CustomPrepareCode => '1',
132         Template          => 'Admin Comment',
133     },
134     {
135         Description       => "When a ticket has been approved by any approver, add correspondence to the original ticket", # loc
136         Queue             => '___Approvals',
137         ScripCondition    => 'On Resolve',
138         ScripAction       => 'User Defined',
139         CustomPrepareCode => 'return(1);',
140         CustomCommitCode  => q[
141 # ------------------------------------------------------------------- #
142 return(1) unless ($self->TicketObj->Type eq 'approval');
143
144 foreach my $obj ($self->TicketObj->AllDependedOnBy( Type => 'ticket' )) {
145     $obj->Correspond(
146         Content => $self->loc( "Your request has been approved by [_1]. Other approvals may still be pending.", # loc
147             $self->TransactionObj->CreatorObj->Name,
148         ) . "\n" . $self->loc( "Approver's notes: [_1]", # loc
149             $self->TicketObj->Transactions->Last->Content,
150         ),
151         _reopen => 0,
152     );
153 }
154
155 return 1;
156 # ------------------------------------------------------------------- #
157         ],
158         Template => 'Admin Comment'
159     },
160     {
161         Description       => "When a ticket has been approved by all approvers, add correspondence to the original ticket", # loc
162         Queue             => '___Approvals',
163         ScripCondition    => 'On Resolve',
164         ScripAction       => 'User Defined',
165         CustomPrepareCode => 'return(1);',
166         CustomCommitCode  => q[
167 # ------------------------------------------------------------------- #
168 # Find all the tickets that depend on this (that this is approving)
169
170 my $Ticket = $self->TicketObj;
171 my @TOP    = $Ticket->AllDependedOnBy( Type => 'ticket' );
172 my $links  = $Ticket->DependedOnBy;
173
174 while (my $link = $links->Next) {
175     my $obj = $link->BaseObj;
176     next if ($obj->HasUnresolvedDependencies( Type => 'approval' ));
177
178     if ($obj->Type eq 'ticket') {
179         $obj->Correspond(
180             Content     => $self->loc("Your request has been approved."),
181             _reopen     => 0,
182         );
183     }
184     elsif ($obj->Type eq 'code') {
185         my $code = $obj->Transactions->First->Content;
186         my $rv;
187
188         foreach my $TOP (@TOP) {
189             local $@;
190             $rv++ if eval $code;
191             $RT::Logger->error("Cannot eval code: $@") if $@;
192         }
193
194         if ($rv or !@TOP) {
195             $obj->SetStatus( Status     => 'resolved', Force    => 1,);
196         }
197         else {
198             $obj->SetStatus( Status     => 'rejected', Force    => 1,);
199         }
200     }
201 }
202
203 return 1;
204 # ------------------------------------------------------------------- #
205         ],
206         Template    => 'Admin Comment',
207     },
208 );
209
210 # }}}
211