[Rt-commit] rt branch, 4.4/default-cfv-dupes, updated. rt-4.4.1-124-g999d464
Shawn Moore
shawn at bestpractical.com
Tue Jan 24 17:07:41 EST 2017
The branch, 4.4/default-cfv-dupes has been updated
via 999d46443902b30dee83903550c33fab273a99f4 (commit)
from cfacf290d01a89e2a8fccbda4e4a83fe84b045bf (commit)
Summary of changes:
lib/RT/Interface/Web.pm | 58 ++++++++++++++--------
.../html/Admin/Assets/Catalogs/DefaultValues.html | 13 +++--
share/html/Admin/Queues/DefaultValues.html | 13 +++--
3 files changed, 54 insertions(+), 30 deletions(-)
- Log -----------------------------------------------------------------
commit 999d46443902b30dee83903550c33fab273a99f4
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Jan 24 21:52:25 2017 +0000
Warn about differing CF values on Defaults pages
This can happen when the same custom field appears in multiple different
groupings, and the JavaScript meant to keep those fields in sync
(sync_grouped_custom_fields) didn't.
By factoring out a _ValidateConsistentCustomFieldValues function, we can
reuse the warning logic that the ordinary custom field processor already
uses.
This also improves parity between ordinary custom field processing and
queue/catalog default processing for which value is picked (the first
grouping, alphabetically)
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 1fc7550..1e863d6 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3089,6 +3089,34 @@ sub ProcessTicketReminders {
return @results;
}
+sub _ValidateConsistentCustomFieldValues {
+ my $cf = shift;
+ my $args = shift;
+ my $ok = 1;
+
+ my @groupings = sort keys %$args;
+ if (@groupings > 1) {
+ # Check for consistency, in case of JS fail
+ for my $key (qw/AddValue Value Values DeleteValues DeleteValueIds/) {
+ my $base = $args->{$groupings[0]}{$key};
+ $base = [ $base ] unless ref $base;
+ for my $grouping (@groupings[1..$#groupings]) {
+ my $other = $args->{$grouping}{$key};
+ $other = [ $other ] unless ref $other;
+ next unless grep {$_} List::MoreUtils::pairwise {
+ no warnings qw(uninitialized);
+ $a ne $b
+ } @{$base}, @{$other};
+
+ warn "CF $cf submitted with multiple differing values";
+ $ok = 0;
+ }
+ }
+ }
+
+ return $ok;
+}
+
sub ProcessObjectCustomFieldUpdates {
my %args = @_;
my $ARGSRef = $args{'ARGSRef'};
@@ -3118,34 +3146,24 @@ sub ProcessObjectCustomFieldUpdates {
$RT::Logger->warning("Couldn't load custom field #$cf");
next;
}
- my @groupings = sort keys %{ $custom_fields_to_mod{$class}{$id}{$cf} };
- if (@groupings > 1) {
- # Check for consistency, in case of JS fail
- for my $key (qw/AddValue Value Values DeleteValues DeleteValueIds/) {
- my $base = $custom_fields_to_mod{$class}{$id}{$cf}{$groupings[0]}{$key};
- $base = [ $base ] unless ref $base;
- for my $grouping (@groupings[1..$#groupings]) {
- my $other = $custom_fields_to_mod{$class}{$id}{$cf}{$grouping}{$key};
- $other = [ $other ] unless ref $other;
- warn "CF $cf submitted with multiple differing values"
- if grep {$_} List::MoreUtils::pairwise {
- no warnings qw(uninitialized);
- $a ne $b
- } @{$base}, @{$other};
- }
- }
- # We'll just be picking the 1st grouping in the hash, alphabetically
- }
+
+ _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];
+
push @results,
_ProcessObjectCustomFieldUpdates(
Prefix => GetCustomFieldInputNamePrefix(
Object => $Object,
CustomField => $CustomFieldObj,
- Grouping => $groupings[0],
+ Grouping => $grouping,
),
Object => $Object,
CustomField => $CustomFieldObj,
- ARGS => $custom_fields_to_mod{$class}{$id}{$cf}{ $groupings[0] },
+ ARGS => $custom_fields_to_mod{$class}{$id}{$cf}{ $grouping },
);
}
}
diff --git a/share/html/Admin/Assets/Catalogs/DefaultValues.html b/share/html/Admin/Assets/Catalogs/DefaultValues.html
index 398a732..b523b51 100644
--- a/share/html/Admin/Assets/Catalogs/DefaultValues.html
+++ b/share/html/Admin/Assets/Catalogs/DefaultValues.html
@@ -81,11 +81,14 @@ if ( $ARGS{Reset} ) {
elsif ( $ARGS{Update} ) {
my $cfs = _ParseObjectCustomFieldArgs(\%ARGS)->{'RT::Asset'}{0};
for my $cf_id (keys %$cfs) {
- # there may be multiple values submitted, pull out only the first,
- # as our JS will make sure the values are synced
- my %names = %{ $cfs->{$cf_id} };
- my $value = $names{ (keys %names)[0] }{Value}
- // $names{ (keys %names)[0] }{Values};
+ _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
+
+ # In the case of inconsistent CFV submission,
+ # we'll pick the 1st grouping in the hash, alphabetically
+
+ my $grouping_name = (sort keys %{ $cfs->{$cf_id} })[0];
+ my $grouping = $cfs->{$cf_id}{$grouping_name};
+ my $value = $grouping->{Value} // $grouping->{Values};
my $cf = RT::CustomField->new($session{CurrentUser});
$cf->Load($cf_id);
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 8ac214f..7a9d145 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -158,11 +158,14 @@ elsif ( $ARGS{Update} ) {
}
my $cfs = _ParseObjectCustomFieldArgs(\%ARGS)->{'RT::Ticket'}{0};
for my $cf_id (keys %$cfs) {
- # there may be multiple values submitted, pull out only the first,
- # as our JS will make sure the values are synced
- my %names = %{ $cfs->{$cf_id} };
- my $value = $names{ (keys %names)[0] }{Value}
- // $names{ (keys %names)[0] }{Values};
+ _ValidateConsistentCustomFieldValues($cf_id, $cfs->{$cf_id});
+
+ # In the case of inconsistent CFV submission,
+ # we'll pick the 1st grouping in the hash, alphabetically
+
+ my $grouping_name = (sort keys %{ $cfs->{$cf_id} })[0];
+ my $grouping = $cfs->{$cf_id}{$grouping_name};
+ my $value = $grouping->{Value} // $grouping->{Values};
my $cf = RT::CustomField->new($session{CurrentUser});
$cf->Load($cf_id);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list