[Bps-public-commit] RT-Extension-CommandByMail branch, master, updated. 2.01-4-geb49905

Jim Brandt jbrandt at bestpractical.com
Wed Jul 13 15:52:31 EDT 2016


The branch, master has been updated
       via  eb499050fc7af94b4e15bb5db3a5337947b20692 (commit)
       via  bdd046ba0b1a617e9bd91a7a7ed7d97b42a4136d (commit)
       via  bb92efb321a274bb904a9f9fb66448dc3657c644 (commit)
      from  f3869e33f735b0b6f656d7ce3511a3efacf084ac (commit)

Summary of changes:
 README                                         |  5 +++++
 lib/RT/Extension/CommandByMail.pm              | 19 +++++++++++--------
 lib/RT/Interface/Email/Action/CommandByMail.pm | 19 ++++++++++++++++---
 xt/create.t                                    | 17 +++++++++++++++++
 xt/update.t                                    | 25 +++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 11 deletions(-)

- Log -----------------------------------------------------------------
commit bb92efb321a274bb904a9f9fb66448dc3657c644
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jul 13 11:52:38 2016 -0400

    Add test for CommandByMailGroup

diff --git a/xt/update.t b/xt/update.t
index f2fb4bf..77c9d40 100644
--- a/xt/update.t
+++ b/xt/update.t
@@ -314,4 +314,29 @@ END
     like($content, qr/Priority: 44/, "invalid Priority command not stripped");
 }
 
