Bug 42656: Improve file transport test display

This patch displays the directory tested in the background jobs results

It updates the language when test results are not stored for the transport and
links to the job when results are stored

To test:
1 - Setup an ftp file transport with good credentials
2 - Enter non-existent directories in incoming/outgoing
3 - Save
4 - Verify on save 'Never used' shows for status
5 - Refresh the page, status now:
     Connection ok
     Change directory ok
     Change directory failed
     Change directory ok
     Change directory failed
6 - Apply patch, restart all
7 - Edit/save the transport again, change nothing
8 - Confirm the page says 'No test results stored'
9 - Reload the page
10 - Confirm results are now:
     Connection ok
     Change directory ok
     Change directory failed
     Change directory ok
     Change directory failed
     Test job details
11 - Click on the job details link
12 - Confirm actual directory and errors are shown
13 - Edit the transport, use existing directories
14 - Save, reload
15 - Confirm the success results and link t background job

Signed-off-by: John Vinke <jvinke@austinseminary.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Nick Clemens 2026-05-20 17:24:17 +00:00 committed by Pedro Amorim
parent a0433635fa
commit 7d6dafef6d
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
4 changed files with 34 additions and 22 deletions

View File

@ -53,7 +53,10 @@ sub process {
my $transport = Koha::File::Transports->find( $args->{transport_id} );
$transport->test_connection;
my $status = { status => 'ok' };
my $status = {
status => 'ok', transport_id => $transport->id, transport_name => $transport->name,
background_job_id => $self->id
};
my $messages = $transport->object_messages;
for my $message (@$messages) {
$status->{status} = 'errors' if $message->{type} eq 'error';

View File

@ -157,7 +157,7 @@ sub _change_directory {
my ( $self, $remote_directory ) = @_;
my $operation = "change_directory";
$self->{connection}->cwd($remote_directory) or return $self->_abort_operation($operation);
$self->{connection}->cwd($remote_directory) or return $self->_abort_operation( $operation, $remote_directory );
$self->add_message(
{
@ -396,15 +396,16 @@ C<return $self-E<gt>_abort_operation($operation)> on failure.
=cut
sub _abort_operation {
my ( $self, $operation ) = @_;
my ( $self, $operation, $operation_params ) = @_;
$self->add_message(
{
message => $operation || 'operation',
type => 'error',
payload => {
detail => $self->{connection} ? $self->{connection}->status : '',
error => $self->{connection} ? $self->{connection}->message : $@
detail => $self->{connection} ? $self->{connection}->status : '',
error => $self->{connection} ? $self->{connection}->message : $@,
operation_params => $operation_params
}
}
);

View File

@ -3,29 +3,30 @@
[%- BLOCK operation_description -%]
[%- SWITCH operation.code -%]
[%- IF operation.error %][% SET status = " failed. " %][% ELSE %][% SET status = " passed. " %][% END -%]
[%- CASE 'connection' -%]
<span>Connection</span>
<span>Connection</span>[% status | html %]
[%- CASE 'upload' -%]
<span>Upload</span>
<span>Upload</span>[% status | html %]
[%- CASE 'download' -%]
<span>Download</span>
<span>Download</span>[% status | html %]
[%- CASE 'list' -%]
<span>List files</span>
<span>List files</span>[% status | html %]
[%- CASE 'change_directory' -%]
<span>Change directory</span>
<span>Change directory ([% operation.detail.directory | html %][% operation.detail.operation_params | html %])</span>[% status | html %]
[%- CASE -%]
<span>[% operation.code | html %]</span>
<span>[% operation.code | html %]</span>[% status | html %]
[%- END -%]
[%- END -%]
[% SET report = job.decoded_data %]
[% BLOCK report %]
[% IF job.status == 'finished' %]
[% IF report.status == 'errors' %]
<div class="alert alert-alert"> Connection test completed with errors </div>
[% ELSE %]
<div class="alert alert-success"> Connection test completed without errors </div>
[% END %]
[%- IF report.status == 'errors' -%]
<div class="alert alert-alert"> Connection test for [% report.transport_name | html %]([% report.transport_id | html %]) completed with errors </div>
[%- ELSE -%]
<div class="alert alert-success"> Connection test for [% report.transport_name | html %]([% report.transport_id | html %]) completed without errors </div>
[%- END -%]
[% ELSIF job.status == 'cancelled' %]
<span>The connection test was cancelled before it finished.</span>
[% END %]
@ -34,9 +35,12 @@
[% BLOCK detail %]
[% FOREACH operation IN report.operations %]
[% IF operation.status == 'error' %]
<div class="text-danger"> <i class="fa-solid fa-circle-xmark"></i> [% PROCESS operation_description %] failed. </div>
<div class="text-danger">
<i class="fa-solid fa-circle-xmark"></i> [% PROCESS operation_description %]
[%- IF operation.detail.error %]- error:[% operation.detail.error | html %][% END -%]</div
>
[% ELSE %]
<div class="text-success"> <i class="fa-solid fa-circle-check"></i> [% PROCESS operation_description %] passed. </div>
<div class="text-success"> <i class="fa-solid fa-circle-check"></i> [% PROCESS operation_description %] </div>
[% END %]
[% END %]
[% IF job.status == 'cancelled' %]

View File

@ -567,10 +567,10 @@
let render = "";
if (data) {
if (data.status == "ok") {
render += '<i class="text-success fa-solid fa-circle-check"></i> ';
render += '<div><i class="text-success fa-solid fa-circle-check"></i> ';
render += '<span class="text-success">';
render += _("Tests passing");
render += "</span>";
render += "</span></div>";
} else if (data.status == "errors") {
data.operations.forEach(operation => {
render += "<div>";
@ -590,10 +590,14 @@
render += "</div>";
});
} else {
render += "<em>" + _("Never used") + "</em>";
render += "<em>" + _("No test results stored") + "</em>";
}
if (data.background_job_id) {
render += '<i class="fa-solid fa-info-circle"></i> ';
render += '<a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=' + data.background_job_id + '">' + _("Test job details") + "</a>";
}
} else {
render += "<em>" + _("Never used") + "</em>";
render += "<em>" + _("No test results stored") + "</em>";
}
return render;
},