X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FElements%2FValidateCustomFields;h=68df407e5a9a2706c3fbaa9be0bc0a6a899761c6;hp=922b885f2d57336cbe199ccf8a2259598db056fe;hb=7322f2afedcc2f427e997d1535a503613a83f088;hpb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7 diff --git a/rt/share/html/Elements/ValidateCustomFields b/rt/share/html/Elements/ValidateCustomFields index 922b885f2..68df407e5 100644 --- a/rt/share/html/Elements/ValidateCustomFields +++ b/rt/share/html/Elements/ValidateCustomFields @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -48,62 +48,59 @@ <%INIT> my ($valid, @res) = (1, ()); $CustomFields->GotoFirstItem; + +my $CFArgs = _ParseObjectCustomFieldArgs( $ARGSRef )->{ref($Object)}{$Object->Id || 0} || {}; + while ( my $CF = $CustomFields->Next ) { - my $field = $NamePrefix . $CF->Id . "-Value"; + my $submitted = $CFArgs->{$CF->Id}; + # Pick the first grouping + $submitted = $submitted ? $submitted->{(keys %$submitted)[0]} : {}; - my $value; - if ($ARGSRef->{"${field}s-Magic"} and exists $ARGSRef->{"${field}s"}) { - $value = $ARGSRef->{"${field}s"}; + # If we don't have a value and we don't see the Magic, then we're not + # submitting a field. + next if not $ValidateUnsubmitted + and not exists $submitted->{"Value"} + and not exists $submitted->{"Upload"} + and not exists $submitted->{"Values"} + and not $submitted->{"Values-Magic"}; - # We only validate Single Combos -- multis can never be user input - next if ref $value; - } - else { - $value = $ARGSRef->{$field}; - } - $m->notes(('Field-' . $CF->Id) => $value); + # We only validate Single Combos -- multis can never be user input + next if $submitted->{"Values-Magic"} and exists $submitted->{"Values"} + and ref $submitted->{"Values"}; - my @values = (); - if ( ref $value eq 'ARRAY' ) { - @values = @$value; - } elsif ( $CF->Type =~ /text/i ) { - @values = ($value); - } else { - @values = split /\r*\n/, ( defined $value ? $value : ''); - } - @values = grep $_ ne '', - map { - s/\r+\n/\n/g; - s/^\s+//; - s/\s+$//; - $_; + $m->notes(('Field-' . $CF->Id) => $submitted->{Values} // $submitted->{Value}); + + my @values = _NormalizeObjectCustomFieldValue( + CustomField => $CF, + Value => ($submitted->{Values} // $submitted->{Value} // $submitted->{Upload}), + ); + if ($CF->Type =~ /^Date(?:Time)?$/) { + if (not @values) { + my $values = $Object->CustomFieldValues($CF->Id); + while (my $ocfv = $values->Next) { + push @values, $ocfv->Content; + } } - grep defined, @values; - @values = ('') unless @values; + @values = grep { + my $DateObj = RT::Date->new ( $session{'CurrentUser'} ); + $DateObj->Set( + Format => 'unknown', + Value => $_, + ($CF->Type eq "Date" ? (Timezone => 'utc') : ()) + ); + $DateObj->IsSet + } @values; + } + push @values, '' unless @values; for my $value( @values ) { if ($value) { - if ( $CF->Type eq 'IPAddress' ) { - use Regexp::Common qw(RE_net_IPv4); - my $ip = RT::ObjectCustomFieldValue->ParseIP( $value ); - unless ( $ip ) { - my $msg = - loc( "Input can not be parsed as an IP address" ); - $m->notes( ( 'InvalidField-' . $CF->Id ) => $msg ); - push @res, $msg; - $valid = 0; - } - } - elsif ( $CF->Type eq 'IPAddressRange' ) { - my ( $start_ip, $end_ip ) = - RT::ObjectCustomFieldValue->ParseIPRange($value); - unless ( $start_ip && $end_ip ) { - my $msg = - loc( "Input can not be parsed as an IP address range" ); - $m->notes( ( 'InvalidField-' . $CF->Id ) => $msg ); - push @res, $msg; - $valid = 0; - } + my $ref = { Content => $value }; + my ($ok, $msg) = $CF->_CanonicalizeValue( $ref ); + unless ($ok) { + $m->notes( ( 'InvalidField-' . $CF->Id ) => $msg ); + push @res, $CF->Name .': '. $msg; + $valid = 0; } } @@ -111,7 +108,7 @@ while ( my $CF = $CustomFields->Next ) { my $msg = loc("Input must match [_1]", $CF->FriendlyPattern); $m->notes( ('InvalidField-' . $CF->Id) => $msg ); - push @res, $msg; + push @res, $CF->Name .': '. $msg; $valid = 0; } } @@ -119,7 +116,8 @@ $m->notes('ValidFields', $valid); return wantarray? ($valid, @res): $valid; <%ARGS> +$Object => RT::Ticket->new( $session{'CurrentUser'}) $CustomFields $ARGSRef -$NamePrefix => "Object-RT::Ticket--CustomField-" +$ValidateUnsubmitted => 0