Browse Source

Bug 22010: Check preferences for ebook integration

To test:
1 - Enable OverDrive and RecordedBooks (you can put anything in the
        prefs)
2 - Search on the opac - verify you get results (or search error) on
first page of results'
3 - Go to second page of results - OD and RB are not searched
4 - Apply patch
5 - Verify nothing has changed

If you have valid credentials:
1 - Enable RB prefs
2 - Sign in with an account that has an email matching your registered
account for recordedbooks
3 - Confirm you RB account loads on opac-user.pl

Otherwise:
Read the patches, verify it all makes sense

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
19.05.x
Nick Clemens 5 years ago
committed by root
parent
commit
7a44c9edb9
  1. 18
      C4/External/OverDrive.pm
  2. 5
      koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc
  3. 2
      koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt
  4. 7
      koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
  5. 6
      opac/opac-search.pl
  6. 2
      opac/svc/overdrive_proxy
  7. 55
      t/External/OverDrive.t

18
C4/External/OverDrive.pm

@ -32,7 +32,6 @@ BEGIN {
require Exporter;
our @ISA = qw( Exporter ) ;
our @EXPORT = qw(
IsOverDriveEnabled
GetOverDriveToken
);
}
@ -63,23 +62,6 @@ This module provides content search for OverDrive,
=over
=item IsOverDriveEnabled
Returns 1 if all of the necessary system preferences for OverDrive are set.
=back
=cut
sub IsOverDriveEnabled {
return (
C4::Context->preference( 'OverDriveClientKey' ) &&
C4::Context->preference( 'OverDriveClientSecret' )
);
}
=over
=item GetOverDriveToken
Fetches an OAuth2 auth token for the OverDrive API, reusing an existing token in

5
koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc

@ -1,4 +1,5 @@
[% USE raw %]
[% USE Koha %]
[%- USE KohaPlugins -%]
[% USE Asset %]
[% UNLESS ( is_popup ) %]
@ -274,8 +275,10 @@ $.widget.bridge('uitooltip', $.ui.tooltip);
</script>
[% END %]
[% IF (RecordedBooksEnabled) %]
[% IF Koha.Preference('RecordedBooksClientSecret') && Koha.Preference('RecordedBooksLibraryID') %]
<script>
var SPINNER_THROBBER = "[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif";
</script>
[% END %]
[% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %]

2
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt

@ -93,7 +93,7 @@ function fetch_availability( prod, $tr ) {
function search( offset ) {
$( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, results_per_page, offset, function( data ) {
KOHA.OverDrive.Search( "[% Koha.Preference('OverDriveLibraryID') | html %]", querystring, results_per_page, offset, function( data ) {
if ( data.error ) {
$( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
return;

7
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt

@ -6,6 +6,11 @@
[% SET AdlibrisEnabled = Koha.Preference('AdlibrisCoversEnabled') %]
[% SET AdlibrisURL = Koha.Preference('AdlibrisCoversURL') %]
[% IF firstPage %]
[% SET OverDriveEnabled = Koha.Preference('OverDriveClientKey') && Koha.Preference('OverDriveClientSecret') %]
[% SET RecordedBooksEnabled = Koha.Preference('RecordedBooksLibraryID') && Koha.Preference('RecordedBooksClientSecret') %]
[% END %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo;
[% IF ( searchdesc ) %]
@ -923,7 +928,7 @@ $(document).ready(function(){
var $overdrive_results = $( '<div id="overdrive-results">' + MSG_SEARCHING.format('OverDrive') + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' );
$( '#numresults' ) .append( ' ' )
.append( $overdrive_results );
KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, 1, 0, function( data ) {
KOHA.OverDrive.Search( "[% Koha.Preference('OverDriveLibraryID') | html %]", querystring, 1, 0, function( data ) {
if ( data.error ) {
$overdrive_results.html( MSG_ERROR_SEARCHING_COLLECTION.format('OverDrive') );
return;

6
opac/opac-search.pl

@ -1022,11 +1022,7 @@ $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBook
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
if ($offset == 0) {
if (IsOverDriveEnabled()) {
$template->param(OverDriveEnabled => 1);
$template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
}
$template->param(RecordedBooksEnabled => C4::Context->preference( 'RecordedBooksClientSecret' ) && C4::Context->preference( 'RecordedBooksLibraryID' ));
$template->param(firstPage => 1);
}
$template->param( borrowernumber => $borrowernumber);

2
opac/svc/overdrive_proxy

@ -47,7 +47,7 @@ my $query = new CGI;
my $token;
if ( !IsOverDriveEnabled() || !( $token = GetOverDriveToken() ) ) {
if ( !(C4::Context->preference('OverDriveClientKey') && C4::Context->preference('OverDriveClientSecret')) || !( $token = GetOverDriveToken() ) ) {
print $query->header(
-status => '400 Bad Request',
);

55
t/External/OverDrive.t

@ -1,55 +0,0 @@
#!/usr/bin/perl
# Copyright 2015 BibLibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use C4::Context;
use t::lib::Mocks qw(mock_preference);
use Test::More tests => 6;
BEGIN {
use_ok('C4::External::OverDrive');
}
can_ok(
'C4::External::OverDrive', qw(
_request
IsOverDriveEnabled
GetOverDriveToken )
);
# ---------- Testing IsOverDriveEnabled ---------
t::lib::Mocks::mock_preference( "OverDriveClientKey", 0 );
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 0 );
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
t::lib::Mocks::mock_preference( "OverDriveClientKey", 0 );
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 1 );
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
t::lib::Mocks::mock_preference( "OverDriveClientKey", 1 );
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 0 );
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
t::lib::Mocks::mock_preference( "OverDriveClientKey", 1 );
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 1 );
is( IsOverDriveEnabled(), 1, 'IsOverDriveEnabled success' );
Loading…
Cancel
Save