[Rt-commit] rt branch, 4.4/processobjectcustomfieldupdates-parameters, created. rt-4.4.3-196-g57ee874ce

Jim Brandt jbrandt at bestpractical.com
Mon Jan 28 17:10:45 EST 2019


The branch, 4.4/processobjectcustomfieldupdates-parameters has been created
        at  57ee874ce9fd66527af6c042a5cef624020135e3 (commit)

- Log -----------------------------------------------------------------
commit a3d1c506c56757ae71fe37e0d55f68d7099ed67a
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Fri Jan 25 11:09:00 2019 -0500

    Add tests to demonstrate commit running for PreviewScrips
    
    PreviewScrips runs to determine possible recipients for a
    comment or reply, but shouldn't send the email. It does this by
    running only the prepare part of notification scrips. However,
    if provided with a custom field argument, the commit stage of
    scrips can run during the DryRun triggered by PreviewScrips.

diff --git a/t/web/dryrun.t b/t/web/dryrun.t
new file mode 100644
index 000000000..f7206fadb
--- /dev/null
+++ b/t/web/dryrun.t
@@ -0,0 +1,63 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my ($baseurl, $agent) = RT::Test->started_ok;
+
+my $url = $agent->rt_base_url;
+diag "Running server at $url";
+
+$agent->login('root' => 'password');
+is( $agent->status, 200, "Fetched the page ok");
+$agent->content_contains("Logout", "Found a logout link");
+
+my ($ok, $msg);
+my $ticket = RT::Ticket->new(RT->SystemUser);
+my ($tv,$ttv,$tm) = $ticket->Create(
+    Queue => 'General',
+    Subject => "An Interesting Title",
+);
+ok($tv, "Ticket created");
+
+my $cf = RT::CustomField->new(RT->SystemUser);
+ok($cf, "RT::CustomField object initialized");
+($ok, $msg) =  $cf->Create(
+    Name        => 'My Custom Field',
+    Queue       => '0',
+    Description => 'A testing custom field',
+    Type        => 'SelectSingle'
+);
+ok($ok, 'Global custom field created');
+my $cf_id = $cf->Id;
+
+#($ok, $msg) = $ticket->Load($tv);
+#ok($ok, 'created a scrip') or diag "error: $msg";
+
+$ticket->AddCustomFieldValue(Field => $cf->Id,  Value => '1');
+
+diag "Create test scrip";
+my $scrip = RT::Scrip->new(RT->SystemUser);
+($ok, $msg) = $scrip->Create(
+    Queue          => 'General',
+    ScripAction    => 'User Defined',
+    ScripCondition => 'User Defined',
+    Template       => 'blank',
+    CustomIsApplicableCode  => "return 1;",
+    CustomPrepareCode       => "return 1;",
+    CustomCommitCode        => "warn 'Commit should not run for PreviewScrips'; return 1;",
+);
+ok($ok, 'Scrip created');
+
+$agent->get_ok( $url . "Ticket/Update.html?Action=Respond;id=$tv" );
+
+diag "Confirm commit does not run for Preview Scrips";
+$agent->post_ok( $url . "Helpers/PreviewScrips", {
+    id                                               => $tv,
+    "Object-RT::Ticket-$tv-CustomField-$cf_id-Value" => 'Test Value',
+    UpdateType                                       => 'response',
+    TxnRecipients                                    => 'root at localhost',
+}, Content_Type => 'form-data' );
+is( $agent->status, 200, "PreviewScrips returned 200");
+
+done_testing();

commit 57ee874ce9fd66527af6c042a5cef624020135e3
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Fri Jan 25 11:10:06 2019 -0500

    Pass ticket object using Object parameter rather than TicketObj
    
    ProcessObjectCustomFieldUpdates accepts an object to act on via
    the generic parameter 'Object'. However, for tickets, it is often
    called in a sequence with several other calls that pass the
    available ticket object with TicketObj rather than Object.
    
    The function loads a fresh object using an id found in other
    parameters, so it works even when the Object parameter is missing.
    However, when running under DryRun, the newly created and loaded
    ticket object doesn't have the DryRun value set. In the case
    of PreviewScrips, this causes the commit phase of scrips to run
    when a custom field argument was passed and processed.

diff --git a/share/html/Helpers/PreviewScrips b/share/html/Helpers/PreviewScrips
index 14fa77344..6303fd7c5 100644
--- a/share/html/Helpers/PreviewScrips
+++ b/share/html/Helpers/PreviewScrips
@@ -68,7 +68,7 @@ my @dryrun = $TicketObj->DryRun(
         ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
         ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
         ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
-        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, Object => $TicketObj );
         ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
     }
 );
diff --git a/share/html/Helpers/ShowSimplifiedRecipients b/share/html/Helpers/ShowSimplifiedRecipients
index d8bf16dfd..30512532f 100644
--- a/share/html/Helpers/ShowSimplifiedRecipients
+++ b/share/html/Helpers/ShowSimplifiedRecipients
@@ -69,7 +69,7 @@ my @dryrun = $TicketObj->DryRun(
         ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
         ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
         ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
-        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, Object => $TicketObj );
         ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
     }
 );
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 87a663ebf..2681a3831 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -191,7 +191,7 @@ if ($ARGS{'id'} eq 'new') {
         push @Actions, ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
         push @Actions, ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
         push @Actions, ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
-        push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, Object => $TicketObj );
         push @Actions, ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
     });
     if ( !$SkipProcessing ) {
diff --git a/share/html/Ticket/ModifyLinks.html b/share/html/Ticket/ModifyLinks.html
index d2bdfbb85..e82037ed7 100644
--- a/share/html/Ticket/ModifyLinks.html
+++ b/share/html/Ticket/ModifyLinks.html
@@ -76,7 +76,7 @@ my @results;
 $Ticket->Atomic(sub{
     $m->callback( TicketObj => $Ticket, ARGSRef => \%ARGS, Results => \@results );
     push @results, ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
-    push @results, ProcessObjectCustomFieldUpdates( TicketObj => $Ticket, ARGSRef => \%ARGS );
+    push @results, ProcessObjectCustomFieldUpdates( Object => $Ticket, ARGSRef => \%ARGS );
 });
 
 MaybeRedirectForResults(
diff --git a/share/html/Ticket/ModifyPeople.html b/share/html/Ticket/ModifyPeople.html
index 5b62fd686..b7208ce1f 100644
--- a/share/html/Ticket/ModifyPeople.html
+++ b/share/html/Ticket/ModifyPeople.html
@@ -109,7 +109,7 @@ unless ($OnlySearchForPeople or $OnlySearchForGroup) {
     $Ticket->Atomic(sub{
         push @results, ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS);
         push @results, ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS);
-        push @results, ProcessObjectCustomFieldUpdates( TicketObj => $Ticket, ARGSRef => \%ARGS );
+        push @results, ProcessObjectCustomFieldUpdates( Object => $Ticket, ARGSRef => \%ARGS );
     });
 }
 
diff --git a/share/html/m/ticket/show b/share/html/m/ticket/show
index 8d6eefbaf..b0553c165 100644
--- a/share/html/m/ticket/show
+++ b/share/html/m/ticket/show
@@ -106,7 +106,7 @@ if ($ARGS{'id'} eq 'new') {
         push @Actions, ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $Ticket );
         push @Actions, ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $Ticket );
         push @Actions, ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $Ticket );
-        push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $Ticket );
+        push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, Object => $Ticket );
         push @Actions, ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $Ticket );
     });
 

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


More information about the rt-commit mailing list