[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, master, updated. 0.13-6-ge33fada

Dave Goehrig dave at bestpractical.com
Thu Oct 13 15:05:01 EDT 2016


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

Summary of changes:
 MANIFEST                                           |   1 +
 README                                             |  23 +--
 .../Elements/EditCustomFields/MassageCustomFields  |   2 +-
 lib/RT/Extension/MandatoryOnTransition.pm          | 195 +++------------------
 lib/RT/Extension/MandatoryOnTransition/Test.pm.in  |  10 ++
 xt/mandatory_on_create.t                           |   2 +-
 6 files changed, 42 insertions(+), 191 deletions(-)

- Log -----------------------------------------------------------------
commit e33fada5995f67169a7075920bab77df08533bc1
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Thu Oct 13 15:04:50 2016 -0400

    reset to version 0.13

diff --git a/MANIFEST b/MANIFEST
index 7057039..858f773 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -36,3 +36,4 @@ README
 xt/basic.t
 xt/mandatory_on_create.t
 xt/required_fields.t
+SIGNATURE                                Public-key signature (added by MakeMaker)
diff --git a/README b/README
index 1ffcace..1e47690 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 NAME
     RT-Extension-MandatoryOnTransition - Require core fields and ticket
-    custom fields on status and/or queue transitions
+    custom fields on status transitions
 
 RT VERSION
     Works with RT 4.0, 4.2, 4.4
@@ -9,11 +9,10 @@ RT VERSION
 
 DESCRIPTION
     This RT extension enforces that certain fields have values before
-    tickets are explicitly moved to or from specified statuses and/or
-    queues. If you list custom fields which must have a value before a
-    ticket is resolved, those custom fields will automatically show up on
-    the "Resolve" page. The reply/comment won't be allowed until a value is
-    provided.
+    tickets are explicitly moved to or from specified statuses. If you list
+    custom fields which must have a value before a ticket is resolved, those
+    custom fields will automatically show up on the "Resolve" page. The
+    reply/comment won't be allowed until a value is provided.
 
     See the configuration example under "INSTALLATION".
 
@@ -98,18 +97,6 @@ CONFIGURATION
     The fallback for queues without specific rules is specified with '*'
     where the queue name would normally be.
 
-    To define mandatory fields for queues is quite similar, however you
-    don't need settings per queue as above. To do this you use the
-    %MandatoryOnQueueTransition config option. This ends up looking like:
-
-        Set( %MandatoryOnQueueTransition,
-            'from -> to' => [ 'BasicField', 'CF.MyField', ],
-        );
-
-    In this case, from and to are expected to be valid queue names. As
-    above, from may also be *. All following must_be and must_not_be
-    features work with queues as well.
-
   Requiring Any Value
     Below is an example which requires 1) time worked and filling in a
     custom field named Resolution before resolving tickets in the Helpdesk
diff --git a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Elements/EditCustomFields/MassageCustomFields b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Elements/EditCustomFields/MassageCustomFields
index 6a6dfdd..8418d5c 100644
--- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Elements/EditCustomFields/MassageCustomFields
+++ b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Elements/EditCustomFields/MassageCustomFields
@@ -6,6 +6,6 @@ $Named => []
 return if RT->Config->Get('ShowAllCustomFieldsOnMandatoryUpdate');
 return unless @$Named;
 
-$CustomFields->Limit( FIELD => 'Name', VALUE => $_, SUBCLAUSE => 'names', ENTRYAGGREGRATOR => 'OR', CASESENSITIVE => 1 )
+$CustomFields->Limit( FIELD => 'Name', VALUE => $_, SUBCLAUSE => 'names', ENTRYAGGREGRATOR => 'OR' )
     for @$Named;
 </%init>
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 4a2ecac..ab0337f 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -6,7 +6,7 @@ our $VERSION = '0.13';
 
 =head1 NAME
 
-RT-Extension-MandatoryOnTransition - Require core fields and ticket custom fields on status and/or queue transitions
+RT-Extension-MandatoryOnTransition - Require core fields and ticket custom fields on status transitions
 
 =head1 RT VERSION
 
@@ -17,7 +17,7 @@ See below for some restrictions on RT 4.0.
 =head1 DESCRIPTION
 
 This RT extension enforces that certain fields have values before tickets are
-explicitly moved to or from specified statuses and/or queues.  If you list custom fields
+explicitly moved to or from specified statuses.  If you list custom fields
 which must have a value before a ticket is resolved, those custom fields will
 automatically show up on the "Resolve" page.  The reply/comment won't be
 allowed until a value is provided.
@@ -125,18 +125,6 @@ status C<to>.
 The fallback for queues without specific rules is specified with C<'*'> where
 the queue name would normally be.
 
