[Rt-commit] rt branch, 4.2/cfs-vs-core-fields-in-create-tickets-action, created. rt-4.2.10-231-g5674ac3

Alex Vandiver alexmv at bestpractical.com
Tue Mar 31 17:50:11 EDT 2015


The branch, 4.2/cfs-vs-core-fields-in-create-tickets-action has been created
        at  5674ac3a7b47559480b259eb5fda23b089ef0614 (commit)

- Log -----------------------------------------------------------------
commit 5674ac3a7b47559480b259eb5fda23b089ef0614
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Mar 31 17:49:31 2015 -0400

    Only use CreateTicket line as a CF name if not also a core field
    
    Every field CreateTickets loads is treated as potential CF; so, in the
    presence of a "Status" CF, the CF was set, in addition to the core
    Status field.
    
    Once a field from %args has been used to fill %ticketargs, remove it,
    such that it is not viewed as a potential custom field name.  To
    accomplish this, handling of "deferred" items (including links and
    Status) are moved before CF handling, so they can remove values they
    consume.
    
    Status is additionally special; it is both deferred _and_ set in
    %ticketargs.  As such, it is temporarily put back into %args before
    GetDeferred is called.
    
    Fixes: I#18145

diff --git a/lib/RT/Action/CreateTickets.pm b/lib/RT/Action/CreateTickets.pm
index 5ec2f06..c162475 100644
--- a/lib/RT/Action/CreateTickets.pm
+++ b/lib/RT/Action/CreateTickets.pm
@@ -715,36 +715,42 @@ sub ParseLines {
     $args{'type'} ||= 'ticket';
 
     my %ticketargs = (
-        Queue           => $args{'queue'},
-        Subject         => $args{'subject'},
-        Status          => $args{'status'} || 'new',
-        Due             => $args{'due'},
-        Starts          => $args{'starts'},
-        Started         => $args{'started'},
-        Resolved        => $args{'resolved'},
-        Owner           => $args{'owner'},
-        Requestor       => $args{'requestor'},
-        Cc              => $args{'cc'},
-        AdminCc         => $args{'admincc'},
-        TimeWorked      => $args{'timeworked'},
-        TimeEstimated   => $args{'timeestimated'},
-        TimeLeft        => $args{'timeleft'},
-        InitialPriority => $args{'initialpriority'} || 0,
-        FinalPriority   => $args{'finalpriority'} || 0,
-        SquelchMailTo   => $args{'squelchmailto'},
-        Type            => $args{'type'},
+        Queue           => delete $args{'queue'},
+        Subject         => delete $args{'subject'},
+        Status          => delete $args{'status'} || 'new',
+        Due             => delete $args{'due'},
+        Starts          => delete $args{'starts'},
+        Started         => delete $args{'started'},
+        Resolved        => delete $args{'resolved'},
+        Owner           => delete $args{'owner'},
+        Requestor       => delete $args{'requestor'},
+        Cc              => delete $args{'cc'},
+        AdminCc         => delete $args{'admincc'},
+        TimeWorked      => delete $args{'timeworked'},
+        TimeEstimated   => delete $args{'timeestimated'},
+        TimeLeft        => delete $args{'timeleft'},
+        InitialPriority => delete $args{'initialpriority'} || 0,
+        FinalPriority   => delete $args{'finalpriority'} || 0,
+        SquelchMailTo   => delete $args{'squelchmailto'},
+        Type            => delete $args{'type'},
     );
 
     if ( $args{content} ) {
         my $mimeobj = MIME::Entity->build(
-            Type    => $args{'contenttype'} || 'text/plain',
+            Type    => delete $args{'contenttype'} || 'text/plain',
             Charset => 'UTF-8',
-            Data    => [ map {Encode::encode( "UTF-8", $_ )} @{$args{'content'}} ],
+            Data    => [ map {Encode::encode( "UTF-8", $_ )} @{delete $args{'content'}} ],
         );
         $ticketargs{MIMEObj} = $mimeobj;
-        $ticketargs{UpdateType} = $args{'updatetype'} || 'correspond';
+        $ticketargs{UpdateType} = delete $args{'updatetype'} || 'correspond';
     }
 
+    # It may be impossible to create the ticket in the desired status;
+    # we defer setting the status in GetDeferred, and try again in
+    # PostProcess.
+    $args{status} = $ticketargs{Status};
+    $self->GetDeferred( \%args, $template_id, $links, $postponed );
+
     foreach my $tag ( keys(%args) ) {
         # if the tag was added later, skip it
         my $orig_tag = $original_tags{$tag} or next;
@@ -774,8 +780,6 @@ sub ParseLines {
         }
     }
 
-    $self->GetDeferred( \%args, $template_id, $links, $postponed );
-
     return $TicketObj, \%ticketargs;
 }
 
