Skip to content

Commit

Permalink
Merge branch '6.0/ticket-update-validation'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Jan 13, 2025
2 parents d13d0e0 + 8b913d4 commit 30beec1
Show file tree
Hide file tree
Showing 24 changed files with 447 additions and 226 deletions.
32 changes: 32 additions & 0 deletions lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6479,6 +6479,38 @@ sub GetDefaultDashboard {
return $dashboard;
}

=head2 GetInvalidFields Object => $Object
Returns a list of fields that are marked as invalid by server.
=cut

sub GetInvalidFields {
my %args = @_;
my @fields;
foreach my $note ( keys %{$m->notes} ) {
if ( $note =~ /^InvalidField\-(\d+)(?:-(.+))?/ ) {
my $cf_id = $1;
my $grouping = $2;
my $cf = RT::CustomField->new($session{'CurrentUser'});
my ($ok, $msg) = $cf->Load($cf_id);
if ( $cf->Id ) {
push @fields,
GetCustomFieldInputName(
CustomField => $cf,
Grouping => $grouping,
# Do not pass misleading ticket object in case it's a txn cf.
$cf->ObjectTypeFromLookupType eq ref $args{Object} ? ( Object => $args{Object} ) : (),
);
}
else {
RT->Logger->error("Unable to load custom field $cf_id: $msg") unless $ok;
}
}
}
return @fields;
}

package RT::Interface::Web;
RT::Base->_ImportOverlays();

Expand Down
11 changes: 11 additions & 0 deletions share/html/Asset/Create.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@
}
} else {
push @results, @cf_errors;

if ( !$cf_ok && RT::Interface::Web::RequestENV('HTTP_HX_BOOSTED') ) {
$r->headers_out->{'HX-Trigger'} = JSON(
{
actionsChanged => { messages => \@results, isWarning => 1 },
validationFailed => [ GetInvalidFields( Object => RT::Asset->new( $session{CurrentUser} ) ) ],
},
ascii => 1,
);
Abort( loc("Validation error"), Code => HTTP::Status::HTTP_UNPROCESSABLE_CONTENT );
}
}
}

Expand Down
24 changes: 19 additions & 5 deletions share/html/Elements/EditCustomField
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ $m->comp(
CustomField => $CustomField,
Name => $Name,
$CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
DescribedBy => $CFHintId,
AddClass => $AddClass,
);

if (my $msg = $m->notes('InvalidField-' . $CustomField->Id)) {
if ( $error_msg ) {
</%perl>
<span class="cfinvalidfield my-1 d-inline-block"><% $msg %></span>
<span id="<% $CFHintId %>" class="form-text invalid-feedback cfinvalidfield d-inline-block"><% $error_msg %></span>
% } elsif ($ShowHints and $CustomField->FriendlyPattern) {
<span class="cfhints my-1 d-inline-block">
<span id="<% $CFHintId %>" class="form-text cfhints d-inline-block">
<% $CustomField->FriendlyPattern %>
</span>
% }
Expand Down Expand Up @@ -106,6 +108,13 @@ if ( !$NamePrefix ) {
$Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
}

my $CFHintId;
my $cf_name_prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );

if ($ShowHints and $CustomField->FriendlyPattern) {
$CFHintId = $cf_name_prefix . 'Hint';
}

# Always fill $Default with submited values if it's empty
if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
my %TOP = %$DECODED_ARGS;
Expand All @@ -116,8 +125,7 @@ if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
// $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
}
else {
my $prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
$Default //= $TOP{ $prefix . 'Values' } // $TOP{ $prefix . 'Value' };
$Default //= $TOP{ $cf_name_prefix . 'Values' } // $TOP{ $cf_name_prefix . 'Value' };
}
}

Expand Down Expand Up @@ -164,6 +172,12 @@ if ( RT->Config->Get('ExternalInfoPriority') && $Object && $Object->isa('RT::Use
}
}

my ($error_msg, $AddClass);
if ( $m->notes('InvalidField-' . $CustomField->Id . ($Grouping ? "-$Grouping" : '') ) ) {
$error_msg = $m->notes( 'InvalidField-' . $CustomField->Id . ($Grouping ? "-$Grouping" : '') );
$AddClass = 'is-invalid';
}

my $EditComponent = "EditCustomField$Type";
$m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$EditComponent = "EditCustomField$Type" unless $m->comp_exists($EditComponent);
Expand Down
13 changes: 11 additions & 2 deletions share/html/Elements/EditCustomFieldAutocomplete
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control"><% $Default || '' %></textarea>
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% $Default || '' %></textarea>

