From 900e0a0327f01acaf9ae453bd63697919e301dec Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 17 Dec 2018 13:35:09 +0000 Subject: [PATCH] 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 --- C4/External/OverDrive.pm | 18 ------- .../bootstrap/en/includes/opac-bottom.inc | 3 +- .../bootstrap/en/modules/opac-overdrive-search.tt | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 7 ++- opac/opac-search.pl | 6 +-- opac/svc/overdrive_proxy | 2 +- t/External/OverDrive.t | 55 ---------------------- 7 files changed, 11 insertions(+), 82 deletions(-) delete mode 100755 t/External/OverDrive.t diff --git a/C4/External/OverDrive.pm b/C4/External/OverDrive.pm index 9044169b59..897e2b3c48 100644 --- a/C4/External/OverDrive.pm +++ b/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 diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index fa7459ddc5..99d41a500f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/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,7 +275,7 @@ $.widget.bridge('uitooltip', $.ui.tooltip); [% END %] -[% IF (RecordedBooksEnabled) %] +[% IF Koha.Preference('RecordedBooksClientSecret') && Koha.Preference('RecordedBooksLibraryID') %] var SPINNER_THROBBER = "[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif"; [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt index 1c2548bcef..deeb767c07 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt @@ -95,7 +95,7 @@ function fetch_availability( prod, $tr ) { function search( offset ) { $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' ' ); - 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( '' + _("Error searching OverDrive collection.") + '' ); return; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 7a490d96fa..98e61ee08d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/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' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog › [% IF ( searchdesc ) %] @@ -899,7 +904,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; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index e0d3dd6229..05f910fa5d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -1010,11 +1010,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); diff --git a/opac/svc/overdrive_proxy b/opac/svc/overdrive_proxy index 9751f6343e..d8fd7c666e 100755 --- a/opac/svc/overdrive_proxy +++ b/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', ); diff --git a/t/External/OverDrive.t b/t/External/OverDrive.t deleted file mode 100755 index b6134fad56..0000000000 --- a/t/External/OverDrive.t +++ /dev/null @@ -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' ); -- 2.11.0