Skip to content

Commit

Permalink
Add Handle* methods for compatibility with RT 4.4
Browse files Browse the repository at this point in the history
Email plugin handling for RT 4.4 was refactored, providing
new HandleAction hooks rather than including all functionality
in GetCurrentUser. Create a new Action module and provide
Handle methods for the standard comment and correspond actions
to allow users to upgrade in place.

The updates allow the code to run for both RT 4.2 and
4.4 with minimal duplication. However the code is in a new
module, so users will need to update their RT_SiteConfig.pm.
  • Loading branch information
cbrandtbuffalo committed Mar 29, 2016
1 parent a14e65a commit 45bb68e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 7 deletions.
12 changes: 12 additions & 0 deletions etc/handle_action_pass_currentuser.patch
@@ -0,0 +1,12 @@
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 175805d..7ffba8e 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -248,6 +248,7 @@ sub Gateway {
Action => $action,
Subject => $Subject,
Message => $Message,
+ CurrentUser => $CurrentUser,
Ticket => $Ticket,
TicketId => $args{ticket},
Queue => $SystemQueueObj,
55 changes: 48 additions & 7 deletions lib/RT/Extension/CommandByMail.pm
Expand Up @@ -57,8 +57,24 @@ C<@MailPlugins> configuration, as follows:
Set(@MailPlugins, qw(Auth::MailFrom Filter::TakeAction));
For RT 4.4 or newer, the plugin code is in C<Action::CommandByMail>, so
add this:
Set(@MailPlugins, qw(Auth::MailFrom Action::CommandByMail));
Be sure to include C<Auth::MailFrom> in the list as well.
B<Note:> The plugin name has changed for RT 4.4, so after upgrading you
must also update your C<RT_SiteConfig.pm> file to change
C<Filter::TakeAction> to the new C<Action::CommandByMail>.
=item Patch RT
For RT 4.4.0, apply the included patch:
cd /opt/rt4 # Your location may be different
patch -p1 < /download/dir/RT-Extension-CommandByMail/etc/handle_action_pass_currentuser.patch
=item Restart your webserver
=back
Expand Down Expand Up @@ -225,6 +241,14 @@ If set, the body will not be examined, only the headers.
This extension is incompatible with C<UnsafeEmailCommands> RT option.
=head1 METHODS
=head2 ProcessCommands
This method provides the main email processing functionality. It supports
both RT 4.2 and earlier and 4.4 and later. To do this, the return hashes
contain some values used by 4.2 code and some used by 4.4. The return
values coexist and unused values are ignored by the different versions.
=cut

sub ProcessCommands {
Expand All @@ -245,11 +269,19 @@ sub ProcessCommands {
."CurrentUser (actor) is not authorized. "
);
return { CurrentUser => $args{'CurrentUser'},
AuthLevel => $args{'AuthLevel'} };
AuthLevel => $args{'AuthLevel'},
MailError => 1,
ErrorSubject => "Permission Denied",
Explanation => "CurrentUser is not set when trying to "
. "process email command via CommandByMail",
Failure => 1
};
}

$RT::Logger->debug("Running CommandByMail as ".$args{'CurrentUser'}->UserObj->Name);

# If the user isn't asking for a comment or a correspond,
# bail out
# bail out. Only relevant for pre-4.2.
unless ( $args{'Action'} =~ /^(?:comment|correspond)$/i ) {
return { CurrentUser => $args{'CurrentUser'},
AuthLevel => $args{'AuthLevel'} };
Expand All @@ -269,12 +301,16 @@ sub ProcessCommands {
if (!$group->HasMemberRecursively($args{'CurrentUser'}->PrincipalObj)) {
$RT::Logger->debug("CurrentUser not in CommandByMailGroup");
return { CurrentUser => $args{'CurrentUser'},
AuthLevel => $args{'AuthLevel'} };
AuthLevel => $args{'AuthLevel'},
MailError => 1,
ErrorSubject => "Permission Denied",
Explanation => "User " . $args{'CurrentUser'}->UserObj->EmailAddress
. " is not in the configured CommandByMailGroup",
Failure => 1
};
}
}

$RT::Logger->debug("Running CommandByMail as ".$args{'CurrentUser'}->UserObj->Name);

my $headername = $new_config
? RT->Config->Get('CommandByMailHeader')
: $RT::CommandByMailHeader;
Expand Down Expand Up @@ -459,7 +495,13 @@ sub ProcessCommands {
"Couldn't write $args{'Action'}."
." Fallback to standard mailgate. Error: $msg");
return { CurrentUser => $args{'CurrentUser'},
AuthLevel => $args{'AuthLevel'} };
AuthLevel => $args{'AuthLevel'},
MailError => 1,
ErrorSubject => "Unable to execute $args{'Action'}",
Explanation => "Unable to execute $args{'Action'} on ticket "
. $args{'Ticket'}->Id . ": $msg",
Failure => 1
};
}
}

Expand Down Expand Up @@ -853,7 +895,6 @@ sub _ReportResults {
}



1;
__END__
Expand Down
56 changes: 56 additions & 0 deletions lib/RT/Interface/Email/Action/CommandByMail.pm
@@ -0,0 +1,56 @@
package RT::Interface::Email::Action::CommandByMail;

use warnings;
use strict;

use Role::Basic 'with';
with 'RT::Interface::Email::Role';

=head1 NAME
RT::Interface::Email::Action::CommandByMail - Change metadata of ticket via email
=head1 DESCRIPTION
This action provides compatibility with the new mail plugin system introduced
in RT 4.4. It provides an alternate to the default comment and correspond
handlers provided by RT.
=cut

# To maintain compatibility with previous versions of CommandByMail,
# handle the standard comment and correspond actions. Follow the
# pattern from RT's default action handling for providing both.

sub HandleComment {
_HandleEither( @_, Action => "Comment" );
}

sub HandleCorrespond {
_HandleEither( @_, Action => "Correspond" );
}

sub _HandleEither {
my %args = (
Action => undef,
Message => undef,
Subject => undef,
Ticket => undef,
TicketId => undef,
Queue => undef,
@_,
);

my $return_ref = RT::Extension::CommandByMail::ProcessCommands(%args);

if ( exists $return_ref->{'MailError'} and $return_ref->{'MailError'} ){
MailError(
Subject => $return_ref->{'ErrorSubject'},
Explanation => $return_ref->{'Explanation'},
FAILURE => $return_ref->{'Failure'},
);
}
return;
}

1;

0 comments on commit 45bb68e

Please sign in to comment.