<script type="text/javascript">
var id = <% "$name" |n,j%>;
Expand All @@ -78,7 +81,11 @@ jQuery('#'+id).autocomplete( {
}
);
% } else {
<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control" value="<% $Default || '' %>"/>
<input type="text" id="<% $name %>" name="<% $name %>" \
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>" value="<% $Default || '' %>"/>
<script type="text/javascript">
var id = <% $name |n,j%>;
id = id.replace(/:/g,'\\:');
Expand Down Expand Up @@ -114,4 +121,6 @@ $Values => undef
$Multiple => undef
$Rows => undef
$Cols => undef
$DescribedBy => undef
$AddClass => undef
</%ARGS>
8 changes: 7 additions & 1 deletion share/html/Elements/EditCustomFieldBinary
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
% while ( $Values and my $value = $Values->Next ) {
%# XXX - let user download the file(s) here?
<div class="form-check">
<input type="checkbox" id="<% $delete_name . $value->id %>" name="<%$delete_name%>" class="form-check-input CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>">
<input type="checkbox" id="<% $delete_name . $value->id %>" name="<%$delete_name%>" \
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
class="form-check-input CF-<%$CustomField->id%>-Edit <% $AddClass // '' %>" value="<% $value->Id %>">
<label class="form-check-label" for="<% $delete_name . $value->id %>">
% if (my $url = RT->System->ExternalStorageURLFor($value)) {
<a hx-boost="false" href="<%$url%>">
Expand Down Expand Up @@ -83,4 +87,6 @@ $Name => undef
$Default => undef
$Values => undef
$MaxValues => undef
$DescribedBy => undef
$AddClass => undef
</%ARGS>
8 changes: 7 additions & 1 deletion share/html/Elements/EditCustomFieldCombobox
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
%# END BPS TAGGED BLOCK }}}
% while ($Values and my $value = $Values->Next and $Multiple) {
<div class="form-check">
<input type="checkbox" name="<% $delete_name %>" id="<% $delete_name %>-<% $value->Id %>" value="<% $value->Id %>" class="CF-<%$CustomField->id%>-Edit checkbox form-check-input" />
<input type="checkbox" name="<% $delete_name %>" id="<% $delete_name %>-<% $value->Id %>" \
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
value="<% $value->Id %>" class="CF-<%$CustomField->id%>-Edit checkbox form-check-input <% $AddClass // '' %>" />
<label class="form-check-label" for="<% $delete_name %>-<% $value->Id %>"><% $value->Content %></label>
</div>
% }
Expand Down Expand Up @@ -76,4 +80,6 @@ $Multiple => 0
$Rows => undef
$MaxValues => undef
$Name => undef
$DescribedBy => undef
$AddClass => undef
</%ARGS>
4 changes: 3 additions & 1 deletion share/html/Elements/EditCustomFieldDate
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
<div class="row">
<div class="col-auto">
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, ShowTime => 0 &>
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, ShowTime => 0, DescribedBy => $DescribedBy, AddClass => $AddClass &>
</div>
</div>
<%ARGS>
Expand All @@ -59,4 +59,6 @@ $Default => undef
$Values => undef
$MaxValues => 1
$Name => undef
$DescribedBy => undef
$AddClass => undef
</%ARGS>
4 changes: 3 additions & 1 deletion share/html/Elements/EditCustomFieldDateTime
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
<div class="row">
<div class="col-auto">
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0 &>
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, DescribedBy => $DescribedBy, AddClass => $AddClass &>
</div>
</div>

Expand All @@ -61,4 +61,6 @@ $Values => undef
$MaxValues => 1
$Name => undef
$Format => 'unknown'
$DescribedBy => undef
$AddClass => undef
</%ARGS>
12 changes: 10 additions & 2 deletions share/html/Elements/EditCustomFieldFreeform
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" id="<%$name%>" wrap="off" class="CF-<%$CustomField->id%>-Edit form-control"><% defined($Default) ? $Default : '' %></textarea>
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" id="<%$name%>" wrap="off" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% defined($Default) ? $Default : '' %></textarea>
% } else {
<input type="text" name="<%$name%>" id="<%$name%>" \
% if ( defined $Cols ) {
size="<% $Cols %>" \
% }
class="CF-<%$CustomField->id%>-Edit form-control" value="<% defined($Default) ? $Default : ''%>" />
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>" value="<% defined($Default) ? $Default : ''%>" />
% }
<%INIT>
if ( $Multiple and $Values ) {
Expand All @@ -80,4 +86,6 @@ $Values => undef
$Multiple => undef
$Cols
$Rows
$DescribedBy => undef
$AddClass => undef
</%ARGS>
12 changes: 10 additions & 2 deletions share/html/Elements/EditCustomFieldHTML
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control richtext"><% $value->Content %></textarea><br />
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control richtext <% $AddClass // '' %>"><% $value->Content %></textarea><br />
% }
% if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
<textarea \
Expand All @@ -64,7 +67,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control richtext"><% $Default %></textarea>
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control richtext <% $AddClass // '' %>"><% $Default %></textarea>
% }
<%INIT>
# XXX - MultiValue textarea is for now outlawed.
Expand All @@ -81,4 +87,6 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$DescribedBy => undef
$AddClass => undef
</%ARGS>
7 changes: 6 additions & 1 deletion share/html/Elements/EditCustomFieldSelect
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<select
name="<%$name%>" id="<%$name%>"

class="CF-Edit CF-<%$CustomField->id%>-Edit form-select selectpicker"
class="CF-Edit CF-<%$CustomField->id%>-Edit form-select selectpicker <% $AddClass // '' %>"
% if ( $use_live_search ) {
data-live-search="true"
% }
Expand All @@ -133,6 +133,9 @@
% if ( $size > 1 ) {
size="<% $Rows %>"
% }
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
<% $Multiple && qq[multiple="multiple"] |n %> >
% if ( $show_empty_option ) {
<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
Expand Down Expand Up @@ -202,6 +205,8 @@ $Rows => undef
$HideCategory => 0
$RenderType => undef
$MaxValues => 1
$DescribedBy => undef
$AddClass => undef
</%ARGS>

<%METHOD options>
Expand Down
12 changes: 10 additions & 2 deletions share/html/Elements/EditCustomFieldText
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% $value->Content %></textarea><br />
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% $value->Content %></textarea><br />
% }
% if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
<textarea \
Expand All @@ -63,7 +66,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% defined($Default) ? $Default : '' %></textarea>
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% defined($Default) ? $Default : '' %></textarea>
% }
<%INIT>
# XXX - MultiValue textarea is for now outlawed.
Expand All @@ -80,4 +86,6 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$DescribedBy => undef
$AddClass => undef
</%ARGS>
12 changes: 10 additions & 2 deletions share/html/Elements/EditCustomFieldWikitext
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% $value->Content %></textarea><br />
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% $value->Content %></textarea><br />
% }
% if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
<textarea \
Expand All @@ -63,7 +66,10 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% $Default %></textarea>
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control <% $AddClass // '' %>"><% $Default %></textarea>
% }
<%INIT>
# XXX - MultiValue textarea is for now outlawed.
Expand All @@ -80,4 +86,6 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$DescribedBy => undef
$AddClass => undef
</%ARGS>
11 changes: 8 additions & 3 deletions share/html/Elements/SelectDate
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
%#
%# END BPS TAGGED BLOCK }}}
% $m->callback( %ARGS, Name => $Name, CallbackName => 'BeforeDateInput', Object => $Object, ARGSRef => $ARGSRef, ShowTimeRef => \$ShowTime, );
<input type="text" class="datepicker<% $ShowTime ? ' withtime' : '' %> form-control"
<input type="text" class="datepicker<% $ShowTime ? ' withtime' : '' %> form-control <% $AddClass // '' %>" \
% if ( $id ) {
id="<% $id %>"
id="<% $id %>" \
% }
name="<% $Name %>" value="<% $Default %>" autocomplete="off" placeholder="" />
% if ( defined $DescribedBy ) {
aria-describedby="<% $DescribedBy %>" \
% }
name="<% $Name %>" value="<% $Default %>" autocomplete="off" placeholder="" />
% $m->callback( %ARGS, Name => $Name, CallbackName => 'AfterDateInput', Object => $Object, ARGSRef => $ARGSRef, );
<%init>
unless ((defined $Default) or ($current <= 0)) {
Expand All @@ -77,4 +80,6 @@ $Name => undef
$Object => undef
$ARGSRef => undef
$id => undef
$DescribedBy => undef
$AddClass => undef
</%args>
Loading

0 comments on commit 30beec1

Please sign in to comment.