[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, must-and-must-not-be, updated. 0.09_01-19-gff53576
Jim Brandt
jbrandt at bestpractical.com
Thu Jun 23 11:45:57 EDT 2016
The branch, must-and-must-not-be has been updated
via ff535764efd0e3c58e828168320a218b64ae8b4b (commit)
via fc8347f1ea9678f83936e9f27c9e4b0b4ec12458 (commit)
via da5daf3335ea12119c225472fe92f2f7b828d399 (commit)
via 6d1615ddf25a3a4eaa16c2501748bceafa7fc34d (commit)
via 83ef77a91649dc9001a2761e738a7a77527b53db (commit)
from babe91626fdd3c8463117ec31bcc2e10612ea23d (commit)
Summary of changes:
README | 16 ++++++++---
lib/RT/Extension/MandatoryOnTransition.pm | 46 +++++++++++++++++++++----------
xt/required_fields.t | 20 +++++++-------
3 files changed, 53 insertions(+), 29 deletions(-)
- Log -----------------------------------------------------------------
commit 83ef77a91649dc9001a2761e738a7a77527b53db
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 23 09:52:32 2016 -0400
Update test to match test config changes
diff --git a/xt/required_fields.t b/xt/required_fields.t
index 3c7a91d..8d91b81 100644
--- a/xt/required_fields.t
+++ b/xt/required_fields.t
@@ -23,11 +23,11 @@ diag "Test RequiredFields without a ticket";
is( $core->[0], 'TimeWorked', 'Got TimeWorked for required core');
is( $cf->[0], 'Test Field', 'Got Test Field for required custom field');
- is( (ref $must_values->{'Test Field2'}), 'HASH', 'Got a hash for Test Field2 must values');
- is( (ref $must_values->{'Test Field2'}{'must_be'}), 'ARRAY', 'Got an array for must be values');
- is( (ref $must_values->{'Test Field2'}{'must_not_be'}), 'ARRAY', 'Got an array for must not be values');
- is( $must_values->{'Test Field2'}{'must_be'}->[0], 'normal', "First must be value is 'normal'");
- is( $must_values->{'Test Field2'}{'must_not_be'}->[0], 'down', "First must not be value is 'down'");
+ is( (ref $must_values->{'Test Field3'}), 'HASH', 'Got a hash for Test Field3 must values');
+ is( (ref $must_values->{'Test Field3'}{'must_be'}), 'ARRAY', 'Got an array for must be values');
+ is( (ref $must_values->{'Test Field4'}{'must_not_be'}), 'ARRAY', 'Got an array for must not be values');
+ is( $must_values->{'Test Field3'}{'must_be'}->[0], 'normal', "First must be value is 'normal'");
+ is( $must_values->{'Test Field4'}{'must_not_be'}->[0], 'down', "First must not be value is 'down'");
}
diag "Test RequiredFields with a ticket";
@@ -48,11 +48,11 @@ diag "Test RequiredFields with a ticket";
is( $core->[0], 'TimeWorked', 'Got TimeWorked for required core');
is( $cf->[0], 'Test Field', 'Got Test Field for required custom field');
- is( (ref $must_values->{'Test Field2'}), 'HASH', 'Got a hash for Test Field2 must values');
- is( (ref $must_values->{'Test Field2'}{'must_be'}), 'ARRAY', 'Got an array for must be values');
- is( (ref $must_values->{'Test Field2'}{'must_not_be'}), 'ARRAY', 'Got an array for must not be values');
- is( $must_values->{'Test Field2'}{'must_be'}->[0], 'normal', "First must be value is 'normal'");
- is( $must_values->{'Test Field2'}{'must_not_be'}->[0], 'down', "First must not be value is 'down'");
+ is( (ref $must_values->{'Test Field3'}), 'HASH', 'Got a hash for Test Field3 must values');
+ is( (ref $must_values->{'Test Field3'}{'must_be'}), 'ARRAY', 'Got an array for must be values');
+ is( (ref $must_values->{'Test Field4'}{'must_not_be'}), 'ARRAY', 'Got an array for must not be values');
+ is( $must_values->{'Test Field3'}{'must_be'}->[0], 'normal', "First must be value is 'normal'");
+ is( $must_values->{'Test Field4'}{'must_not_be'}->[0], 'down', "First must not be value is 'down'");
}
done_testing;
commit 6d1615ddf25a3a4eaa16c2501748bceafa7fc34d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 23 10:59:49 2016 -0400
Fix incorrect sample configuration
diff --git a/README b/README
index 1ea76f0..8ff74b2 100644
--- a/README
+++ b/README
@@ -128,14 +128,14 @@ CONFIGURATION
Sometimes you want to restrict a transition if a field has a specific
value (maybe a ticket can't be resolved if System Status = down) or
require a specific value to to allow a transition (ticket can't be
- resolved unless System Status = normal). To enforce specific values, you
+ resolved unless a problem was fixed). To enforce specific values, you
can add the following:
Set( %MandatoryOnTransition,
Helpdesk => {
- '* -> resolved' => ['TimeWorked', 'CF.Some Field1', 'CF.Some Field2'],
- 'CF.Test Field2' => { transition => '* -> resolved', must_be => ['normal', 'restored'] },
- 'CF.Test Field3' => { transition => '* -> resolved', must_not_be => ['reduced', 'down']}
+ '* -> resolved' => ['TimeWorked', 'CF.Resolution', 'CF.System Status'],
+ 'CF.Resolution' => { transition => '* -> resolved', must_be => ['fixed', 'not an issue'] },
+ 'CF.System Status' => { transition => '* -> resolved', must_not_be => ['reduced', 'down']}
},
);
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index b073ffd..49c043b 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -157,14 +157,14 @@ C<perldoc /opt/rt4/etc/RT_Config.pm>.
Sometimes you want to restrict a transition if a field has a specific
value (maybe a ticket can't be resolved if System Status = down) or
require a specific value to to allow a transition (ticket can't be
-resolved unless System Status = normal). To enforce specific values, you
+resolved unless a problem was fixed). To enforce specific values, you
can add the following:
Set( %MandatoryOnTransition,
Helpdesk => {
- '* -> resolved' => ['TimeWorked', 'CF.Some Field1', 'CF.Some Field2'],
- 'CF.Test Field2' => { transition => '* -> resolved', must_be => ['normal', 'restored'] },
- 'CF.Test Field3' => { transition => '* -> resolved', must_not_be => ['reduced', 'down']}
+ '* -> resolved' => ['TimeWorked', 'CF.Resolution', 'CF.System Status'],
+ 'CF.Resolution' => { transition => '* -> resolved', must_be => ['fixed', 'not an issue'] },
+ 'CF.System Status' => { transition => '* -> resolved', must_not_be => ['reduced', 'down']}
},
);
commit da5daf3335ea12119c225472fe92f2f7b828d399
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 23 11:16:23 2016 -0400
Clean up must values with temp arrays
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 49c043b..c6f97ef 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -303,7 +303,7 @@ sub RequiredFields {
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");
+ RT->Logger->error("No transition defined in must_be or must_not_be rules for $cf");
next;
}
@@ -452,11 +452,13 @@ sub CheckMandatoryFields {
unless defined $cf_value;
if ( exists $must_values->{$cf->Name}{'must_be'} ){
+ my @must_be = @{$must_values->{$cf->Name}{'must_be'}};
+
# OK if it's defined and is one of the specified values
- next if defined $cf_value and grep { $cf_value eq $_ } @{$must_values->{$cf->Name}{'must_be'}};
- my $valid_values = join ", ", @{$must_values->{$cf->Name}{'must_be'}};
+ next if defined $cf_value and grep { $cf_value eq $_ } @must_be;
+ my $valid_values = join ", ", @must_be;
my $one_of = '';
- $one_of = " one of:" if @{$must_values->{$cf->Name}{'must_be'}} > 1;
+ $one_of = " one of:" 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);
@@ -464,11 +466,13 @@ sub CheckMandatoryFields {
}
if ( exists $must_values->{$cf->Name}{'must_not_be'} ){
+ my @must_not_be = @{$must_values->{$cf->Name}{'must_not_be'}};
+
# OK if it's defined and _not_ in the list
- next if defined $cf_value and !grep { $cf_value eq $_ } @{$must_values->{$cf->Name}{'must_not_be'}};
- my $valid_values = join ", ", @{$must_values->{$cf->Name}{'must_not_be'}};
+ next if defined $cf_value and !grep { $cf_value eq $_ } @must_not_be;
+ my $valid_values = join ", ", @must_not_be;
my $one_of = '';
- $one_of = " one of:" if @{$must_values->{$cf->Name}{'must_not_be'}} > 1;
+ $one_of = " one of:" 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);
commit fc8347f1ea9678f83936e9f27c9e4b0b4ec12458
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 23 11:22:46 2016 -0400
Add some new items to todo list
diff --git a/README b/README
index 8ff74b2..51fce9e 100644
--- a/README
+++ b/README
@@ -238,6 +238,14 @@ TODO
Enforcement on other update pages
SelfService - can't do it without patches to <form> POST + additional callbacks
+ Full Validation of Configuration
+ Check that all CFs are actually CFs applied to the indicated queues (or global). Also
+ validate additional CF's with "must" configuration are defined in a transition.
+
+ Allow empty values in "must" configuration
+ When defining a list of "must be" or "must not be" values, there may be use cases where
+ an empty value could be valid. Provide a way to specify and allow this.
+
AUTHOR
Best Practical Solutions, LLC <modules at bestpractical.com>
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index c6f97ef..7182188 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -527,6 +527,16 @@ sub Config {
SelfService - can't do it without patches to <form> POST + additional callbacks
+=item Full Validation of Configuration
+
+ Check that all CFs are actually CFs applied to the indicated queues (or global). Also
+ validate additional CF's with "must" configuration are defined in a transition.
+
+=item Allow empty values in "must" configuration
+
+ When defining a list of "must be" or "must not be" values, there may be use cases where
+ an empty value could be valid. Provide a way to specify and allow this.
+
=back
=head1 AUTHOR
commit ff535764efd0e3c58e828168320a218b64ae8b4b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 23 11:43:06 2016 -0400
Confirm Ticket is available before calling methods
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 7182188..3600661 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -297,7 +297,7 @@ sub RequiredFields {
my @cfs = map { /^CF\.(.+)$/i; $1; }
grep { /^CF\./i } @$required;
- # Pull out an must be or must not be rules
+ # Pull out any must_be or must_not_be rules
my %cf_must_values = ();
foreach my $cf (@cfs){
if ( $config{"CF.$cf"} ){
@@ -447,9 +447,11 @@ sub CheckMandatoryFields {
# Check for specific values
if ( exists $must_values->{$cf->Name} ){
my $cf_value = $value;
- # Fetch the current value if we didn't receive a new one
- $cf_value = $args{'Ticket'}->FirstCustomFieldValue($cf->Name)
- unless defined $cf_value;
+
+ if ( not defined $cf_value and $args{'Ticket'} ){
+ # Fetch the current value if we didn't receive a new one
+ $cf_value = $args{'Ticket'}->FirstCustomFieldValue($cf->Name);
+ }
if ( exists $must_values->{$cf->Name}{'must_be'} ){
my @must_be = @{$must_values->{$cf->Name}{'must_be'}};
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list