[Rt-commit] rt branch, 4.4/default-cfv-dupes, updated. rt-4.4.1-126-ge9abdf5

Jim Brandt jbrandt at bestpractical.com
Fri Feb 24 16:49:52 EST 2017


The branch, 4.4/default-cfv-dupes has been updated
       via  e9abdf5aaf16268db23154b4f6b513e429a4d74a (commit)
       via  2f9f65fa36656e315ecfb04abfcca433e5a34e68 (commit)
      from  999d46443902b30dee83903550c33fab273a99f4 (commit)

Summary of changes:
 lib/RT/Interface/Web.pm                            | 14 +++----
 .../html/Admin/Assets/Catalogs/DefaultValues.html  |  5 +--
 share/html/Admin/Queues/DefaultValues.html         |  6 +--
 t/api/interface_web.t                              | 43 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 14 deletions(-)
 create mode 100644 t/api/interface_web.t

- Log -----------------------------------------------------------------
commit 2f9f65fa36656e315ecfb04abfcca433e5a34e68
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Feb 24 16:46:54 2017 -0500

    Return the alpha sorted default group name along with the success value
    
    Since the validator function already sorts the submitted values,
    return the default group name to standardize the default behavior
    in one place.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 1e863d6..1e164ca 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3095,6 +3095,9 @@ sub _ValidateConsistentCustomFieldValues {
     my $ok = 1;
 
     my @groupings = sort keys %$args;
+    return ($ok, undef) unless @groupings;
+    my $default_grouping = $groupings[0]; # Default to use if multiple are submitted
+
     if (@groupings > 1) {
         # Check for consistency, in case of JS fail
         for my $key (qw/AddValue Value Values DeleteValues DeleteValueIds/) {
@@ -3108,13 +3111,13 @@ sub _ValidateConsistentCustomFieldValues {
                     $a ne $b
                 } @{$base}, @{$other};
 
-                warn "CF $cf submitted with multiple differing values";
+                RT::Logger->warn("CF $cf submitted with multiple differing values");
                 $ok = 0;
             }
         }
     }
 
-    return $ok;
+    return ($ok, $default_grouping);
 }
 
 sub ProcessObjectCustomFieldUpdates {
@@ -3147,12 +3150,9 @@ sub ProcessObjectCustomFieldUpdates {
                     next;
                 }
 
-                _ValidateConsistentCustomFieldValues($cf, $custom_fields_to_mod{$class}{$id}{$cf});
-
                 # In the case of inconsistent CFV submission,
-                # we'll pick the 1st grouping in the hash, alphabetically
-
-                my $grouping = (sort keys %{ $custom_fields_to_mod{$class}{$id}{$cf} })[0];
+                # we'll get the 1st grouping in the hash, alphabetically
+                my ($ret, $grouping) = _ValidateConsistentCustomFieldValues($cf, $custom_fields_to_mod{$class}{$id}{$cf});
 
                 push @results,
                     _ProcessObjectCustomFieldUpdates(
diff --git a/share/html/Admin/Assets/Catalogs/DefaultValues.html b/share/html/Admin/Assets/Catalogs/DefaultValues.html
index b523b51..cceaf15 100644
--- a/share/html/Admin/Assets/Catalogs/DefaultValues.html
+++ b/share/html/Admin/Assets/Catalogs/DefaultValues.html
@@ -81,12 +81,11 @@ if ( $ARGS{Reset} ) {
 elsif ( $ARGS{Update} ) {
     my $cfs = _ParseObjectCustomFieldArgs(\%ARGS)->{'RT::Asset'}{0};
     for my $cf_id (keys %$cfs) {
-        _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
 
         # In the case of inconsistent CFV submission,
-        # we'll pick the 1st grouping in the hash, alphabetically
+        # we'll get the 1st grouping in the hash, alphabetically
+        my ($ret, $grouping_name) = _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
 
-        my $grouping_name = (sort keys %{ $cfs->{$cf_id} })[0];
         my $grouping = $cfs->{$cf_id}{$grouping_name};
         my $value = $grouping->{Value} // $grouping->{Values};
 
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 7a9d145..f82c926 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -158,12 +158,10 @@ elsif ( $ARGS{Update} ) {
     }
     my $cfs = _ParseObjectCustomFieldArgs(\%ARGS)->{'RT::Ticket'}{0};
     for my $cf_id (keys %$cfs) {
-        _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
-
         # In the case of inconsistent CFV submission,
-        # we'll pick the 1st grouping in the hash, alphabetically
+        # we'll get the 1st grouping in the hash, alphabetically
+        my ($ret, $grouping_name) = _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
 
-        my $grouping_name = (sort keys %{ $cfs->{$cf_id} })[0];
         my $grouping = $cfs->{$cf_id}{$grouping_name};
         my $value = $grouping->{Value} // $grouping->{Values};
 

commit e9abdf5aaf16268db23154b4f6b513e429a4d74a
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Feb 24 16:49:32 2017 -0500

    Tests for _ValidateConsistentCustomFieldValues

diff --git a/t/api/interface_web.t b/t/api/interface_web.t
new file mode 100644
index 0000000..154ffb0
--- /dev/null
+++ b/t/api/interface_web.t
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use RT::Test nodb => 1, tests => 5;
+use Test::Warn;
+use RT::Interface::Web; # This gets us HTML::Mason::Commands
+
+{
+    my $cf = 2;
+    my %args = (
+        'GroupingName' => {
+            'Value'       => "bar",
+            'Value-Magic' => 1
+        },
+    );
+
+    my ($ret, $grouping) = HTML::Mason::Commands::_ValidateConsistentCustomFieldValues($cf, \%args);
+
+    ok ( $ret, 'No duplicates found');
+    is ( $grouping, 'GroupingName', 'Grouping is GroupingName');
+}
+
+{
+    my $cf = 2;
+    my %args = (
+        'GroupingName'    => {
+            'Value'       => "foo",
+            'Value-Magic' => 1
+        },
+        'AnotherGrouping' => {
+            'Value'       => "bar",
+            'Value-Magic' => 1
+        },
+    );
+
+    my ($ret, $grouping);
+    warning_like {
+        ($ret, $grouping) = HTML::Mason::Commands::_ValidateConsistentCustomFieldValues($cf, \%args);
+    } qr/^CF 2 submitted with multiple differing values/i;
+
+    ok ( !$ret, 'Caught duplicate values');
+    is ( $grouping, 'AnotherGrouping', 'Defaulted to AnotherGrouping');
+}

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


More information about the rt-commit mailing list