[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, master, updated. 0.14-4-g856074a

Brian Duggan brian at bestpractical.com
Thu May 4 15:46:25 EDT 2017


The branch, master has been updated
       via  856074a75bbe95899517886d874023503d19b8ec (commit)
       via  c6291938e58e17c94620ce6ee35abb18cc1519fa (commit)
      from  b1fe403f5a23f3cebe1c2bb45365a5689d593986 (commit)

Summary of changes:
 .../Ticket/Modify.html/Default                     |   6 -
 .../Ticket/ModifyAll.html/Default                  |   8 --
 lib/RT/Extension/MandatoryOnTransition.pm          |  12 +-
 lib/RT/Extension/MandatoryOnTransition/Test.pm.in  |   2 +-
 xt/immutable_core_for_update.t                     | 129 +++++++++++++++++++++
 5 files changed, 141 insertions(+), 16 deletions(-)
 create mode 100644 xt/immutable_core_for_update.t

- Log -----------------------------------------------------------------
commit c6291938e58e17c94620ce6ee35abb18cc1519fa
Author: Brian C. Duggan <brian at dugga.net>
Date:   Wed May 3 10:28:03 2017 -0400

    Test that %CORE_FOR_UPDATE doesn't change on ticket modification
    
    The Ticket/Modify.html/Default and Ticket/ModifyAll.html/Default
    callbacks alter $CORE_FOR_UPDATE{'TimeWorked'} to match the field name
    for Time Worked in the Modify[All].html form. Once a user updates a
    ticket through the Basics or Jumbo links, the value for
    $CORE_FOR_UPDATE{'TimeWorked'} no longer matches the field name for
    the Ticket/Update.html form. Subsequent attempts to transition any
    ticket to a status that requires TimeWorked through Update.html
    fail.
    
    The first two tests test that MoT with required TimeWorked functions
    on Modify[All].html. The second two tests demonstrate the failure
    above.
    
    Additionally, update MandatoryOnTransition/Test.pm to allow setting
    config via 'use'.

diff --git a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
index c3d08b5..3a0067b 100644
--- a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
+++ b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
@@ -30,7 +30,7 @@ sub import {
         $args{'testing'} = 'RT::Extension::MandatoryOnTransition';
     }
 
-    $args{'config'} =<<CONFIG;
+    $args{'config'} ||=<<CONFIG;
 Set( %MandatoryOnTransition,
     '*' => {
         'open -> resolved' => [qw(TimeWorked TimeTaken)]
diff --git a/xt/immutable_core_for_update.t b/xt/immutable_core_for_update.t
new file mode 100644
index 0000000..298a1f7
--- /dev/null
+++ b/xt/immutable_core_for_update.t
@@ -0,0 +1,129 @@
+use strict;
+use warnings;
+
+use RT::Extension::MandatoryOnTransition::Test tests => undef, config => <<CONFIG
+Set( %MandatoryOnTransition,
+     '*' => {
+         '* -> resolved' => ['TimeWorked',]
+     }
+    );
+CONFIG
+    ;
+
+use_ok('RT::Extension::MandatoryOnTransition');
+
+my ( $baseurl, $m ) = RT::Test->started_ok();
+
+ok( $m->login( 'root', 'password' ), 'logged in' );
+$m->get_ok($m->rt_base_url);
+
+diag "Resolve ticket through Basics with required TimeWorked";
+{
+    my $t = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to resolve through Modify.html',
+        Content => 'Testing',
+        );
+    ok( $t->id, 'Created ticket to resolve through Modify.html: ' . $t->id);
+
+    $m->goto_ticket($t->id);
+    $m->follow_link_ok( { text => 'Basics' }, 'Get Modify.html of ticket' );
+    $m->submit_form_ok( { form_name => 'TicketModify',
+                          fields => { Status => 'resolved', TimeWorked => 10, },
+                          button => 'SubmitTicket', },
+                        'Resolve ticket through Basics with required TimeWorked', );
+
+    $m->content_contains("Worked 10 minutes");
+    $m->content_contains("Status changed from 'new' to 'resolved'");
+}
+
+diag "Resolve ticket through Jumbo with required TimeWorked";
+{
+    my $t = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to resolve through ModifyAll.html',
+        Content => 'Testing',
+        );
+    ok( $t->id, 'Created ticket to resolve through ModifyAll.html: ' . $t->id);
+
+    $m->goto_ticket($t->id);
+    $m->follow_link_ok( { text => 'Jumbo' }, 'Get ModifyAll.html of ticket' );
+    $m->submit_form_ok( { form_name => 'TicketModifyAll',
+                          fields => { Status => 'resolved', TimeWorked => 10, },
+                          button => 'SubmitTicket', },
+                        'Resolve ticket through Jumbo with required TimeWorked', );
+
+    $m->content_contains("Worked 10 minutes");
+    $m->content_contains("Status changed from 'new' to 'resolved'");
+}
+
+diag "Modify ticket through Basics without permanently altering %CORE_FOR_UPDATE";
+{
+    my $t0 = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to modify',
+        Content => 'Testing',
+        );
+    ok( $t0->id, 'Created ticket to modify: ' . $t0->id);
+
+    my $t1 = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to resolve',
+        Content => 'Testing',
+        );
+    ok( $t1->id, 'Created ticket to resolve, after modifying another: ' . $t1->id);
+
+    $m->goto_ticket($t0->id);
+    $m->follow_link_ok( { text => 'Basics' }, 'Get Modify.html of ticket' );
+    $m->submit_form_ok( { form_name => 'TicketModify',
+                          fields => { Priority => 1, },
+                          button => 'SubmitTicket', },
+                        'Modify any ticket 0 metadata except status, queue, or TimeWorked', );
+    $m->content_contains('Priority changed from (no value) to '1'');
+
+    $m->goto_ticket($t1->id);
+    $m->follow_link_ok( { text => 'Resolve' }, 'Try to resolve ticket');
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          fields => { UpdateTimeWorked => 10 },
+                          button => 'SubmitTicket',},
+                        'Resolve ticket 1 with value for TimeWorked after modifying another ticket');
+    $m->content_contains("Worked 10 minutes");
+    $m->content_contains("Status changed from 'new' to 'resolved'");
+}
+
+diag "Modify ticket through Jumbo without permanently altering %CORE_FOR_UPDATE";
+{
+    my $t0 = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to modify',
+        Content => 'Testing',
+        );
+    ok( $t0->id, 'Created ticket to modify: ' . $t0->id);
+
+    my $t1 = RT::Test->create_ticket(
+        Queue => 'General',
+        Subject => 'Ticket to resolve',
+        Content => 'Testing',
+        );
+    ok( $t1->id, 'Created ticket to resolve, after modifying another: ' . $t1->id);
+
+    $m->goto_ticket($t0->id);
+    $m->follow_link_ok( { text => 'Jumbo' }, 'Get ModifyAll.html of ticket' );
+    $m->submit_form_ok( { form_name => 'TicketModifyAll',
+                          fields => { Priority => 1, },
+                          button => 'SubmitTicket', },
+                        'Modify any ticket 0 metadata except status, queue, or TimeWorked', );
+    $m->content_contains('Priority changed from (no value) to '1'');
+
+    $m->goto_ticket($t1->id);
+    $m->follow_link_ok( { text => 'Resolve' }, 'Try to resolve ticket');
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          fields => { UpdateTimeWorked => 10 },
+                          button => 'SubmitTicket',},
+                        'Resolve ticket 1 with value for TimeWorked after modifying another ticket');
+    $m->content_contains("Worked 10 minutes");
+    $m->content_contains("Status changed from 'new' to 'resolved'");
+}
+
+undef $m;
+done_testing;

