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

(-)a/Koha/ExternalContent/RecordedBooks.pm (+111 lines)
Line 0 Link Here
1
# Copyright 2016 Catalyst
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
package Koha::ExternalContent::RecordedBooks;
19
20
use Modern::Perl;
21
use Carp;
22
23
use base qw(Koha::ExternalContent);
24
use WebService::ILS::RecordedBooks::PartnerPatron;
25
use WebService::ILS::RecordedBooks::Partner;
26
use C4::Context;
27
use Koha::Logger;
28
29
use constant logger => Koha::Logger->get();
30
31
__PACKAGE__->mk_accessors(qw(domain is_identified));
32
33
=head1 NAME
34
35
Koha::ExternalContent::RecordedBooks
36
37
=head1 SYNOPSIS
38
39
    use Koha::ExternalContent::RecordedBooks;
40
    my $od_client = Koha::ExternalContent::RecordedBooks->new();
41
    my $od_auth_url = $od_client->auth_url();
42
43
=head1 DESCRIPTION
44
45
A (very) thin wrapper around C<WebService::ILS::RecordedBooks::Patron>
46
47
Takes "RecordedBooks*" Koha preferences
48
49
=cut
50
51
sub new {
52
    my $class  = shift;
53
    my $params = shift || {};
54
55
    my $self = $class->SUPER::new($params);
56
    unless ($params->{client}) {
57
        my $client_secret  = C4::Context->preference('RecordedBooksClientSecret')
58
          or croak("RecordedBooksClientSecret pref not set");
59
        my $library_id     = C4::Context->preference('RecordedBooksLibraryID')
60
          or croak("RecordedBooksLibraryID pref not set");
61
        my $domain         = C4::Context->preference('RecordedBooksDomain');
62
        my $patron = $params->{koha_session_id} ? $self->koha_patron : undef;
63
        my $email;
64
        if ($patron) {
65
            $email = $patron->email
66
              or $self->logger->warn("User with no email, cannot identify with RecordedBooks");
67
        }
68
        my $client;
69
        if ($email) {
70
            local $@;
71
            $client = eval { WebService::ILS::RecordedBooks::PartnerPatron->new(
72
                client_secret     => $client_secret,
73
                library_id        => $library_id,
74
                domain            => $domain,
75
                user_id           => $email,
76
                user_agent_params => { agent => $class->agent_string }
77
            ) };
78
            $self->logger->warn("Invalid RecordedBooks user $email ($@)") if $@;
79
            $self->is_identified($client);
80
        }
81
        $client ||= WebService::ILS::RecordedBooks::Partner->new(
82
                client_secret     => $client_secret,
83
                library_id        => $library_id,
84
                domain            => $domain,
85
        );
86
        $self->client( $client );
87
    }
88
    return $self;
89
}
90
91
=head1 METHODS
92
93
L<WebService::ILS::RecordedBooks::PartnerPatron> methods used without mods:
94
95
=over 4
96
97
=item C<error_message()>
98
99
=back
100
101
=cut
102
103
use vars qw{$AUTOLOAD};
104
sub AUTOLOAD {
105
    my $self = shift;
106
    (my $method = $AUTOLOAD) =~ s/.*:://;
107
    return $self->client->$method(@_);
108
}
109
sub DESTROY { }
110
111
1;
(-)a/installer/data/mysql/atomicupdate/recordedbooks.sql (+4 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
2
VALUES ('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'),
3
       ('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'),
4
       ('RecordedBooksDomain','','','RecordedBooks domain','Free');
(-)a/installer/data/mysql/sysprefs.sql (+3 lines)
Lines 215-220 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
215
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
215
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
216
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
216
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
217
('IntranetCatalogSearchPulldown','0', NULL, 'Show a search field pulldown for \"Search the catalog\" boxes','YesNo'),
217
('IntranetCatalogSearchPulldown','0', NULL, 'Show a search field pulldown for \"Search the catalog\" boxes','YesNo'),
218
('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'),
219
('RecordedBooksDomain','','','RecordedBooks domain','Free'),
220
('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'),
218
('OnSiteCheckouts','0','','Enable/Disable the on-site checkouts feature','YesNo'),
221
('OnSiteCheckouts','0','','Enable/Disable the on-site checkouts feature','YesNo'),
219
('OnSiteCheckoutsForce','0','','Enable/Disable the on-site for all cases (Even if a user is debarred, etc.)','YesNo'),
222
('OnSiteCheckoutsForce','0','','Enable/Disable the on-site for all cases (Even if a user is debarred, etc.)','YesNo'),
220
('InProcessingToShelvingCart','0','','If set, when any item with a location code of PROC is \'checked in\', it\'s location code will be changed to CART.','YesNo'),
223
('InProcessingToShelvingCart','0','','If set, when any item with a location code of PROC is \'checked in\', it\'s location code will be changed to CART.','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref (+12 lines)
Lines 362-367 Enhanced Content: Link Here
362
            - If you enable access, you must register auth return url of
362
            - If you enable access, you must register auth return url of
363
            - http(s)://my.opac.hostname/cgi-bin/koha/external/overdrive/auth.pl
363
            - http(s)://my.opac.hostname/cgi-bin/koha/external/overdrive/auth.pl
364
            - with OverDrive.
364
            - with OverDrive.
365
    RecordedBooks:
366
        -
367
            - Include RecordedBooks availability information with the client secret
368
            - pref: RecordedBooksClientSecret
369
            - .
370
        -
371
            - Show items from the RecordedBooks catalog of library ID
372
            - pref: RecordedBooksLibraryID
373
            - .
374
        -
375
            - RecordedBooks domain
376
            - pref: RecordedBooksDomain
365
    Coce Cover images cache:
377
    Coce Cover images cache:
366
        -
378
        -
367
            - pref: Coce
379
            - pref: Coce
(-)a/t/db_dependent/Koha_ExternalContent_RecordedBooks.t (-1 / +55 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use t::lib::Mocks;
4
use t::lib::TestBuilder;
5
use Test::More tests => 3;                      # last test to print
6
use C4::Auth;
7
use Koha::Database;
8
9
use Module::Load::Conditional qw( can_load );
10
SKIP: {
11
    skip "cannot filnd WebService::ILS::RecordedBooks::PartnerPatron", 3
12
      unless can_load( modules => {'WebService::ILS::RecordedBooks::PartnerPatron' => undef} );
13
14
    use_ok('Koha::ExternalContent::RecordedBooks');
15
16
    my $ocd_user_email = $ENV{RECORDEDBOOKS_TEST_USER_EMAIL};
17
    SKIP: {
18
        skip "Env RECORDEDBOOKS_TEST_USER_EMAIL not set", 2 unless $ocd_user_email;
19
20
        my $ocd_secret = $ENV{RECORDEDBOOKS_TEST_CLIENT_SECRET}
21
          || C4::Context->preference('RecordedBooksClientSecret');
22
        my $ocd_library_id = $ENV{RECORDEDBOOKS_TEST_LIBRARY_ID}
23
          || C4::Context->preference('RecordedBooksLibraryID');
24
        my $ocd_domain = $ENV{RECORDEDBOOKS_TEST_DOMAIN}
25
          || C4::Context->preference('RecordedBooksDomain');
26
        skip "Env RECORDEDBOOKS_TEST_CLIENT_SECRET RECORDEDBOOKS_TEST_LIBRARY_ID RECORDEDBOOKS_TEST_DOMAIN not set", 2
27
          unless $ocd_secret && $ocd_library_id && $ocd_domain;
28
29
        my $schema = Koha::Database->schema;
30
        $schema->storage->txn_begin;
31
        my $builder = t::lib::TestBuilder->new();
32
33
        t::lib::Mocks::mock_preference('RecordedBooksClientSecret', $ocd_secret);
34
        t::lib::Mocks::mock_preference('RecordedBooksLibraryID', $ocd_library_id);
35
        t::lib::Mocks::mock_preference('RecordedBooksDomain', $ocd_domain);
36
37
        my $patron = $builder->build({
38
            source => 'Borrower',
39
            value => {
40
                email => $ocd_user_email,
41
            }
42
        });
43
44
        my $session = C4::Auth::get_session("");
45
        $session->param('number', $patron->{borrowernumber});
46
        $session->flush;
47
        my $client = Koha::ExternalContent::RecordedBooks->new({koha_session_id => $session->id});
48
49
        my $user_agent_string = $client->user_agent->agent();
50
        ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set')
51
          or diag("User Agent string: $user_agent_string");
52
53
        ok ($client->search({query => "school"}), 'search()');
54
    }
55
}

Return to bug 17602