RT-Extension-RelocateReply
view release on metacpan or search on metacpan
---
abstract: 'relocate missplaced messages to the right ticket'
author:
- 'Fazekas Bálint, Mithrandir kft. fazekas.balint@mithrandir.hu'
build_requires:
ExtUtils::MakeMaker: 6.59
configure_requires:
ExtUtils::MakeMaker: 6.59
distribution_type: module
dynamic_config: 1
generated_by: 'Module::Install version 1.19'
license: gpl_2
version: 1.4
name: RT-Extension-RelocateReply
no_index:
directory:
- html
- inc
requires:
perl: 5.10.1
resources:
license: http://opensource.org/licenses/gpl-license.php
repository: https://github.com/bestpractical/rt-extension-relocatereply
version: '1.00'
x_module_install_rtx_version: '0.40'
x_requires_rt: 4.2.0
x_rt_too_new: 4.6.0
Makefile.PL view on Meta::CPAN
use inc::Module::Install;
RTx 'RT-Extension-RelocateReply';
license 'gpl_2';
repository 'https://github.com/bestpractical/rt-extension-relocatereply';
requires_rt '4.2.0';
rt_too_new '4.6.0';
sign;
WriteAll;
NAME
RT::Extension::RelocateReply - relocate missplaced messages to the right
ticket
DESCRIPTION
This extension for RT gives the ability to those who have the
RelocateReply right to relocate / move messages (comments or
correspondences) from one ticket to another. The relocation action
appears in both ticket's history width the current date. There will be
message at the original place stating the transaction transition.
RT VERSION
Works with RT 4.4.
INSTALLATION
sudo perl Makefile.PL
make
html/Callbacks/RT-Extension-RelocateReply/Elements/ShowTransaction/Default view on Meta::CPAN
<%init>
return if defined $ARGS{'ShowActions'} && ! $ARGS{'ShowActions'};
my $txn_type = $Transaction->Type;
return if ( $txn_type =~ /EmailRecord$/ );
if ( $txn_type =~ /^Relocate/ ) {
my $desc = $$Description;
my @data = split(';', $Transaction->Data);
my $relocate_date = $data[1]||'??';
my $relocated_transaction_date = $data[2]||'??';
my $message_type = $data[3]||'';
foreach my $DATE ( \$relocate_date, \$relocated_transaction_date ) {
if ( $$DATE ne '??' ) {
my $DateObj = RT::Date->new( $session{CurrentUser} );
$DateObj->Set(
Format => 'ISO',
Value => $$DATE,
);
$$DATE = $DateObj->AsString;
$$DATE = $m->interp->apply_escapes( $$DATE, 'h' );
$$DATE =~ s/\s/ /g;
}
}
if ( $Object->id eq $Transaction->OldValue ) {
if ( $message_type eq 'past' ) {
$desc = loc("Transaction #[_1] from this place was relocated to ticket #[_2] at [_3]",
$data[0]||'??' ,$Transaction->NewValue ,$relocate_date );
} else {
$desc = loc("Transaction #[_1] from this ticket was relocated to ticket #[_2]",
$data[0]||'??' ,$Transaction->NewValue );
}
} else {
$desc = loc("Transaction #[_1] ([_2]) from ticket #[_3] was relocated to this ticket",
$data[0]||'??' ,$relocated_transaction_date ,$Transaction->OldValue );
}
$$Description = $desc;
return;
}
return if ( $txn_type !~ /Correspond|Comment$/ );
my $required_right_name = 'RelocateReply';
my $has_right_RelocateReply = RT::ACE->CanonicalizeRightName($required_right_name);
if ( ! defined $has_right_RelocateReply ) {
RT->Logger->error("No right with name [$required_right_name] found!" );
return;
}
if ( $txn_type =~ /Correspond|Comment$/ ) {
RT->Logger->info("TrID: ".$Transaction->id." Object->CurrentUserHasRight ". ($Object->CurrentUserHasRight( $has_right_RelocateReply)||'no' ) );
}
if ( $txn_type =~ /Correspond|Comment$/ && $RelocatePath && $has_right_RelocateReply &&
$Object->CurrentUserHasRight( $has_right_RelocateReply ) ) {
my @actions = @$Actions;
push @actions, {
class => "relocate-link",
title => loc('Relocate'),
path => $RelocatePath
.'?id='. $Object->id
.'&TransactionId='. $Transaction->id
,
};
@$Actions = @actions;
}
</%init>
<%ARGS>
html/Ticket/Relocate.html view on Meta::CPAN
'/Elements/ShowTransactionAttachments',
%ARGS,
Transaction => $Transaction,
AttachmentPath => $AttachmentPath,
Parent => 0
);
</%PERL>
</div>
% $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterContent' );
</div>
<div class="relocate-transaction" style="width:500px;">
<form action="Relocate.html" name="TicketUpdate"
method="post" enctype="multipart/form-data">
<input type="hidden" class="hidden" name="id" value="<%$id%>" /><br />
<input type="hidden" class="hidden" name="TransactionId" value="<% $ARGS{TransactionId}||'' %>" /><br />
<table>
<tr>
<td class="label"><&|/l&>Relocate message to ticket</&>:</td>
<td class="entry"><input name="relocate-to" value="" data-autocomplete="Tickets" data-autocomplete-exclude="" /></td>
</tr>
</table>
<& /Elements/Submit, Label => loc('Relocate Ticket'), Name => 'Submit', id => 'Submit' &>
</form>
</div>
<%ARGS>
html/Ticket/Relocate.html view on Meta::CPAN
Abort(loc('No right with name [[_1]] found!', $required_right_name ));
return;
}
#RT->Logger->error("__3: ". $has_right_RelocateReply);
my $STicket = RT::Ticket->new( $session{'CurrentUser'} );
$STicket->Load( $ARGS{'id'} );
unless ( $STicket ) {
Abort(loc('Source ticket not found'));
}
unless ( $STicket->CurrentUserHasRight( $has_right_RelocateReply ) ) {
Abort(loc('You have no permission to relocate reply from this ticket'));
}
# we need to set AttachmentPath here, because /Elements/ShowHistory didn't get called
my $AttachmentPath = ($ARGS{PathPrefix}||'').'Attachment';
while ( $ARGS{'Submit'} ) {
unless ( $ARGS{'relocate-to'} ) {
push @Actions, loc('Target ticket id is not specified');
last;
}
my $TargetTicket = RT::Ticket->new( $session{'CurrentUser'} );
$TargetTicket->Load( $ARGS{'relocate-to'} );
unless ( $TargetTicket && $TargetTicket->id == $ARGS{'relocate-to'} ) {
push @Actions, loc('Target ticket not found');
last;
}
unless ( $TargetTicket->CurrentUserHasRight( $has_right_RelocateReply ) ) {
push @Actions, loc('You have no permission to relocate reply to target ticket. (#[_1]: [_2])', $TargetTicket->id, $TargetTicket->Subject );
last;
}
$RT::Handle->BeginTransaction();
my $Now = RT::Date->new( $session{CurrentUser} );
$Now->SetToNow();
my $dbh = $RT::Handle->dbh;
##########################
# create a new transaction preserving the original's ObjectType, ObjectId and created field
# oldvalue: original ticket ID, newvalue: new ticket ID, data: old transaction id; date when relocate happens; message place (past/present)
my $query = "INSERT INTO transactions (objecttype, objectid, type, field, oldvalue, newvalue, data, creator, created )
(SELECT objecttype, objectid, ?, ?, objectid, ?, ?, ?, created FROM transactions WHERE id = ?)";
my $sth = $dbh->prepare( $query );
unless (defined $sth) {
$RT::Logger->error( "couldn't prepare query: ". $dbh->errstr );
Abort(loc('There were an error in relocating the requested transaction'));
}
RT->Logger->info("copy values: 'Relocate'.$txn_type, 'Transaction.ObjectId', ".$TargetTicket->id.", $TransactionId;".$Now->ISO.$Transaction->Created.";past, ".$session{'CurrentUser'}->Id.", $TransactionId" );
my $result = $sth->execute( 'Relocate'.$txn_type, 'Transaction.ObjectId', $TargetTicket->id, "$TransactionId;".$Now->ISO.";".$Transaction->Created.";past", $session{'CurrentUser'}->Id, $TransactionId );
if ( ! defined $result) {
$RT::Logger->error( "couldn't execute query: ". $dbh->errstr );
$RT::Handle->Rollback();
Abort(loc('There were an error in relocating the requested transaction'));
}
$RT::Logger->error( "result#1: ". $result );
##########################
# change the original transaction's ObjectId to the target ticket id
$query = "UPDATE Transactions SET ObjectId=? WHERE id=?";
$sth = $dbh->prepare( $query );
$result = $sth->execute( $TargetTicket->id, $TransactionId );
if ( ! defined $result) {
$RT::Logger->error( "couldn't execute query: ". $dbh->errstr );
$RT::Handle->Rollback();
Abort(loc('There were an error in relocating the requested transaction'));
}
$RT::Logger->error( "result#2: ". $result );
##########################
# create a new 'Relocate' transaction in the original (source) ticket to inform about the relocated transaction
$query = "INSERT INTO transactions (objecttype, objectid, type, field, oldvalue, newvalue, data, creator, created )
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
$sth = $dbh->prepare( $query );
unless (defined $sth) {
$RT::Logger->error( "couldn't prepare query: ". $dbh->errstr );
Abort(loc('There were an error in relocating the requested transaction'));
}
$result = $sth->execute( 'RT::Ticket', $STicket->id, 'Relocate'.$txn_type, 'Transaction.ObjectId', $STicket->id, $TargetTicket->id, "$TransactionId;".$Now->ISO.";".$Transaction->Created.";present", $session{'CurrentUser'}->Id, $Now->ISO );
if ( ! defined $result) {
$RT::Logger->error( "couldn't execute query: ". $dbh->errstr );
$RT::Handle->Rollback();
Abort(loc('There were an error in relocating the requested transaction'));
}
$RT::Logger->error( "result#3: ". $result );
##########################
# create a new 'Relocate' transaction in the target (destination) ticket to inform about the relocated transaction
$query = "INSERT INTO transactions (objecttype, objectid, type, field, oldvalue, newvalue, data, creator, created )
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
$sth = $dbh->prepare( $query );
unless (defined $sth) {
$RT::Logger->error( "couldn't prepare query: ". $dbh->errstr );
Abort(loc('There were an error in relocating the requested transaction'));
}
$result = $sth->execute( 'RT::Ticket', $TargetTicket->id, 'Relocate'.$txn_type, 'Transaction.ObjectId', $STicket->id, $TargetTicket->id, "$TransactionId;".$Now->ISO.";".$Transaction->Created.";present", $session{'CurrentUser'}->Id, $Now->ISO );
if ( ! defined $result) {
$RT::Logger->error( "couldn't execute query: ". $dbh->errstr );
$RT::Handle->Rollback();
Abort(loc('There were an error in relocating the requested transaction'));
}
$RT::Logger->error( "result#4: ". $result );
# $RT::Handle->Rollback();
# Abort(loc('EXIT EXIT EXIT'));
$RT::Handle->Commit();
RT::Interface::Web::Redirect(RT->Config->Get('WebURL').'Ticket/History.html?id='.$TargetTicket->id );
$m->abort;
}
my $desc = $Transaction->BriefDescriptionAsHTML;
lib/RT/Extension/RelocateReply.pm view on Meta::CPAN
use Data::Dumper;
package RT::Extension::RelocateReply;
our $VERSION = '1.00';
'RT::Queue'->AddRight( Admin => RelocateReply => "Relocate comments or correspondances of a ticket");
=head1 NAME
RT::Extension::RelocateReply - relocate missplaced messages to the right ticket
=head1 DESCRIPTION
This extension for RT gives the ability to those who have the
C<RelocateReply> right to relocate / move messages (comments or
correspondences) from one ticket to another. The relocation action
appears in both ticket's history width the current date. There will be
message at the original place stating the transaction transition.
=head1 RT VERSION
Works with RT 4.4.
=head1 INSTALLATION
( run in 1.128 second using v1.01-cache-2.11-cpan-5511b514fd6 )