Skip to content

Commit 0c8c2d7

Browse files
author
Ian Walls
committed
Issue #384: Add view option to public printing interface
Adds a 'View' button along with Print and Cancel buttons on the list of print jobs for a user. Opens in a new browser window. Access is limited to the user who owns the print job This is especially helpful now that we can do automated PDF conversion; users may want to verify that their file rendered right before paying to print it.
1 parent ef5f2ca commit 0c8c2d7

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/Libki/Controller/Public/API/User.pm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@ sub funds : Local Args(0) {
4747
$c->forward( $c->view('JSON') );
4848
}
4949

50+
51+
=head2 view_print_job
52+
53+
Returns the PDF of a given print job.
54+
55+
=cut
56+
57+
sub view_print_job : Local : Args(0) {
58+
my ( $self, $c ) = @_;
59+
60+
if ( !$c->user_exists ) {
61+
$c->response->body('Unauthorized');
62+
$c->response->status(401);
63+
return;
64+
}
65+
66+
my $id = $c->request->params->{id};
67+
68+
my $user = $c->user();
69+
my $instance = $c->instance;
70+
my $print_job = $c->model('DB::PrintJob')->find($id);
71+
72+
if ( $user->id != $print_job->user_id ) {
73+
$c->response->body('Forbidden');
74+
$c->response->status(403);
75+
return;
76+
}
77+
78+
if ($print_job) {
79+
my $print_file = $c->model('DB::PrintFile')->find( $print_job->print_file_id );
80+
if ($print_file) {
81+
my $filename = $print_file->filename;
82+
83+
$c->response->body( $print_file->data );
84+
$c->response->content_type('application/pdf');
85+
$c->response->header( 'Content-Disposition', "inline; filename=$filename" );
86+
}
87+
else {
88+
$c->stash( success => 0, error => 'PRINT_FILE_NOT_FOUND' );
89+
$c->forward( $c->view('JSON') );
90+
}
91+
}
92+
else {
93+
$c->stash( success => 0, error => 'PRINT_JOB_NOT_FOUND' );
94+
$c->forward( $c->view('JSON') );
95+
}
96+
}
97+
5098
=head2 release_print_job
5199
52100
Sends the given print job to the actual print management backend.

root/dynamic/includes/index/printing.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ $(document).ready(function() {
215215
const not_held = row["status"] !== "Held";
216216

217217
let html = "<div class='btn-group' role='group' aria-label='Print actions'>";
218+
html += `<a id="view-btn-${print_job_id}" class="btn btn-info print-view" onclick="window.open('/public/api/user/view_print_job?id=${print_job_id}', '_blank' )" href="#" role="button"><i class="fa fa-eye"></i> View</a>`;
219+
218220
[% IF public_print_release != "disabled" %]
219221
if (not_held || user_funds < row["7"]) {
220222
html += `<a id="print-btn-${print_job_id}" data-jobid="${print_job_id}" class="btn btn-primary print-release disabled" disabled aria-disabled="true" href="#" role="button"><i class="fa fa-print"></i> Print</a>`;

0 commit comments

Comments
 (0)