]> git.uio.no Git - usit-rt.git/blame - lib/RT/Action/AutoOpen.pm
Merge branch 'master' of git.uio.no:usit-rt
[usit-rt.git] / lib / RT / Action / AutoOpen.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
320f0092 5# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
13# This work is made available to you under the terms of Version 2 of
14# the GNU General Public License. A copy of that license should have
15# been provided with this software, but in any event can be snarfed
16# from www.gnu.org.
17#
18# This work is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301 or visit their web page on the internet at
27# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
32# (The following paragraph is not intended to limit the rights granted
33# to you to modify and distribute this software under the terms of
34# the GNU General Public License and is only of importance to you if
35# you choose to contribute your changes and enhancements to the
36# community by submitting them to Best Practical Solutions, LLC.)
37#
38# By intentionally submitting any modifications, corrections or
39# derivatives to this work, or any other work intended for use with
40# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41# you are the copyright holder for those contributions and you grant
42# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43# royalty-free, perpetual, license to use, copy, create derivative
44# works based on those contributions, and sublicense and distribute
45# those contributions and any derivatives thereof.
46#
47# END BPS TAGGED BLOCK }}}
48
84fb5b46
MKG
49package RT::Action::AutoOpen;
50
51use strict;
52use warnings;
53use base qw(RT::Action);
54
55=head1 DESCRIPTION
56
57This action automatically moves a ticket to an active status.
58
59Status is not changed if there is no active statuses in the lifecycle.
60
61Status is not changed if the current status is first active for ticket's status
62lifecycle. For example if ticket's status is 'processing' and active statuses are
63'processing', 'on hold' and 'waiting' then status is not changed, but for ticket
64with status 'on hold' other rules are checked.
65
66Status is not changed if it's in the list of C<initial> statuses for the
67current scheme and creator of the current transaction
68is one of the ticket's requestors.
69
70Status is not changed if message's head has field C<RT-Control> with C<no-autoopen>
71substring.
72
73Status is set to the first possible active status. If the ticket's
74status is C<Stalled> then RT finds all possible transitions from C<Stalled>
75status and selects first one that results in the ticket having an
76active status.
77
78=cut
79
80sub Prepare {
81 my $self = shift;
82
83 my $ticket = $self->TicketObj;
84 my $next = $ticket->FirstActiveStatus;
85 return 1 unless defined $next;
86
87 # no change if the ticket is in initial status and the message is a mail
88 # from a requestor
af59614d 89 return 1 if $ticket->LifecycleObj->IsInitial($ticket->Status)
84fb5b46
MKG
90 && $self->TransactionObj->IsInbound;
91
92 if ( my $msg = $self->TransactionObj->Message->First ) {
93 return 1 if ($msg->GetHeader('RT-Control') || '') =~ /\bno-autoopen\b/i;
94 }
95
96 $self->{'set_status_to'} = $next;
97
98 return 1;
99}
100
101sub Commit {
102 my $self = shift;
103
104 return 1 unless my $new_status = $self->{'set_status_to'};
105
106 my ($val, $msg) = $self->TicketObj->SetStatus( $new_status );
107 unless ( $val ) {
108 $RT::Logger->error( "Couldn't auto-open ticket: ". $msg );
109 return 0;
110 }
111 return 1;
112}
113
114RT::Base->_ImportOverlays();
115
1161;