View | Details | Raw Unified | Return to bug 22010
Collapse All | Expand All

(-)a/C4/External/OverDrive.pm (-18 lines)
Lines 32-38 BEGIN { Link Here
32
    require Exporter;
32
    require Exporter;
33
    our @ISA = qw( Exporter ) ;
33
    our @ISA = qw( Exporter ) ;
34
    our @EXPORT = qw(
34
    our @EXPORT = qw(
35
        IsOverDriveEnabled
36
        GetOverDriveToken
35
        GetOverDriveToken
37
    );
36
    );
38
}
37
}
Lines 63-85 This module provides content search for OverDrive, Link Here
63
62
64
=over
63
=over
65
64
66
=item IsOverDriveEnabled
67
68
Returns 1 if all of the necessary system preferences for OverDrive are set.
69
70
=back
71
72
=cut
73
74
sub IsOverDriveEnabled {
75
    return (
76
        C4::Context->preference( 'OverDriveClientKey' ) &&
77
        C4::Context->preference( 'OverDriveClientSecret' )
78
    );
79
}
80
81
=over
82
83
=item GetOverDriveToken
65
=item GetOverDriveToken
84
66
85
Fetches an OAuth2 auth token for the OverDrive API, reusing an existing token in
67
Fetches an OAuth2 auth token for the OverDrive API, reusing an existing token in
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc (-1 / +4 lines)
Lines 1-4 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Koha %]
2
[%- USE KohaPlugins -%]
3
[%- USE KohaPlugins -%]
3
[% USE Asset %]
4
[% USE Asset %]
4
[% UNLESS ( is_popup ) %]
5
[% UNLESS ( is_popup ) %]
Lines 274-281 $.widget.bridge('uitooltip', $.ui.tooltip); Link Here
274
</script>
275
</script>
275
[% END %]
276
[% END %]
276
277
277
[% IF (RecordedBooksEnabled) %]
278
[% IF Koha.Preference('RecordedBooksClientSecret') && Koha.Preference('RecordedBooksLibraryID') %]
279
<script>
278
  var SPINNER_THROBBER = "[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif";
280
  var SPINNER_THROBBER = "[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif";
