Skip to content

Commit

Permalink
Merge branch '6.0/htmx-response-targets-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Dec 17, 2024
2 parents f05dd7f + c6b0b70 commit 74283f9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
6 changes: 6 additions & 0 deletions share/html/Elements/JavascriptConfig
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ my $Catalog = {
clip => "Show less", #loc
show_details => "Show Details", #loc
hide_details => "Hide Details", #loc
http_message_500 => 'Server Error: Unable to load content for this request.', # loc
http_message_400 => 'Client Request Error: Unable to process this request.', # loc
http_message_401 => 'Client Request Error: Unauthorized.', # loc
http_message_403 => 'Client Request Error: Permission Denied.', # loc
http_message_404 => 'Client Request Error: The requested URL was not found.', # loc
http_message_network => 'Network Error: Unable to reach the RT server.', # loc
};
$_ = loc($_) for values %$Catalog;

Expand Down
31 changes: 31 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,30 @@ jQuery(function() {
jQuery(evt.detail.historyElt).find('.selectpicker').selectpicker('destroy').addClass('selectpicker');
});

// Detect 400/500 errors
document.body.addEventListener('htmx:beforeSwap', function(evt) {
const status = evt.detail.xhr.status.toString();
if (status.match(/^[45]/)) {
if (evt.target && evt.detail.requestConfig.verb === "get") {
evt.detail.shouldSwap = true;
}
else {
// Fall back to general 400/500 errors for 4XX/5XX errors without specific messages
const message = RT.I18N.Catalog['http_message_' + status] || RT.I18N.Catalog['http_message_' + status.substr(0, 1) + '00'];
if (message) {
alertError(message);
}
}
}
});

// Detect network errors
document.body.addEventListener('htmx:sendError', function(evt) {
if ( RT.I18N.Catalog['http_message_network'] ) {
alertError(RT.I18N.Catalog['http_message_network']);
}
});

document.body.addEventListener('actionsChanged', function(evt) {
if ( evt.detail.value ) {
for ( const action of evt.detail.value ) {
Expand Down Expand Up @@ -2023,3 +2047,10 @@ function clipContent(elt) {
return false;
});
}

function alertError(message) {
jQuery.jGrowl(`
<div id="rt-content-fetch-errors-network" class="p-3 text-danger-emphasis bg-danger-subtle border border-danger-subtle rounded-3">
<span class="danger-text-emphasis">${message}</span>
</div>`, { sticky: true, themeState: 'none' });
}
6 changes: 3 additions & 3 deletions t/web/dashboards-basics.t
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $m->warning_like(qr/Permission Denied/, "got a permission denied warning");
$user_obj->PrincipalObj->GrantRight(Right => 'AdminOwnDashboard', Object => $RT::System);

$m->get_ok($url."Dashboards/Modify.html?Create=1");
$m->content_lacks("Permission Denied");
$m->text_lacks("Permission Denied");
$m->content_contains("Create");

$m->get_ok($url."Dashboards/index.html");
Expand All @@ -109,11 +109,11 @@ $m->content_contains("Dashboard created");
$user_obj->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard', Object => $RT::System);
$m->get($url."Dashboards/index.html");
$m->follow_link_ok({ text => 'different dashboard'});
$m->content_lacks("Permission Denied", "we now have SeeOwnDashboard");
$m->text_lacks("Permission Denied", "we now have SeeOwnDashboard");

$m->get_ok($url."Dashboards/index.html");
$m->content_contains("different dashboard", "we now have SeeOwnDashboard");
$m->content_lacks("Permission Denied");
$m->text_lacks("Permission Denied");

$m->follow_link_ok({text => "different dashboard"});
$m->content_contains("Basics");
Expand Down
4 changes: 2 additions & 2 deletions t/web/dashboards-groups.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $m->form_name('ModifyDashboard');
$m->field("Name" => 'inner dashboard');
$m->field("PrincipalId" => $inner_group->Id);
$m->click_button(value => 'Create');
$m->content_lacks("Permission Denied", "we now have SeeGroupDashboard");
$m->text_lacks("Permission Denied", "we now have SeeGroupDashboard");
$m->content_contains("Dashboard created");

my $dashboard = RT::Dashboard->new($currentuser);
Expand All @@ -93,7 +93,7 @@ is($dashboard->PossibleHiddenSearches, 0, "all searches are visible");

$m->get_ok("/Dashboards/Modify.html?id=$id");
$m->content_contains("inner dashboard", "we now have SeeGroupDashboard right");
$m->content_lacks("Permission Denied");
$m->text_lacks("Permission Denied");
$m->content_contains('Subscription', "Subscription link not hidden because we have SubscribeDashboard");


Expand Down
2 changes: 1 addition & 1 deletion t/web/dashboards-subscription.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $m->get_ok("/Dashboards/Subscription.html?id=$id");
$m->content_contains('id="page-subscription"', "subscription link should be visible");
$m->form_name('SubscribeDashboard');
$m->click_button(name => 'Save');
$m->content_lacks("Permission Denied");
$m->text_lacks("Permission Denied");
$m->content_contains("Subscribed to dashboard test dashboard");

# Verify subscription exists
Expand Down
4 changes: 2 additions & 2 deletions t/web/ticket_create.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $m->warning_like(qr/Permission Denied/, 'Permission denied warning' );

ok( $user->PrincipalObj->GrantRight( Right => 'CreateTicket', Object => $queue2 ), 'Grant CreateTicket right' );
$m->submit_form_ok( { form_name => 'CreateTicketInQueue' }, 'Try to create ticket' );
$m->content_lacks( 'Permission Denied', 'Has permission to create ticket' );
$m->text_lacks( 'Permission Denied', 'Has permission to create ticket' );
$form = $m->form_name('TicketCreate');
is_deeply( [ $form->find_input('Queue','option')->possible_values ], [ $queue2->id ], 'Only Another queue is listed' );

Expand All @@ -109,7 +109,7 @@ $m->warning_like(qr/Permission Denied/, 'Permission denied warning' );

ok( $user->PrincipalObj->GrantRight( Right => 'SeeQueue', Object => $queue2 ), 'Grant SeeQueue right to Another queue' );
$m->submit_form_ok( { form_name => 'CreateTicketInQueue' }, 'Try to create ticket' );
$m->content_lacks( 'Permission Denied', 'Has permission to create ticket' );
$m->text_lacks( 'Permission Denied', 'Has permission to create ticket' );
$form = $m->form_name('TicketCreate');
is( $form->value('Queue'), $queue2->id, 'Queue selection dropdown populated and pre-selected with ' . $queue2->Name );
is_deeply( [ $form->find_input('Queue','option')->possible_values ], [ $queue2->id ], 'Only queue listed is ' . $queue2->Name );
Expand Down

0 comments on commit 74283f9

Please sign in to comment.