summaryrefslogtreecommitdiff
path: root/rt/etc/upgrade/2.1.71
blob: cb89a3ac3811017ce247c52a61926c9c69d65e78 (plain)
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
@Queues = ( {
        Name        => '___Approvals',
    Description => 'A system-internal queue for the approvals system',
        Disabled    => 2,
        }
);





# {{{ Templates
@Templates = (
    {
        Queue       => '___Approvals',
        Name        => "New Pending Approval", # loc
        Description => "Notify Owners and AdminCcs of new items pending their approval", # loc
	Content     => 'Subject: New Pending Approval: {$Ticket->Subject}

Greetings,

There is a new item pending your approval: "{$Ticket->Subject()}", 
a summary of which appears below.

Please visit {$RT::WebURL}Approvals/Display.html?id={$Ticket->id}
to approve or reject this ticket, or {$RT::WebURL}Approvals/ to
batch-process all your pending approvals.

-------------------------------------------------------------------------
{$Transaction->Content()}
'
    },
);

# }}}

1;

@ScripActions = (
     { Name => 'Open Tickets',
       Description => 'Open tickets on correspondence',
        ExecModule => 'AutoOpen' },

);

 @Scrips = (
        { ScripCondition => 'On Correspond',
          ScripAction => 'Open Tickets',
          Template => 'Blank',
          Queue => '0'
        }, 
    {  ScripCondition => 'On Create',
       ScripAction    => 'AutoReply To Requestors',
       Template       => 'AutoReply' },
    {  ScripCondition => 'On Create',
       ScripAction    => 'Notify AdminCcs',
       Template       => 'Transaction' },
    {  ScripCondition => 'On Correspond',
       ScripAction    => 'Notify AdminCcs',
       Template       => 'Admin Correspondence' },
    {  ScripCondition => 'On Correspond',
       ScripAction    => 'Notify Requestors And Ccs',
       Template       => 'Correspondence' },
    {  ScripCondition => 'On Correspond',
       ScripAction    => 'Notify Other Recipients',
       Template       => 'Correspondence' },
    {  ScripCondition => 'On Comment',
       ScripAction    => 'Notify AdminCcs As Comment',
       Template       => 'Admin Comment' },
    {  ScripCondition => 'On Comment',
       ScripAction    => 'Notify Other Recipients As Comment',
       Template       => 'Correspondence' },
    {  ScripCondition => 'On Resolve',
       ScripAction    => 'Notify Requestors',
       Template       => 'Resolved' },


    {
        Description    => "When an approval ticket is created, notify the Owner and AdminCc of the item awaiting their approval", # loc
        Queue          => '___Approvals',
        ScripCondition => 'On Create',
        ScripAction    => 'Notify AdminCcs',
        Template       => 'New Pending Approval'
    },
    {
        Description	       => "If an approval is rejected, reject the original and delete pending approvals",	# loc
        Queue                  => '___Approvals',
        ScripCondition         => 'On Status Change',
        ScripAction            => 'User Defined',
        CustomCommitCode       => q[
# ------------------------------------------------------------------- #
return(1) unless ( lc($self->TransactionObj->NewValue) eq "rejected" or
	           lc($self->TransactionObj->NewValue) eq "deleted" );

my $links = $self->TicketObj->DependedOnBy;
foreach my $link (@{ $links->ItemsArrayRef }) {
    my $obj = $link->BaseObj;
    if ($obj->QueueObj->IsActiveStatus($obj->Status)) {
	if ($obj->Type eq 'ticket') {
	    $obj->Correspond(
		Content	=> $self->loc("Your request was rejected."),
	    );
	    $obj->SetStatus(
		Status	=> 'rejected',
		Force	=> 1,
	    );
	}
	else {
	    $obj->SetStatus(
		Status	=> 'deleted',
		Force	=> 1,
	    );
	}
    }
}

$links = $self->TicketObj->DependsOn;
foreach my $link (@{ $links->ItemsArrayRef }) {
    my $obj = $link->TargetObj;
    if ($obj->QueueObj->IsActiveStatus($obj->Status)) {
	$obj->SetStatus(
	    Status	=> 'deleted',
	    Force	=> 1,
	);
    }
}

return 1;
# ------------------------------------------------------------------- #
	],
        CustomPrepareCode => '1',
        Template          => 'Admin Comment',
    },
    {
        Description	  => "When a ticket has been approved by any approver, add correspondence to the original ticket", # loc
        Queue             => '___Approvals',
        ScripCondition    => 'On Resolve',
        ScripAction       => 'User Defined',
        CustomPrepareCode => 'return(1);',
        CustomCommitCode  => q[
# ------------------------------------------------------------------- #
return(1) unless ($self->TicketObj->Type eq 'approval');

foreach my $obj ($self->TicketObj->AllDependedOnBy( Type => 'ticket' )) {
    $obj->Correspond(
	Content => $self->loc( "Your request has been approved by [_1]. Other approvals may still be pending.", # loc
	    $self->TransactionObj->CreatorObj->Name,
	) . "\n" . $self->loc( "Approver's notes: [_1]", # loc
	    $self->TicketObj->Transactions->Last->Content,
	),
	_reopen	=> 0,
    );
}

return 1;
# ------------------------------------------------------------------- #
	],
	Template => 'Admin Comment'
    },
    {
        Description	  => "When a ticket has been approved by all approvers, add correspondence to the original ticket", # loc
        Queue             => '___Approvals',
        ScripCondition    => 'On Resolve',
        ScripAction       => 'User Defined',
        CustomPrepareCode => 'return(1);',
        CustomCommitCode  => q[
# ------------------------------------------------------------------- #
# Find all the tickets that depend on this (that this is approving)

my $Ticket = $self->TicketObj;
my @TOP    = $Ticket->AllDependedOnBy( Type => 'ticket' );
my $links  = $Ticket->DependedOnBy;

while (my $link = $links->Next) {
    my $obj = $link->BaseObj;
    next if ($obj->HasUnresolvedDependencies( Type => 'approval' ));

    if ($obj->Type eq 'ticket') {
	$obj->Correspond(
	    Content	=> $self->loc("Your request has been approved."),
	    _reopen	=> 0,
	);
    }
    elsif ($obj->Type eq 'code') {
	my $code = $obj->Transactions->First->Content;
	my $rv;

	foreach my $TOP (@TOP) {
	    local $@;
	    $rv++ if eval $code;
	    $RT::Logger->error("Cannot eval code: $@") if $@;
	}

	if ($rv or !@TOP) {
	    $obj->SetStatus( Status	=> 'resolved', Force	=> 1,);
	}
	else {
	    $obj->SetStatus( Status	=> 'rejected', Force	=> 1,);
	}
    }
}

return 1;
# ------------------------------------------------------------------- #
	],
        Template    => 'Admin Comment',
    },
);

# }}}