Skip to content

Commit 4cae21a

Browse files
committed
Merge branch '6.0/optimize-incident-create' into 6.0-trunk
2 parents fda62a1 + 08eb7eb commit 4cae21a

6 files changed

Lines changed: 121 additions & 3 deletions

File tree

html/Callbacks/RTIR/Ticket/Create.html/AfterShowWidgets

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@
5353
<div id="ticket-create-investigation" data-name-prefix="Investigation">
5454
<&| /Widgets/TitleBox, title => RT::IR::TicketType( Lifecycle => 'investigations' ) &>
5555
<& /Elements/ShowWidgets,
56-
Object => $InvestigationsQueueObj,
57-
Page => 'Create',
58-
ARGSRef => {
56+
Object => $InvestigationsQueueObj,
57+
Page => 'Create',
58+
LazyLoad => 1,
59+
ARGSRef => {
5960
Queue => $InvestigationsQueueObj->Id,
6061
SelectIncident => 0,
6162
AddAttachments => 0,

html/Ticket/Widgets/Create/AttachReports

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,36 @@ if ( $ARGS{Incident} ) {
6262
<%ARGS>
6363
$QueueObj
6464
</%ARGS>
65+
66+
<%METHOD PreCheck>
67+
<%args>
68+
$ARGSRef
69+
</%args>
70+
<%init>
71+
return 0 unless $ARGSRef && $ARGSRef->{Incident};
72+
73+
my $id = ref $ARGSRef->{Incident} ? $ARGSRef->{Incident}[0] : $ARGSRef->{Incident};
74+
my $incident = RT::Ticket->new( $session{CurrentUser} );
75+
$incident->Load($id);
76+
return 0 unless $incident->Id;
77+
78+
my @parents;
79+
if ( RT::IR->IsIncidentQueue( $incident->QueueObj ) ) {
80+
push @parents, $incident->id;
81+
}
82+
else {
83+
push @parents, map $_->id, @{ RT::IR->Incidents($incident)->ItemsArrayRef || [] };
84+
}
85+
return 0 unless @parents;
86+
87+
my $siblings = RT::Tickets->new( $incident->CurrentUser );
88+
$siblings->FromSQL(
89+
RT::IR->Query(
90+
Lifecycle => RT::IR->lifecycle_report,
91+
MemberOf => \@parents,
92+
Exclude => [$incident],
93+
)
94+
);
95+
return $siblings->Count ? 1 : 0;
96+
</%init>
97+
</%METHOD>

html/Ticket/Widgets/Display/CVEDetails

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@
5555
<%ARGS>
5656
$TicketObj
5757
</%ARGS>
58+
59+
<%METHOD PreCheck>
60+
<%args>
61+
$Object
62+
</%args>
63+
<%init>
64+
return 0 unless $Object && $Object->isa('RT::Ticket');
65+
return $Object->CustomFieldValues('CVE ID')->Count ? 1 : 0;
66+
</%init>
67+
</%METHOD>

html/Ticket/Widgets/Display/LinkedArticles

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@
5454
<%ARGS>
5555
$TicketObj
5656
</%ARGS>
57+
58+
<%METHOD PreCheck>
59+
<%args>
60+
$Object
61+
</%args>
62+
<%init>
63+
return 0 unless $Object && $Object->isa('RT::Ticket');
64+
my $articles = RT::Articles->new( $session{'CurrentUser'} );
65+
$articles->LimitReferredToBy( $Object->URI );
66+
return $articles->Count ? 1 : 0;
67+
</%init>
68+
</%METHOD>

t/020-incident-and-investigation.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,36 @@ is ($agent->status, 200, "Attempting to create new incident and investigation li
3131
$agent->text_like(qr{You must enter a correspondent for the investigation},
3232
"RT did not allow an empty correspondent field");
3333

34+
# Same scenario, but submitted as an htmx-boosted request (matching what
35+
# the browser sends when the body's hx-boost intercepts the form).
36+
$agent->display_ticket($ir);
37+
$agent->follow_link_ok({id => "create-incident"}, "Followed 'New (Incident)' link (htmx-boosted scenario)");
38+
$agent->form_number(3);
39+
$agent->field('Subject', 'Incident for htmx-boosted validation test');
40+
$agent->field('InvestigationSubject', 'Investigation for htmx-boosted validation test');
41+
$agent->field('InvestigationRequestors', '');
42+
43+
$agent->add_header( 'HX-Request' => 'true' );
44+
$agent->add_header( 'HX-Boosted' => 'true' );
45+
46+
# autocheck would fail the test on a non-2xx response; 422 is what we want here.
47+
my $orig_autocheck = $agent->autocheck;
48+
$agent->autocheck(0);
49+
50+
$agent->click("InvestigationSubmitTicket");
51+
52+
is( $agent->status, 422, 'htmx-boosted InvestigationSubmitTicket validation failure returns 422' );
53+
54+
$agent->next_warning_like( qr/Validation error/, 'htmx-boosted validation failure logs expected "Validation error"' );
55+
56+
my $hx_trigger = $agent->response->header('HX-Trigger');
57+
ok( $hx_trigger, 'HX-Trigger header is set on htmx-boosted validation failure' );
58+
like( $hx_trigger // '', qr/actionsChanged/, 'HX-Trigger contains actionsChanged event' );
59+
like( $hx_trigger // '', qr/correspondent for the investigation/, 'HX-Trigger payload mentions the validation error' );
60+
61+
$agent->autocheck($orig_autocheck);
62+
$agent->delete_header('HX-Request');
63+
$agent->delete_header('HX-Boosted');
3464

3565
my ( $inc_id, $inv_id ) = $agent->create_incident_and_investigation(
3666
'',

t/playwright/incident_create.t

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use strict;
2+
use warnings;
3+
4+
use RT::IR::Test tests => undef, playwright => 1;
5+
6+
my ( $url, $p ) = RT::Test->started_ok;
7+
$p->login();
8+
9+
$p->get_ok('/RTIR/Incident/Create.html?Lifecycle=incidents');
10+
$p->wait_for_htmx;
11+
12+
my $incident_section = $p->{page}->locator('#ticket-create-incident');
13+
my $investigation_section = $p->{page}->locator('#ticket-create-investigation');
14+
15+
ok( $incident_section->isVisible, 'Incident section is rendered in the DOM' );
16+
ok( $investigation_section->count > 0, 'Investigation section is rendered in the DOM' );
17+
18+
# Each widget is wrapped by HTMXLoadStart in a div with the
19+
# class="htmx-load-widget" and an hx-trigger attribute. The trigger
20+
# should be "...load" for the eager Incident half and "...revealed" for
21+
# the lazy Investigation half.
22+
my $incident_widget = $incident_section->locator('.htmx-load-widget')->first;
23+
my $investigation_widget = $investigation_section->locator('.htmx-load-widget')->first;
24+
25+
my $inc_trigger = $incident_widget->getAttribute('hx-trigger') // '';
26+
my $inv_trigger = $investigation_widget->getAttribute('hx-trigger') // '';
27+
28+
like( $inc_trigger, qr/\bload\b/, "Incident widget triggers on load (hx-trigger='$inc_trigger')" );
29+
like( $inv_trigger, qr/\brevealed\b/, "Investigation widget triggers on reveal (hx-trigger='$inv_trigger')" );
30+
31+
$p->logout;
32+
done_testing;

0 commit comments

Comments
 (0)