commit 856074a75bbe95899517886d874023503d19b8ec
Author: Brian C. Duggan <brian at dugga.net>
Date:   Thu May 4 15:37:14 2017 -0400

    Don't alter %CORE_FOR_UPDATE on ticket modification
    
    Don't alter %CORE_FOR_UPDATE when a user updates a ticket through
    Modify[All].html (Basics or Jumbo). Instead, create copy in
    CheckMandatoryFields, update the copy to match the Modify[All].html
    form when called from Modify[All].html, and use the copy for
    reference.

diff --git a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Modify.html/Default b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Modify.html/Default
index 91451b5..780fc67 100644
--- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Modify.html/Default
+++ b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Modify.html/Default
@@ -1,7 +1 @@
-<%INIT>
-# CORE_FOR_UPDATE assumes that any update to a Ticket is coming from Update.html
-# which calls TimeWorked UpdateTimeWorked
-$RT::Extension::MandatoryOnTransition::CORE_FOR_UPDATE{TimeWorked} = "TimeWorked";
-$RT::Extension::MandatoryOnTransition::CORE_FOR_UPDATE{TimeTaken} = "TimeWorked";
-</%INIT>
 <& /Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate, %ARGS &>
diff --git a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/ModifyAll.html/Default b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/ModifyAll.html/Default
index 43b0258..780fc67 100644
--- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/ModifyAll.html/Default
+++ b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/ModifyAll.html/Default
@@ -1,9 +1 @@
-<%INIT>
-# CORE_FOR_UPDATE assumes that any update to a Ticket is coming from Update.html
-# which calls TimeWorked UpdateTimeWorked
-# Luckily - while Jumbo contains a Content box, it's called UpdateContent like Update.html, rather than
-# Content like Create.html.
-$RT::Extension::MandatoryOnTransition::CORE_FOR_UPDATE{TimeWorked} = "TimeWorked";
-$RT::Extension::MandatoryOnTransition::CORE_FOR_UPDATE{TimeTaken} = "TimeWorked";
-</%INIT>
 <& /Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate, %ARGS &>
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index b17a0a1..a2735d0 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -431,12 +431,22 @@ sub CheckMandatoryFields {
 
     my $transition =  ($args{'From'} ||'') ne ($args{'To'} || '') ? 'Status' : 'Queue';
 
+    # If we were called from Modify.html (Basics) or ModifyAll.html
+    # (Jumbo), where the SubmitTicket button goes by 'Save Changes',
+    # then set the form field name for Time Worked to 'TimeWorked' in
+    # our local copy of %CORE_FOR_UPDATE
+    my %CORE_FOR_UPDATE_COPY = %CORE_FOR_UPDATE;
+    if ( $ARGSRef->{'SubmitTicket'} eq 'Save Changes' ) {
+        $CORE_FOR_UPDATE_COPY{'TimeWorked'} = 'TimeWorked';
+        $CORE_FOR_UPDATE_COPY{'TimeTaken'} = 'TimeWorked';
+    }
+
     # Check core fields, after canonicalization for update
     for my $field (@$core) {
 
         # Will we have a value on update/create?
         my $arg = $args{'Ticket'}
-            ? $CORE_FOR_UPDATE{$field}
+            ? $CORE_FOR_UPDATE_COPY{$field}
             : $CORE_FOR_CREATE{$field};
         next unless $arg;
         next if defined $ARGSRef->{$arg} and length $ARGSRef->{$arg};

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


More information about the Bps-public-commit mailing list