+diag("check CommandByMail group") if $ENV{'TEST_VERBOSE'};
+{
+    ok (my $group = RT::Group->new(RT->SystemUser), "instantiated a group object");
+    ok (my ($gid, $gmsg) = $group->CreateUserDefinedGroup( Name => 'TestGroup', Description => 'A test group',
+                        ), 'Created a new group');
+    RT::Config->Set( CommandByMailGroup => $gid );
+    my $text = <<END;
+Subject: [$RT::rtname #$test_ticket_id] test
+From: root\@localhost
+
+Priority: 44
+
+test
+END
+    my (undef, $id) = $test->send_via_mailgate( $text );
+    is($id, $test_ticket_id, "updated ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->Priority, 20, "not updated, user not in CommandByMail group");
+
+    my $content = $obj->Transactions->Last->Content;
+    like($content, qr/Priority: 44/, "text processed as normal email text");
+}
+
 done_testing();

commit bdd046ba0b1a617e9bd91a7a7ed7d97b42a4136d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jul 13 12:04:25 2016 -0400

    Add option to defer email handling to RT
    
    There are cases where CommandByMail wants to defer email processing,
    for example when a user is not in the defined CommandByMailGroup.
    Previous versions handled this by returning to RT. Provide a similar
    path for RT 4.4 to pass processing back to the default RT path.

diff --git a/README b/README
index b2bfcdf..76ea3ff 100644
--- a/README
+++ b/README
@@ -205,6 +205,11 @@ METHODS
     The return values coexist and unused values are ignored by the different
     versions.
 
+    For 4.4, returning { DeferToRT => 1 } invokes the normal RT mail
+    processing flow. This allows CommandByMail to pass on processing an
+    email message for cases like a user not being a member of
+    CommandByMailGroup.
+
   ParseCcAddressesFromHead HASH
     Takes a hash containing QueueObj, Head and CurrentUser objects. Returns
     a list of all email addresses in the To and Cc headers b<except> the
diff --git a/lib/RT/Extension/CommandByMail.pm b/lib/RT/Extension/CommandByMail.pm
index cc20218..c5e4cd5 100644
--- a/lib/RT/Extension/CommandByMail.pm
+++ b/lib/RT/Extension/CommandByMail.pm
@@ -258,6 +258,11 @@ 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.
+
+For 4.4, returning C<{ DeferToRT =E<gt> 1 }> invokes the normal RT mail processing
+flow. This allows CommandByMail to pass on processing an email message for
+cases like a user not being a member of C<CommandByMailGroup>.
+
 =cut
 
 sub ProcessCommands {
@@ -308,15 +313,13 @@ sub ProcessCommands {
         $group->Load($group_id);
 
         if (!$group->HasMemberRecursively($args{'CurrentUser'}->PrincipalObj)) {
+
             $RT::Logger->debug("CurrentUser not in CommandByMailGroup");
-            return { CurrentUser => $args{'CurrentUser'},
-                     AuthLevel   => $args{'AuthLevel'},
-                     MailError   => 1,
-                     ErrorSubject     => "Permission Denied",
-                     Explanation => "User " . $args{'CurrentUser'}->UserObj->EmailAddress
-                     . " is not in the configured CommandByMailGroup",
-                     Failure     => 1
-                 };
+
+            # User has no access to process commands, so defer to RT to process
+            # like a normal email response.
+
+            return { DeferToRT => 1 };
         }
     }
 
diff --git a/lib/RT/Interface/Email/Action/CommandByMail.pm b/lib/RT/Interface/Email/Action/CommandByMail.pm
index 6195345..efc2020 100644
--- a/lib/RT/Interface/Email/Action/CommandByMail.pm
+++ b/lib/RT/Interface/Email/Action/CommandByMail.pm
@@ -23,14 +23,20 @@ handlers provided by RT.
 # pattern from RT's default action handling for providing both.
 
 sub HandleComment {
-    _HandleEither( @_, Action => "Comment" );
+    CBMHandleEither( @_, Action => "Comment" );
 }
 
 sub HandleCorrespond {
-    _HandleEither( @_, Action => "Correspond" );
+    CBMHandleEither( @_, Action => "Correspond" );
 }
 
-sub _HandleEither {
+=head2 CBMHandleEither
+
+This method is the CommandByMail version of RT's _HandleEither.
+
+=cut
+
+sub CBMHandleEither {
     my %args = (
         Action      => undef,
         Message     => undef,
@@ -43,6 +49,12 @@ sub _HandleEither {
 
     my $return_ref = RT::Extension::CommandByMail::ProcessCommands(%args);
 
+    if ( exists $return_ref->{'DeferToRT'} and $return_ref->{'DeferToRT'} ){
+        # Let RT process like normal email.
+        # Action and other params should already be set appropriately.
+        return RT::Interface::Email::Action::Defaults::_HandleEither( %args );
+    }
+
     if ( exists $return_ref->{'MailError'} and $return_ref->{'MailError'} ){
         MailError(
             Subject     => $return_ref->{'ErrorSubject'},
@@ -50,6 +62,7 @@ sub _HandleEither {
             FAILURE     => $return_ref->{'Failure'},
         );
     }
+
     return;
 }
 

commit eb499050fc7af94b4e15bb5db3a5337947b20692
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jul 13 15:46:49 2016 -0400

    Add a test with umlauts in the subject
    
    Ticket #115654 in rt.cpan.org reported subjects with umlauts
    getting mangled on create with CommandByMail. Add a simple test
    case. It passes, so waiting more details to potentially create
    a failing test case.

diff --git a/xt/create.t b/xt/create.t
index 150460b..e8c946b 100644
--- a/xt/create.t
+++ b/xt/create.t
@@ -1,5 +1,6 @@
 use strict;
 use warnings;
+use utf8;
 
 use RT::Extension::CommandByMail::Test tests => undef;
 my $test = 'RT::Extension::CommandByMail::Test';
@@ -22,6 +23,22 @@ END
     $test_ticket_id = $id;
 }
 
+diag("test with umlaut in subject") if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<END;
+Subject: test Brontë
+From: root\@localhost
+
+test
+END
+    my (undef, $id) = $test->send_via_mailgate( $text );
+    ok($id, "created ticket");
+    my $obj = RT::Ticket->new( $RT::SystemUser );
+    $obj->Load( $id );
+    is($obj->id, $id, "loaded ticket");
+    is($obj->Subject, "test Brontë", "got correct subject with umlauts");
+}
+
 # XXX: use statuses from config/libs
 diag("set status on create") if $ENV{'TEST_VERBOSE'};
 foreach my $status ( qw(new open resolved) ) {

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list