281
</script>
279
[% END %]
282
[% END %]
280
283
281
[% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %]
284
[% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-overdrive-search.tt (-1 / +1 lines)
Lines 93-99 function fetch_availability( prod, $tr ) { Link Here
93
function search( offset ) {
93
function search( offset ) {
94
    $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
94
    $( '#overdrive-status' ).html( _("Searching OverDrive...") + ' <img class="throbber" src="[% interface | html %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
95
95
96
    KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, results_per_page, offset, function( data ) {
96
    KOHA.OverDrive.Search( "[% Koha.Preference('OverDriveLibraryID') | html %]", querystring, results_per_page, offset, function( data ) {
97
        if ( data.error ) {
97
        if ( data.error ) {
98
            $( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
98
            $( '#overdrive-status' ).html( '<strong class="unavailable">' + _("Error searching OverDrive collection.") + '</strong>' );
99
            return;
99
            return;
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt (-1 / +6 lines)
Lines 6-11 Link Here
6
[% SET AdlibrisEnabled = Koha.Preference('AdlibrisCoversEnabled') %]
6
[% SET AdlibrisEnabled = Koha.Preference('AdlibrisCoversEnabled') %]
7
[% SET AdlibrisURL = Koha.Preference('AdlibrisCoversURL') %]
7
[% SET AdlibrisURL = Koha.Preference('AdlibrisCoversURL') %]
8
8
9
[% IF firstPage %]
10
     [% SET OverDriveEnabled = Koha.Preference('OverDriveClientKey') && Koha.Preference('OverDriveClientSecret') %]
11
     [% SET RecordedBooksEnabled = Koha.Preference('RecordedBooksLibraryID') && Koha.Preference('RecordedBooksClientSecret') %]
12
[% END %]
13
9
[% INCLUDE 'doc-head-open.inc' %]
14
[% INCLUDE 'doc-head-open.inc' %]
10
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo;
15
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo;
11
[% IF ( searchdesc ) %]
16
[% IF ( searchdesc ) %]
Lines 923-929 $(document).ready(function(){ Link Here
923
        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>' );
928
        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>' );
924
        $( '#numresults' ) .append( ' ' )
929
        $( '#numresults' ) .append( ' ' )
925
            .append( $overdrive_results );
930
            .append( $overdrive_results );
926
        KOHA.OverDrive.Search( "[% OverDriveLibraryID | html %]", querystring, 1, 0, function( data ) {
931
        KOHA.OverDrive.Search( "[% Koha.Preference('OverDriveLibraryID') | html %]", querystring, 1, 0, function( data ) {
927
            if ( data.error ) {
932
            if ( data.error ) {
928
                $overdrive_results.html( MSG_ERROR_SEARCHING_COLLECTION.format('OverDrive') );
933
                $overdrive_results.html( MSG_ERROR_SEARCHING_COLLECTION.format('OverDrive') );
929
                return;
934
                return;
(-)a/opac/opac-search.pl (-5 / +1 lines)
Lines 1022-1032 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBook Link Here
1022
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1022
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1023
1023
1024
if ($offset == 0) {
1024
if ($offset == 0) {
1025
    if (IsOverDriveEnabled()) {
1025
    $template->param(firstPage => 1);
1026
        $template->param(OverDriveEnabled => 1);
1027
        $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
1028
    }
1029
    $template->param(RecordedBooksEnabled => C4::Context->preference( 'RecordedBooksClientSecret' ) && C4::Context->preference( 'RecordedBooksLibraryID' ));
1030
}
1026
}
1031
1027
1032
    $template->param( borrowernumber    => $borrowernumber);
1028
    $template->param( borrowernumber    => $borrowernumber);
(-)a/opac/svc/overdrive_proxy (-1 / +1 lines)
Lines 47-53 my $query = new CGI; Link Here
47
47
48
my $token;
48
my $token;
49
49
50
if ( !IsOverDriveEnabled() || !( $token = GetOverDriveToken() ) ) {
50
if ( !(C4::Context->preference('OverDriveClientKey') && C4::Context->preference('OverDriveClientSecret')) || !( $token = GetOverDriveToken() ) ) {
51
    print $query->header(
51
    print $query->header(
52
        -status => '400 Bad Request',
52
        -status => '400 Bad Request',
53
    );
53
    );
(-)a/t/External/OverDrive.t (-56 lines)
Lines 1-55 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use C4::Context;
21
use t::lib::Mocks qw(mock_preference);
22
use Test::More tests => 6;
23
24
BEGIN {
25
    use_ok('C4::External::OverDrive');
26
}
27
28
can_ok(
29
    'C4::External::OverDrive', qw(
30
      _request
31
      IsOverDriveEnabled
32
      GetOverDriveToken )
33
);
34
35
# ---------- Testing IsOverDriveEnabled ---------
36
37
t::lib::Mocks::mock_preference( "OverDriveClientKey",    0 );
38
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 0 );
39
40
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
41
42
t::lib::Mocks::mock_preference( "OverDriveClientKey",    0 );
43
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 1 );
44
45
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
46
47
t::lib::Mocks::mock_preference( "OverDriveClientKey",    1 );
48
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 0 );
49
50
is( IsOverDriveEnabled(), 0, 'IsOverDriveEnabled fail' );
51
52
t::lib::Mocks::mock_preference( "OverDriveClientKey",    1 );
53
t::lib::Mocks::mock_preference( "OverDriveClientSecret", 1 );
54
55
is( IsOverDriveEnabled(), 1, 'IsOverDriveEnabled success' );
56
- 

Return to bug 22010