[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, master, updated. 0.13-7-gf44b722

Dave Goehrig dave at bestpractical.com
Thu Oct 13 15:08:32 EDT 2016


The branch, master has been updated
       via  f44b7229eec0a660065b0e6bed0f13683b722b38 (commit)
      from  e33fada5995f67169a7075920bab77df08533bc1 (commit)

Summary of changes:
 .../Elements/EditCustomFields/MassageCustomFields  | 11 -----
 .../Ticket/Update.html/BeforeUpdate                |  1 -
 lib/RT/Extension/MandatoryOnTransition.pm          | 50 +++++++++++++++-------
 lib/RT/Extension/MandatoryOnTransition/Test.pm.in  | 10 ++---
 xt/basic.t                                         |  1 -
 xt/mandatory_on_create.t                           |  1 +
 xt/required_fields.t                               |  1 +
 7 files changed, 41 insertions(+), 34 deletions(-)
 delete mode 100644 html/Callbacks/RT-Extension-MandatoryOnTransition/Elements/EditCustomFields/MassageCustomFields

- Log -----------------------------------------------------------------
commit f44b7229eec0a660065b0e6bed0f13683b722b38
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Thu Oct 13 15:08:23 2016 -0400

    transition checks on queue change

diff --git a/html/Callbacks/RT-Extension-MandatoryOnTransition/Elements/EditCustomFields/MassageCustomFields b/html/Callbacks/RT-Extension-MandatoryOnTransition/Elements/EditCustomFields/MassageCustomFields
deleted file mode 100644
index 6a6dfdd..0000000
--- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Elements/EditCustomFields/MassageCustomFields
+++ /dev/null
@@ -1,11 +0,0 @@
-<%args>
-$CustomFields
-$Named => []
-</%args>
-<%init>
-return if RT->Config->Get('ShowAllCustomFieldsOnMandatoryUpdate');
-return unless @$Named;
-
-$CustomFields->Limit( FIELD => 'Name', VALUE => $_, SUBCLAUSE => 'names', ENTRYAGGREGRATOR => 'OR', CASESENSITIVE => 1 )
-    for @$Named;
-</%init>
diff --git a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate
index dd91b1d..171893f 100644
--- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate
+++ b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/BeforeUpdate
@@ -5,7 +5,6 @@ $skip_update
 $results => []
 </%args>
 <%init>
-
 my $errors_ref = RT::Extension::MandatoryOnTransition->CheckMandatoryFields(
     ARGSRef => $ARGSRef,
     Ticket  => $TicketObj,
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index ab0337f..2ceef95 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -261,6 +261,8 @@ sub RequiredFields {
         Queue   => undef,
         From    => undef,
         To      => undef,
+        NewQueue => undef,
+        ToQueue => undef,
         @_,
     );
 
@@ -269,17 +271,30 @@ sub RequiredFields {
         $args{From}  ||= $args{Ticket}->Status;
     }
     my ($from, $to) = @args{qw(From To)};
-    return ([], []) unless $from and $to;
 
-    my %config = $self->Config($args{Queue});
+    if ($args{NewQueue}) {
+        my $queue = RT::Queue->new(RT->SystemUser);
+        $queue->Load($args{NewQueue});
+        $args{ToQueue} = $queue->Name;
+    }
+
+    my ($from_queue, $to_queue) = ($args{Queue}, $args{ToQueue} || $args{Queue});
+
+    return ([], []) unless ($from and $to) or ($from_queue and $to_queue );
+
+    my %config = ();
+    %config = $self->Config($args{Queue});
+
     return ([], []) unless %config;
 
-    # No transition.
-    return ([], []) if $from eq $to;
+   $to ||= '';
+   $from ||= '';
+   $to_queue ||= '*';
 
     my $required = $config{"$from -> $to"}
                 || $config{"* -> $to"}
                 || $config{"$from -> *"}
+		|| $config{$to_queue}
                 || [];
 
     my %core_supported = map { $_ => 1 } @CORE_SUPPORTED;
@@ -364,10 +379,13 @@ sub CheckMandatoryFields {
         Queue   => $args{'Queue'} ? $args{'Queue'}->Name : undef,
         From    => $args{'From'},
         To      => $args{'To'},
+	NewQueue => $$ARGSRef{'Queue'},
     );
 
     return \@errors unless @$core or @$cfs;
 
+    my $transition =  ($args{'From'} ||'') ne ($args{'To'} || '') ? 'Status' : 'Queue';
+
     # Check core fields, after canonicalization for update
     for my $field (@$core) {
 
@@ -385,8 +403,8 @@ sub CheckMandatoryFields {
 
         (my $label = $field) =~ s/(?<=[a-z])(?=[A-Z])/ /g; # /
         push @errors,
-          $CurrentUser->loc("[_1] is required when changing Status to [_2]",
-                                     $label, $CurrentUser->loc($ARGSRef->{Status}));
+          $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
+            $label, $CurrentUser->loc($transition),  $CurrentUser->loc($ARGSRef->{$transition}));
     }
 
     return \@errors unless @$cfs;
@@ -452,13 +470,13 @@ sub CheckMandatoryFields {
                 my $valid_values = join ", ", @must_be;
                 if ( @must_be > 1 ){
                     push @errors,
-                        $CurrentUser->loc("[_1] must be one of: [_3] when changing Status to [_2]",
-                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+                        $CurrentUser->loc("[_1] must be one of: [_4] when changing [_2] to [_3]",
+                        $cf->Name, $CurrentUser->loc($transition), $CurrentUser->loc($ARGSRef->{$transition}), $valid_values);
                 }
                 else{
                     push @errors,
-                        $CurrentUser->loc("[_1] must be [_3] when changing Status to [_2]",
-                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+                        $CurrentUser->loc("[_1] must be [_4] when changing [_2] to [_3]",
+                        $cf->Name, $CurrentUser->loc($transition),  $CurrentUser->loc($ARGSRef->{$transition}), $valid_values);
                 }
                 next;
             }
@@ -471,13 +489,13 @@ sub CheckMandatoryFields {
                 my $valid_values = join ", ", @must_not_be;
                 if ( @must_not_be > 1 ){
                     push @errors,
-                        $CurrentUser->loc("[_1] must not be one of: [_3] when changing Status to [_2]",
-                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+                        $CurrentUser->loc("[_1] must not be one of: [_4] when changing [_2] to [_3]",
+                        $cf->Name, $CurrentUser->loc($transition), $CurrentUser->loc($ARGSRef->{$transition}), $valid_values);
                 }
                 else{
                     push @errors,
-                        $CurrentUser->loc("[_1] must not be [_3] when changing Status to [_2]",
-                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+                        $CurrentUser->loc("[_1] must not be [_4] when changing [_2] to [_3]",
+                        $cf->Name, $CurrentUser->loc($transition),$CurrentUser->loc($ARGSRef->{$transition}), $valid_values);
                 }
                 next;
             }
@@ -491,8 +509,8 @@ sub CheckMandatoryFields {
         next if $args{'Ticket'} && $cf->ValuesForObject($args{'Ticket'})->Count;
 
         push @errors,
-          $CurrentUser->loc("[_1] is required when changing Status to [_2]",
-                                     $cf->Name, $CurrentUser->loc($ARGSRef->{Status}));
+          $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
+                                     $cf->Name, $CurrentUser->loc($transition), $CurrentUser->loc($ARGSRef->{$transition}));
     }
 
     return \@errors;
diff --git a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
index 1757bb1..87d127c 100644
--- a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
+++ b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
@@ -50,11 +50,11 @@ CONFIG
 
 sub RTAtorNewerThan{
     my $version = shift;
-    my ($my_major, $my_minor, $my_sub) = split(/\./, $version);
-    my ($major, $minor, $sub) = split(/\./, $RT::VERSION);
-    return ($my_major >= $major
-            and $my_minor >= $minor
-            and $my_sub >= $sub)
+    my ($my_major, $my_minor, $my_sub) = split(/[\.\-]/, $version);
+    my ($major, $minor, $sub) = split(/[\.\-]/, $RT::VERSION);
+    return ($my_major <= $major
+            and $my_minor <= $minor
+            and $my_sub <= $sub)
             ? 1 : 0;
 }
 
diff --git a/xt/basic.t b/xt/basic.t
index 3823fe6..86017dc 100644
--- a/xt/basic.t
+++ b/xt/basic.t
@@ -88,7 +88,6 @@ diag "Try a resolve without TimeWorked";
 
     $m->follow_link_ok( { text => 'Resolve' }, 'Try to resolve ticket');
     $m->content_contains('Test Field');
-    $m->content_lacks('XXX Optional Field ZZZ');
     $m->submit_form_ok( { form_name => 'TicketUpdate',
                           button => 'SubmitTicket',},
                           'Submit resolve with no Time Worked');
diff --git a/xt/mandatory_on_create.t b/xt/mandatory_on_create.t
index a635e4f..7224844 100644
--- a/xt/mandatory_on_create.t
+++ b/xt/mandatory_on_create.t
@@ -32,6 +32,7 @@ diag "Test mandatory fields on create";
                           fields => { Queue => 'General',},
                         }, 'Click button to create ticket');
 
+    print STDERR RT::Extension::MandatoryOnTransition::Test::RTAtorNewerThan('4.3.0');
     if (RT::Extension::MandatoryOnTransition::Test::RTAtorNewerThan('4.4.0')){
         $m->title_is('Create a new ticket in General');
     }
diff --git a/xt/required_fields.t b/xt/required_fields.t
index 8d91b81..4f2135c 100644
--- a/xt/required_fields.t
+++ b/xt/required_fields.t
@@ -8,6 +8,7 @@ use_ok('RT::Extension::MandatoryOnTransition');
 diag "Test RequiredFields without a ticket";
 {
     my ($core, $cf) = RT::Extension::MandatoryOnTransition->RequiredFields(
+			   Queue => 'General',
                            From => 'open',
                            To   => 'resolved',
                        );

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


More information about the Bps-public-commit mailing list