-To define mandatory fields for queues is quite similar, however you don't need
-settings per queue as above. To do this you use the
-C<%MandatoryOnQueueTransition> config option. This ends up looking like:
-
-    Set( %MandatoryOnQueueTransition,
-        'from -> to' => [ 'BasicField', 'CF.MyField', ],
-    );
-
-In this case, C<from> and C<to> are expected to be valid queue names.  As
-above, C<from> may also be C<*>. All following must_be and must_not_be features
-work with queues as well.
-
 =head2 Requiring Any Value
 
 Below is an example which requires 1) time worked and filling in a custom field
@@ -321,65 +309,6 @@ sub RequiredFields {
     return (\@core, \@cfs, \%cf_must_values);
 }
 
-sub QueueRequiredFields {
-    my $self  = shift;
-    my %args  = (
-        Ticket  => undef,
-        To      => undef,
-        @_,
-    );
-
-    my ($from, $to);
-    $from = $args{Ticket}->QueueObj->Name;
-
-    my $to_obj = RT::Queue->new( $args{Ticket}->CurrentUser );
-    $to_obj->Load( $args{To} );
-    return ([], []) unless $to_obj->id;
-    $to = $to_obj->Name;
-
-    return ([], []) unless $from and $to;
-
-    my %config = $self->QueueConfig;
-    return ([], []) unless %config;
-
-    # No transition.
-    return ([], []) if $from eq $to;
-
-    my $required = $config{"$from -> $to"}
-                || $config{"* -> $to"}
-                || $config{"$from -> *"}
-                || [];
-
-    my %core_supported = map { $_ => 1 } @CORE_SUPPORTED;
-
-    my @core = grep { !/^CF\./i && $core_supported{$_} } @$required;
-    my @cfs  =  map { /^CF\.(.+)$/i; $1; }
-               grep { /^CF\./i } @$required;
-
-    # Pull out any must_be or must_not_be rules
-    my %cf_must_values = ();
-    foreach my $cf (@cfs){
-        if ( $config{"CF.$cf"} ){
-            my $transition = $config{"CF.$cf"}->{'transition'};
-            unless ( $transition ){
-                RT->Logger->error("No transition defined in must_be or must_not_be rules for $cf");
-                next;
-            }
-
-            if ( $transition eq "$from -> $to"
-                 || $transition eq "* -> $to"
-                 || $transition eq "$from -> *" ) {
-
-                $cf_must_values{$cf} = $config{"CF.$cf"};
-            }
-        }
-    }
-
-    return (\@core, \@cfs, \%cf_must_values);
-}
-
-
-
 =head3 CheckMandatoryFields
 
 Pulls core and custom mandatory fields from the configuration and
@@ -412,86 +341,7 @@ sub CheckMandatoryFields {
         To      => undef,
         @_,
     );
