[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, content-spaces, created. 0.18-3-g4f85d64

Jim Brandt jbrandt at bestpractical.com
Mon Aug 12 17:14:52 EDT 2019


The branch, content-spaces has been created
        at  4f85d645a0be07d61974b116d803abe57ee3cad4 (commit)

- Log -----------------------------------------------------------------
commit 7a40696a211b05a12c8bc2e74679097cd234c353
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Aug 12 16:53:50 2019 -0400

    Add test showing content passes with a space

diff --git a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
index 3a0067b..1955480 100644
--- a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
+++ b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
@@ -39,6 +39,9 @@ Set( %MandatoryOnTransition,
         '* -> resolved' => ['TimeWorked', 'TimeTaken', 'CF.Test Field', 'CF.Test Field3', 'CF.Test Field4'],
         'CF.Test Field3' => { transition => '* -> resolved', must_be => ['normal', 'restored'] },
         'CF.Test Field4' => { transition => '* -> resolved', must_not_be => ['down', 'reduced'] } },
+    'Content' => {
+        '* -> resolved' => [ qw(Content) ]
+    },
 );
 CONFIG
 
diff --git a/xt/basic.t b/xt/basic.t
index 3823fe6..93d6e20 100644
--- a/xt/basic.t
+++ b/xt/basic.t
@@ -183,5 +183,42 @@ diag "Try a resolve without TimeWorked in mobile interface";
     like($m->uri->as_string, qr/show/, "On show page after ticket resolve");
 }
 
+my $content = RT::Test->load_or_create_queue( Name => 'Content' );
+
+diag "Try a resolve without Content";
+{
+    my $t = RT::Test->create_ticket(
+         Queue => 'Content',
+         Subject => 'Test Mandatory On Resolve',
+         Content => 'Testing',
+         );
+
+    ok( $t->id, 'Created test ticket: ' . $t->id);
+    ok( $t->SetStatus('open'), 'Set status to open');
+    $m->goto_ticket($t->id);
+
+    $m->follow_link_ok( { text => 'Resolve' }, 'Try to resolve ticket');
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          button => 'SubmitTicket',},
+                          'Submit resolve with no Content');
+    $m->content_contains('Content is required when changing Status to resolved');
+
+    # Space shouldn't count as content
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          fields => { UpdateTimeWorked => 10,
+                                    'UpdateContent' => ' ',},
+                          button => 'SubmitTicket',
+                        }, 'Submit resolve with space as Content');
+    $m->content_contains('Content is required when changing Status to resolved');
+
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          fields => { UpdateTimeWorked => 10,
+                                    'UpdateContent' => 'Some real content',},
+                          button => 'SubmitTicket',
+                        }, 'Submit resolve with real content');
+
+    $m->content_contains("Status changed from 'open' to 'resolved'");
+}
+
 undef $m;
 done_testing;
diff --git a/xt/mandatory_on_create.t b/xt/mandatory_on_create.t
index af5e947..02c9f48 100644
--- a/xt/mandatory_on_create.t
+++ b/xt/mandatory_on_create.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Extension::MandatoryOnTransition::Test tests => 38;
+use RT::Extension::MandatoryOnTransition::Test tests => undef;
 
 use_ok('RT::Extension::MandatoryOnTransition');
 
@@ -110,3 +110,46 @@ diag "Test mandatory fields on create for mobile";
     $m->title_like(qr/#(\d+):/, 'Looks like a ticket number in the title');
     like($m->uri->as_string, qr/show/, "On show page after ticket create");
 }
+
+my $content = RT::Test->load_or_create_queue( Name => 'Content' );
+
+diag "Test mandatory fields on create with content";
+{
+    $m->get_ok($m->rt_base_url);
+    $m->submit_form_ok( { form_name => 'CreateTicketInQueue',
+                          fields => { Queue => 'Content',},
+                        }, 'Click button to create ticket');
+
+    if (RT::Handle::cmp_version( '4.4.0', $RT::VERSION) <= 0) {
+        $m->title_is('Create a new ticket in Content');
+    }
+    else{
+        # RT 4.2 or older
+        $m->title_is('Create a new ticket');
+    }
+
+    $m->submit_form_ok( { form_name => 'TicketCreate',
+                          fields => { Status => 'resolved' },
+                        }, 'Submit with resolved status');
+
+    $m->content_contains('Content is required when changing Status to resolved');
+
+    # Space should not count as content
+    $m->submit_form_ok( { form_name => 'TicketCreate',
+                          fields => { Status => 'resolved',
+                                      'TimeWorked' => '10',
+                                      'Content' => ' ' },
+                        }, 'Submit with resolved status');
+
+    $m->content_contains('Content is required when changing Status to resolved');
+
+    $m->submit_form_ok( { form_name => 'TicketCreate',
+                          fields => { Status => 'resolved',
+                                      'TimeWorked' => '10',
+                                      'Content' => 'This is a message' },
+                        }, 'Submit with resolved status');
+
+    $m->content_contains("Ticket 3 created in queue 'Content'");
+}
+
+done_testing();

commit 4f85d645a0be07d61974b116d803abe57ee3cad4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Aug 12 17:10:06 2019 -0400

    Process Content the same way RT will process it
    
    When checking for required content on a change, some whitespace
    values like space or carriage return would pass validation since
    they appeared to be content. However, RT clears those whitespace
    values, so no transaction with content would appear in the
    history.
    
    Run the content through the same signature stripping function
    RT uses to evaluate it the same way as RT. Note that this
    should also prevent empty content with only a signature
    from validating as having content.

diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 54e63d5..d6f9b89 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -523,7 +523,24 @@ sub CheckMandatoryFields {
             : $CORE_FOR_CREATE{$field};
         next unless $arg;
 
-        next if defined $ARGSRef->{$arg} and length $ARGSRef->{$arg};
+        # Process Content the same way it will be processed by RT on update
+        # Which means cleaning out any possible signature
+        if ( $field eq 'Content' && defined $ARGSRef->{$arg} && length $ARGSRef->{$arg} ) {
+
+            # Create = ContentType, Update = UpdateContentType,
+            # So use $arg to find the ARG for ContentType
+            my $content_type_arg = $arg . 'Type';
+            my $sig_removed = RT::Interface::Web::StripContent(
+                Content        => $ARGSRef->{$arg},
+                ContentType    => $ARGSRef->{$content_type_arg},
+                StripSignature => $ARGSRef->{SkipSignatureOnly} || 1,
+                CurrentUser    => $CurrentUser,
+            );
+            next if defined $sig_removed and length $sig_removed;
+        }
+        else {
+            next if defined $ARGSRef->{$arg} and length $ARGSRef->{$arg};
+        }
 
         # Do we have a value currently?
         # In Create the ticket hasn't been created yet.

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


More information about the Bps-public-commit mailing list