Bugzilla – Attachment 86585 Details for
Bug 22508
Add the ability to prefill 856$u with the direct URL of the file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22508: Add the ability to prefill 856$u with the direct URL of the file
Bug-22508-Add-the-ability-to-prefill-856u-with-the.patch (text/plain), 11.45 KB, created by
Jonathan Druart
on 2019-03-13 19:26:18 UTC
(
hide
)
Description:
Bug 22508: Add the ability to prefill 856$u with the direct URL of the file
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-03-13 19:26:18 UTC
Size:
11.45 KB
patch
obsolete
>From 72ef705800aea7fd32a4097c6e4d1882572258a9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 13 Mar 2019 00:20:06 -0300 >Subject: [PATCH] Bug 22508: Add the ability to prefill 856$u with the direct > URL of the file > >When uploading a file using the cataloguing plugin, the current value >used to fill 856$u (or others) in is > OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=a-big-hash > >This patch add the ability to define a custom and direct URL to this >file. > >To accomplish that we need 2 new entries in our config file: > * upload_public_path > * upload_public_url >The first one will be the local path where the files will be stored, >that will be publicly accessible. >The second one is the root of the URL which links to ths public dir >path. > >Test plan: >0. Define the 2 new config entries, like: > <upload_public_path>/home/vagrant/kohaclone/koha-tmpl/public_path</upload_public_path> > <upload_public_url>http://catalogue.kohadev.org/public_path</upload_public_url> >Then restart memcached+plack to take into account the changes >1. Link the cataloguing plugin 'upload.pl' to 856$u >2. Edit a record, 856$u > click the plugin link >3. A new "Use a public path:" appears if the config is set, tick it and >upload a file >4. Pick "Choose the direct url" >5. 856$u will be prefilled with > http://catalogue.kohadev.org/public_path/$hash_value >instead of the usual > http://catalogue.kohadev.org/cgi-bin/koha/opac-retrieve-file.pl?id=$hash_value > >6. Use the link and confirm that you can access the file. > >Note: This patch is not ready for inclusion yet and is published to get >feedback. There are several things that will block its inclusion: > * TODO: "Delete" button must delete the file > * See TODO and FIXME in the patch > * Tests and POD for new methods are missing > * Variable naming is not perfect > * In discussion - what about the upload of files from outside of the > cataloguing plugin? > * TODO: add check to the about page (?) > * FIXME: in upload_public_path the files are not suffixed by the > filename as it is for upload_path. We certainly want to be consistent > here. >--- > Koha/UploadedFile.pm | 32 ++++++++++++++++++++ > Koha/Uploader.pm | 4 ++- > .../intranet-tmpl/prog/en/modules/tools/upload.tt | 34 +++++++++++++++------- > tools/upload-file.pl | 14 ++++++++- > tools/upload.pl | 6 ++-- > 5 files changed, 75 insertions(+), 15 deletions(-) > >diff --git a/Koha/UploadedFile.pm b/Koha/UploadedFile.pm >index 20fc608c68..982cdc6ae3 100644 >--- a/Koha/UploadedFile.pm >+++ b/Koha/UploadedFile.pm >@@ -148,6 +148,38 @@ sub httpheaders { > } > } > >+sub url { >+ my ($self) = @_; >+ my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); >+ $OPACBaseURL =~ s|/$||; >+ return "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=" . $self->hashvalue; >+} >+ >+sub local_public_path { >+ my ($self) = @_; >+ my $upload_public_path = C4::Context->config('upload_public_path'); >+ return unless $upload_public_path; >+ $upload_public_path =~ s|/$||; >+ my $filepath = "$upload_public_path/" . $self->hashvalue; >+ return $filepath; >+} >+ >+sub has_local_public_path { >+ my ($self) = @_; >+ my $filepath = $self->local_public_path; >+ return $filepath if -e $filepath; >+} >+ >+sub direct_url { >+ my ( $self ) = @_; >+ # TODO It could start with '/' and we prefix with OPACBaseURL >+ my $upload_public_path = C4::Context->config('upload_public_url'); >+ return unless $upload_public_path; >+ $upload_public_path =~ s|/$||; >+ my $direct_url = "$upload_public_path/" . $self->hashvalue; >+ return $direct_url; >+} >+ > =head2 CLASS METHODS > > =head3 permanent_directory >diff --git a/Koha/Uploader.pm b/Koha/Uploader.pm >index a4baa6a30b..d226e3be66 100644 >--- a/Koha/Uploader.pm >+++ b/Koha/Uploader.pm >@@ -31,7 +31,7 @@ Koha::Uploader - Facilitate file uploads (temporary and permanent) > > # add an upload (see tools/upload-file.pl) > # the public flag allows retrieval via OPAC >- my $upload = Koha::Uploader->new( public => 1, category => 'A' ); >+ my $upload = Koha::Uploader->new( public => 1, category => 'A', use_public_path => 1 ); > my $cgi = $upload->cgi; > # Do something with $upload->count, $upload->result or $upload->err > >@@ -205,6 +205,7 @@ sub _init { > $self->{category} = $params->{category} || KOHA_UPLOAD; > } > >+ $self->{use_public_path} = $params->{use_public_path}; > $self->{files} = {}; > $self->{uid} = C4::Context->userenv->{number} if C4::Context->userenv; > $self->{public} = $params->{public}? 1: undef; >@@ -293,6 +294,7 @@ sub _register { > public => $self->{public}, > permanent => $self->{temporary}? 0: 1, > })->store; >+ > $self->{files}->{$filename}->{id} = $rec->id if $rec; > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >index 6bd010ad6f..f863f315a2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >@@ -72,8 +72,12 @@ > <li> > [% IF plugin %] > <input type="hidden" id="public" name="public" value="1"/> >+ [% IF can_use_public_path %] >+ <label id="use_public_path_cb" for="use_public_path">Use a public path:</label> >+ <input type="checkbox" id="use_public_path" name="use_public_path" /> >+ [% END %] > [% ELSE %] >- <label id="public_cb">Allow public downloads:</label> >+ <label id="public_cb" for="public">Allow public downloads:</label> > <input type="checkbox" id="public" name="public" /> > [% END %] > </li> >@@ -175,7 +179,10 @@ > [% END %] > <td class="actions"> > [% IF plugin %] >- <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button> >+ <button class="btn btn-default btn-xs choose_entry" data-record-url="[% record.url | html %]"><i class="fa fa-plus"></i> Choose</button> >+ [% IF record.has_local_public_path %] >+ <button class="btn btn-default btn-xs choose_entry_public_path" data-record-url="[% record.direct_url | html %]"><i class="fa fa-plus"></i> Choose the direct url</button> >+ [% END %] > [% END %] > <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button> > [% IF record.owner == owner || CAN_user_tools_upload_manage %] >@@ -270,12 +277,17 @@ > $("#searchfile").hide(); > $("#lastbreadcrumb").text( _("Add a new upload") ); > >- var cat, xtra=''; >+ var cat = xtra = use_public_path = ''; > if( $("#uploadcategory").val() ) > cat = encodeURIComponent( $("#uploadcategory").val() ); > if( cat ) xtra= 'category=' + cat + '&'; >+ >+ if( $("#use_public_path").is(":checked") ) { >+ xtra = xtra + 'use_public_path=1&'; >+ } >+ > [% IF plugin %] >- xtra = xtra + 'public=1&temp=0'; >+ xtra = xtra + 'public=1&temp=0&'; > [% ELSE %] > if( !cat ) xtra = 'temp=1&'; > if( $('#public').prop('checked') ) xtra = xtra + 'public=1'; >@@ -372,12 +384,9 @@ > $(window.opener.document).find('#[% index | html %]').val( '' ); > [% END %] > } >- function Choose(hashval) { >- var res = '[% Koha.Preference('OPACBaseURL') | html %]'; >- res = res.replace( /\/$/, ''); >- res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval; >+ function Choose(url) { > [% IF index %] >- $(window.opener.document).find('#[% index | html %]').val( res ); >+ $(window.opener.document).find('#[% index | html %]').val( url ); > [% END %] > window.close(); > } >@@ -408,8 +417,11 @@ > }); > $(".choose_entry").on("click",function(e){ > e.preventDefault(); >- var record_hashvalue = $(this).data("record-hashvalue"); >- Choose( record_hashvalue ); >+ Choose( $(this).data("record-url") ); >+ }); >+ $(".choose_entry_public_path").on("click",function(e){ >+ e.preventDefault(); >+ Choose( $(this).data("record-url") ); > }); > $(".download_entry").on("click",function(e){ > e.preventDefault(); >diff --git a/tools/upload-file.pl b/tools/upload-file.pl >index 86ef2c5dc2..dcbe1afdbd 100755 >--- a/tools/upload-file.pl >+++ b/tools/upload-file.pl >@@ -24,6 +24,7 @@ use CGI::Cookie; > use Encode; > use JSON; > use URI::Escape; >+use File::Copy qw( copy ); > > use C4::Context; > use C4::Auth qw/check_cookie_auth haspermission/; >@@ -53,6 +54,17 @@ if( !$upload || !$upload->cgi || !$upload->count ) { > # not one upload succeeded > send_reply( 'failed', undef, $upload? $upload->err: undef ); > } else { >+ my $upload_public_path = C4::Context->config('upload_public_path'); >+ # FIXME The copy must be done in Koha::Uploader, but where? >+ # I (Joubu) did not find a place where the file was completely written >+ if ( $upload->{use_public_path} && $upload_public_path ) { >+ for my $file ( values %{ $upload->{files} } ) { >+ my $uploaded_file = Koha::UploadedFiles->find($file->{id}); >+ next unless $uploaded_file; >+ copy $uploaded_file->full_path, $uploaded_file->local_public_path >+ or warn sprintf("Copy %s to %s failed (%s)", $uploaded_file->filename, $upload_public_path, $!); >+ } >+ } > # in case of multiple uploads, at least one got through > send_reply( 'done', $upload->result, $upload->err ); > } >@@ -75,7 +87,7 @@ sub upload_pars { # this sub parses QUERY_STRING in order to build the > $qstr = Encode::decode_utf8( uri_unescape( $qstr ) ); > # category could include a utf8 character > my $rv = {}; >- foreach my $p ( qw[public category temp] ) { >+ foreach my $p ( qw[public category temp use_public_path] ) { > if( $qstr =~ /(^|&)$p=(\w+)(&|$)/ ) { > $rv->{$p} = $2; > } >diff --git a/tools/upload.pl b/tools/upload.pl >index afb7c516f9..ace55ab784 100755 >--- a/tools/upload.pl >+++ b/tools/upload.pl >@@ -54,8 +54,10 @@ $template->param( > ); > > if ( $op eq 'new' ) { >+ my $can_use_public_path = C4::Context->config('upload_public_path'); > $template->param( > mode => 'new', >+ can_use_public_path => $can_use_public_path, > ); > output_html_with_http_headers $input, $cookie, $template->output; > >@@ -65,7 +67,7 @@ if ( $op eq 'new' ) { > my @id = split /,/, $id; > foreach my $recid (@id) { > my $rec = Koha::UploadedFiles->find( $recid ); >- push @$uploads, $rec->unblessed >+ push @$uploads, $rec # FIXME replace find with search and let the DB do that > if $rec && ( $rec->public || !$plugin ); > # Do not show private uploads in the plugin mode (:editor) > } >@@ -73,7 +75,7 @@ if ( $op eq 'new' ) { > $uploads = Koha::UploadedFiles->search_term({ > term => $term, > $plugin? (): ( include_private => 1 ), >- })->unblessed; >+ }); > } > > $template->param( >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22508
:
86583
|
86584
|
86585
|
87272
|
87273
|
87274
|
87430
|
87431
|
87432
|
89540
|
89541
|
89542
|
89543
|
89544
|
89545
|
89617