-
-    my $ARGSRef = $args{ARGSRef};
-
-    my @errors;
-    my $CurrentUser;
-
-    unless ( $args{Ticket} || $args{Queue} ) {
-        $RT::Logger->error("CheckMandatoryFields requires a Ticket object or a Queue object");
-        return \@errors;
-    }
-
-    $CurrentUser = $args{Ticket} ? $args{Ticket}->CurrentUser : $args{Queue}->CurrentUser;
-
-    # Check queue change fields if changing queue
-    my $new_queue = $ARGSRef->{Queue};
-    if ( $new_queue && $args{Ticket} && $args{Ticket}->Queue != $new_queue ) {
-        my ($core, $cfs, $must_values) = $self->QueueRequiredFields(
-            Ticket  => $args{'Ticket'},
-            To      => $args{ARGSRef}->{Queue},
-        );
-
-        if ( @$core && @$cfs ) {
-            my $new_queue_obj = RT::Queue->new( $CurrentUser );
-            $new_queue_obj->Load( $new_queue );
-            push @errors, @{ $self->_CheckMandatoryFields(
-                    %args,
-                    TransitionType => $CurrentUser->loc('Queue'),
-                    NewValue => $new_queue_obj->Name,
-                    CoreFields => $core,
-                    CustomFields => $cfs,
-                    MustValues => $must_values,
-                ) };
-        }
-    }
-
-    # Check standard status change fields
-    my ($core, $cfs, $must_values) = $self->RequiredFields(
-        Ticket  => $args{'Ticket'},
-        Queue   => $args{'Queue'} ? $args{'Queue'}->Name : undef,
-        From    => $args{'From'},
-        To      => $args{'To'},
-    );
-
-    if ( @$core && @$cfs ) {
-        push @errors, @{ $self->_CheckMandatoryFields(
-                %args,
-                TransitionType => $CurrentUser->loc('Status'),
-                NewValue => $CurrentUser->loc($ARGSRef->{Status}),
-                CoreFields => $core,
-                CustomFields => $cfs,
-                MustValues => $must_values,
-            ) };
-    }
-
-    return \@errors;
-}
-
-sub _CheckMandatoryFields {
-    my $self = shift;
-
-    my %args = (
-        TransitionType => undef,
-        NewValue => undef,
-        CoreFields => undef,
-        CustomFields => undef,
-        MustValues => undef,
-        @_,
-    );
-
-    my $ARGSRef = $args{ARGSRef};
-
-    # Convenience varialbes
-    my ( $type, $new_value, $core, $cfs, $must_values ) = (
-        $args{TransitionType},
-        $args{NewValue},
-        $args{CoreFields},
-        $args{CustomFields},
-        $args{MustValues},
-    );
-
+    my $ARGSRef = $args{'ARGSRef'};
     my @errors;
 
     # Some convenience variables set depending on what gets passed
@@ -509,6 +359,15 @@ sub _CheckMandatoryFields {
         return \@errors;
     }
 
+    my ($core, $cfs, $must_values) = $self->RequiredFields(
+        Ticket  => $args{'Ticket'},
+        Queue   => $args{'Queue'} ? $args{'Queue'}->Name : undef,
+        From    => $args{'From'},
+        To      => $args{'To'},
+    );
+
+    return \@errors unless @$core or @$cfs;
+
     # Check core fields, after canonicalization for update
     for my $field (@$core) {
 
@@ -526,8 +385,8 @@ sub _CheckMandatoryFields {
 
         (my $label = $field) =~ s/(?<=[a-z])(?=[A-Z])/ /g; # /
         push @errors,
-          $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
-                                     $label, $CurrentUser->loc($type), $new_value);
+          $CurrentUser->loc("[_1] is required when changing Status to [_2]",
+                                     $label, $CurrentUser->loc($ARGSRef->{Status}));
     }
 
     return \@errors unless @$cfs;
@@ -593,13 +452,13 @@ sub _CheckMandatoryFields {
                 my $valid_values = join ", ", @must_be;
                 if ( @must_be > 1 ){
                     push @errors,
-                        $CurrentUser->loc("[_1] must be one of: [_2] when changing [_3] to [_4]",
-                        $cf->Name, $valid_values, $type, $new_value);
+                        $CurrentUser->loc("[_1] must be one of: [_3] when changing Status to [_2]",
+                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
                 }
                 else{
                     push @errors,
-                        $CurrentUser->loc("[_1] must be [_2] when changing [_3] to [_4]",
-                        $cf->Name, $valid_values, $type, $new_value);
+                        $CurrentUser->loc("[_1] must be [_3] when changing Status to [_2]",
+                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
                 }
                 next;
             }
@@ -612,13 +471,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: [_2] when changing [_3] to [_4]",
-                        $cf->Name, $valid_values, $type, $new_value);
+                        $CurrentUser->loc("[_1] must not be one of: [_3] when changing Status to [_2]",
+                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
                 }
                 else{
                     push @errors,
-                        $CurrentUser->loc("[_1] must not be [_2] when changing [_3] to [_4]",
-                        $cf->Name, $valid_values, $type, $new_value);
+                        $CurrentUser->loc("[_1] must not be [_3] when changing Status to [_2]",
+                        $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
                 }
                 next;
             }
@@ -632,8 +491,8 @@ sub _CheckMandatoryFields {
         next if $args{'Ticket'} && $cf->ValuesForObject($args{'Ticket'})->Count;
 
         push @errors,
-          $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
-              $cf->Name, $type, $new_value);
+          $CurrentUser->loc("[_1] is required when changing Status to [_2]",
+                                     $cf->Name, $CurrentUser->loc($ARGSRef->{Status}));
     }
 
     return \@errors;
@@ -658,12 +517,6 @@ sub Config {
     return;
 }
 
-sub QueueConfig {
-    my $self  = shift;
-    my %config = RT->Config->Get('MandatoryOnQueueTransition');
-    return %config;
-}
-
 =head1 TODO
 
 =over 4
diff --git a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
index c3d08b5..1757bb1 100644
--- a/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
+++ b/lib/RT/Extension/MandatoryOnTransition/Test.pm.in
@@ -48,4 +48,14 @@ CONFIG
     require RT::Extension::MandatoryOnTransition;
 }
 
+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)
+            ? 1 : 0;
+}
+
 1;
diff --git a/xt/mandatory_on_create.t b/xt/mandatory_on_create.t
index 6511c86..a635e4f 100644
--- a/xt/mandatory_on_create.t
+++ b/xt/mandatory_on_create.t
@@ -32,7 +32,7 @@ diag "Test mandatory fields on create";
                           fields => { Queue => 'General',},
                         }, 'Click button to create ticket');
 
-    if (RT::Handle::cmp_version( '4.4.0', $RT::VERSION) <= 0) {
+    if (RT::Extension::MandatoryOnTransition::Test::RTAtorNewerThan('4.4.0')){
         $m->title_is('Create a new ticket in General');
     }
     else{

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


More information about the Bps-public-commit mailing list