@@ -929,19 +933,19 @@ sub GetDeferred {
     push @$links,
         (
         $id,
-        {   DependsOn    => $args->{'dependson'},
-            DependedOnBy => $args->{'dependedonby'},
-            RefersTo     => $args->{'refersto'},
-            ReferredToBy => $args->{'referredtoby'},
-            Children     => $args->{'children'},
-            Parents      => $args->{'parents'},
+        {   DependsOn    => delete $args->{'dependson'},
+            DependedOnBy => delete $args->{'dependedonby'},
+            RefersTo     => delete $args->{'refersto'},
+            ReferredToBy => delete $args->{'referredtoby'},
+            Children     => delete $args->{'children'},
+            Parents      => delete $args->{'parents'},
         }
         );
 
     push @$postponed, (
 
         # Status is postponed so we don't violate dependencies
-        $id, { Status => $args->{'status'}, }
+        $id, { Status => delete $args->{'status'}, }
     );
 }
 
diff --git a/t/ticket/create-action-cf-vs-core.t b/t/ticket/create-action-cf-vs-core.t
new file mode 100644
index 0000000..3610ec9
--- /dev/null
+++ b/t/ticket/create-action-cf-vs-core.t
@@ -0,0 +1,71 @@
+use strict; use warnings;
+
+use RT::Test tests => undef;
+
+my $cf;
+{
+    my $cf = RT::CustomField->new( RT->SystemUser );
+    my ($id, $msg)=  $cf->Create(
+        Name => 'Status',
+        Queue => '0',
+        Description => 'A Testing custom field',
+        Type=> 'FreeformSingle'
+    );
+    ok($id, 'Global custom field correctly created');
+
+    ($id, $msg)=  $cf->Create(
+        Name => 'Subject',
+        Queue => '0',
+        Description => 'A Testing custom field',
+        Type => 'FreeformSingle'
+    );
+    ok($id, 'Global custom field correctly created');
+}
+
+my $queuea = RT::Test->load_or_create_queue( Name => 'A' );
+ok $queuea && $queuea->id;
+
+my $queueb = RT::Test->load_or_create_queue( Name => 'B' );
+ok $queueb && $queueb->id;
+
+my $template;
+{
+    my $content = <<'END';
+===Create-Ticket: approval
+Subject: New ticket
+Queue: B
+Status: open
+END
+    $template = RT::Template->new(RT->SystemUser);
+    my ($status, $msg) = $template->Create(
+        Name => "Test",
+        Queue => $queuea->id,
+        Content => $content,
+    );
+    ok $status, "created a template";
+
+    my $scrip = RT::Scrip->new( RT->SystemUser );
+    ($status, $msg) = $scrip->Create(
+        Queue => 'A',
+        ScripCondition => 'On Create',
+        ScripAction => 'Create Tickets',
+        Template => $template->Name,
+    );
+    ok $status, "created a scrip";
+}
+
+{
+    my $ticket = RT::Ticket->new( RT->SystemUser );
+    my ($id) = $ticket->Create( Queue => $queuea, Subject => 'test' );
+    ok $id, "created a ticket";
+
+    my $last = RT::Test->last_ticket;
+    isnt $last->id, $id;
+    is $last->FirstCustomFieldValue('Status'), undef;
+    is $last->Status, 'open';
+
+    is $last->FirstCustomFieldValue('Subject'), undef;
+    is $last->Subject, 'New ticket';
+}
+
+done_testing;

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


More information about the rt-commit mailing list