Difference between revisions of "Conditional Reopen Reject"

From Request Tracker Wiki
Jump to navigation Jump to search
(Added author reference)
(An improved version inspired by the original work. The functionality remains the same, but the code is refactored into two scripts. This avoids making dubious changes in the custom condition, and uses standard RT actions instead.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Contributed by [http://wiki.bestpractical.com/view/Cris Cris]
==Introduction==
==Introduction==
Conditional Reopen Reject lets you decide that, after a set amount of time since resolution, users won't be able to reopen a ticket.
Conditional Reopen Reject lets you decide that, after a set amount of time since resolution, users won't be able to reopen a ticket.


It works with a scrip and a template, as explained below.
It works with two scrips and a template, as explained below.


==Setting up the scrip==
Keep in mind that this is configured so that tickets become non-reopenable after a week since resolution. If you want a different timeframe, just change the ''$Days'' variable.


We have had this customization installed for so long that I do not remember the default configuration of RT. I believe a script called "On Correspond Open Tickets" already exists in a default installation.


You have to change it (or create it if it doesn't exist) the following way.
==The default reopen script==


Keep in mind that this is configured so that tickets become non-reopenable after a week since resolution. If you want a different timeframe, just change the ''$Days'' variable.
There's a default script for opening inactive tickets unconditionally. It's called ''On Correspond Open Inactive Tickets''. You have to disable it first (or you may choose to repurpose it for one of the scripts below.
 
 
==Setting up the scrip for reopening recent tickets==


'''Description:''' On Correspond Open Tickets
'''Description:''' On Correspond ( < week ) Open Inactive Tickets


'''Condition:''' User defined
'''Condition:''' User defined


'''Action:''' Autoreply to requestors
'''Action:''' Open Inactive Tickets


'''Template:''' Conditional Reopen Reject
'''Template:''' Blank


'''Applies to:''' Global
'''Applies to:''' Global


'''Custom condition:'''
'''Custom condition:'''
  my $Days = 60*60*24*7; # 7 days
<pre>
# This condition is true only for mails coming in within a week of the ticket being closed.
# Script "On Correspond ( > week ) Open Inactive Tickets" is strongly related.
 
# my $Days = 60; # debugging
my $Days = 60*60*24*7; # 7 days
 
my $TransactionObj = $self->TransactionObj;
my $TicketObj = $self->TicketObj;
my $QueueObj = $TicketObj->QueueObj;
   
   
return 0 unless $TransactionObj->Type eq 'Correspond';
   
   
my $TransactionObj = $self->TransactionObj;
 
if ( $TransactionObj->IsInbound &&
    $QueueObj->IsInactiveStatus( $TicketObj->Status ) &&
    time() - $TicketObj->ResolvedObj->Unix < $Days ) {
   
   
  my $TicketObj = $self->TicketObj;
  return 1; # reopen the ticket
}
 
return 0; # Don't reopen the ticket. Another script should send the user a mail that the ticket cannot be reopened.
</pre>
 
'''Custom action preparation code:''' empty
 
'''Custom action commit code:''' empty
 
 
 
==Setting up the scrip for rejecting reopening of old tickets==
 
'''Description:''' On Correspond ( > week ) Open Inactive Tickets
 
'''Condition:''' User defined
 
'''Action:''' Autoreply To Requestors
 
'''Template:''' Conditional Reopen Reject
 
'''Applies to:''' Global
 
'''Custom condition:'''
<pre>
# Inspired by this: https://rt-wiki.bestpractical.com/wiki/Conditional_Reopen_Reject
# This condition is true only for mails coming in after the ticket has been closed for a week.
# Script "On Correspond ( < week ) Open Inactive Tickets" is strongly related to this.
 
# my $Days = 60; # debugging
my $Days = 60*60*24*7; # 7 days
 
my $TransactionObj = $self->TransactionObj;
my $TicketObj = $self->TicketObj;
my $QueueObj = $TicketObj->QueueObj;
   
   
my $QueueObj = $TicketObj->QueueObj;
return 0 unless $TransactionObj->Type eq 'Correspond';
   
   
my $QueueName = $QueueObj->Name;
 
if ( $TransactionObj->IsInbound &&
    $QueueObj->IsInactiveStatus( $TicketObj->Status ) &&
    time() - $TicketObj->ResolvedObj->Unix > $Days ) {
   
   
  return 1;  # Send a mail saying that this ticket cannot be reopened.
return 0 unless $TransactionObj->Type eq 'Correspond';
}
 
return 0; # Don't send the mail, another script may reopen the ticket.
# begin debug section #############
</pre>
 
my $dr = $TicketObj->ResolvedObj->Unix;
my $tt = time() - $TicketObj->ResolvedObj->Unix;
$RT::Logger->info( ">  -- Scrip 1 --\n" );
$RT::Logger->info( ">  DataRisoluzione: $dr \n" );
$RT::Logger->info( ">  TempoTrascorso: $tt \n" );
  # InBound should be true only if the email comes from the original requestor
if ( $TransactionObj->IsInbound ) {$RT::Logger->info(">  Inbound\n");}
if ( $QueueObj->IsInactiveStatus( $TicketObj->Status ) ) {$RT::Logger->info(">  Inactive\n");}
# end debug section #############
if ( $TransactionObj->IsInbound &&
      $QueueObj->IsInactiveStatus( $TicketObj->Status ) &&
      time() - $TicketObj->ResolvedObj->Unix > $Days ) {
  return 1; # send mail template
} else {
  $TicketObj->SetStatus( 'open' );
  return 0; # don't send mail template
}
'''Custom action preparation code:''' empty
'''Custom action preparation code:''' empty


'''Custom action commit code:''' empty
'''Custom action commit code:''' empty


==Setting up the template==
==Setting up the template==
Line 93: Line 110:


'''Content:'''
'''Content:'''
Subject: WARNING - TICKET REJECTED: {$Ticket->Subject}
<pre>
Subject: WARNING - TICKET REJECTED: {$Ticket->Subject}
Ticket #{$Ticket->id()} has been closed for more than 7 days: it is not possible to reopen it.
Please submit a new ticket instead.
Thank you
RT for {$Ticket->QueueObj->SubjectTag || $rtname}
 
 


Ticket #{$Ticket->id()} has been closed for more than 7 days: it is not possible to reopen it.


Please submit a new ticket instead.


OK, that's all.


I hope you enjoy it!
Thank you,
{$Ticket->QueueObj->CorrespondAddress()}
</pre>

Latest revision as of 01:55, 14 June 2023

Introduction

Conditional Reopen Reject lets you decide that, after a set amount of time since resolution, users won't be able to reopen a ticket.

It works with two scrips and a template, as explained below.

Keep in mind that this is configured so that tickets become non-reopenable after a week since resolution. If you want a different timeframe, just change the $Days variable.


The default reopen script

There's a default script for opening inactive tickets unconditionally. It's called On Correspond Open Inactive Tickets. You have to disable it first (or you may choose to repurpose it for one of the scripts below.


Setting up the scrip for reopening recent tickets

Description: On Correspond ( < week ) Open Inactive Tickets

Condition: User defined

Action: Open Inactive Tickets

Template: Blank

Applies to: Global

Custom condition:

# This condition is true only for mails coming in within a week of the ticket being closed.
# Script "On Correspond  ( > week ) Open Inactive Tickets" is strongly related.

# my $Days = 60; # debugging
my $Days = 60*60*24*7; # 7 days

my $TransactionObj = $self->TransactionObj;
my $TicketObj = $self->TicketObj;
my $QueueObj = $TicketObj->QueueObj;
 
return 0 unless $TransactionObj->Type eq 'Correspond';
 

if ( $TransactionObj->IsInbound && 
    $QueueObj->IsInactiveStatus( $TicketObj->Status ) &&
    time() - $TicketObj->ResolvedObj->Unix < $Days ) {
 
  return 1; # reopen the ticket
}

return 0;  # Don't reopen the ticket. Another script should send the user a mail that the ticket cannot be reopened.

Custom action preparation code: empty

Custom action commit code: empty


Setting up the scrip for rejecting reopening of old tickets

Description: On Correspond ( > week ) Open Inactive Tickets

Condition: User defined

Action: Autoreply To Requestors

Template: Conditional Reopen Reject

Applies to: Global

Custom condition:

# Inspired by this: https://rt-wiki.bestpractical.com/wiki/Conditional_Reopen_Reject
# This condition is true only for mails coming in after the ticket has been closed for a week.
# Script "On Correspond ( < week ) Open Inactive Tickets" is strongly related to this.

# my $Days = 60; # debugging
my $Days = 60*60*24*7; # 7 days

my $TransactionObj = $self->TransactionObj;
my $TicketObj = $self->TicketObj;
my $QueueObj = $TicketObj->QueueObj;
 
return 0 unless $TransactionObj->Type eq 'Correspond';
 

if ( $TransactionObj->IsInbound && 
    $QueueObj->IsInactiveStatus( $TicketObj->Status ) &&
    time() - $TicketObj->ResolvedObj->Unix > $Days ) {
 
  return 1;  # Send a mail saying that this ticket cannot be reopened.
}

return 0; # Don't send the mail, another script may reopen the ticket.

Custom action preparation code: empty

Custom action commit code: empty


Setting up the template

This is how the template should be configured:

Name: Conditional Reopen Reject

Description: Reject reopen if ticket has been closed for more than X days

Type: Perl

Content:

Subject: WARNING - TICKET REJECTED: {$Ticket->Subject}

Ticket #{$Ticket->id()} has been closed for more than 7 days: it is not possible to reopen it.

Please submit a new ticket instead.


Thank you,
{$Ticket->QueueObj->CorrespondAddress()}