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

(-)a/C4/Installer/PerlDependencies.pm (-1 / +1 lines)
Lines 860-866 our $PERL_DEPS = { Link Here
860
    'WebService::ILS' => {
860
    'WebService::ILS' => {
861
        'usage'    => 'Interface third party systems',
861
        'usage'    => 'Interface third party systems',
862
        'required' => '0',
862
        'required' => '0',
863
        'min_ver'  => '0.07',
863
        'min_ver'  => '0.16',
864
    },
864
    },
865
};
865
};
866
866
(-)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 202-207 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
202
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
202
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
203
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
203
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
204
('IntranetCatalogSearchPulldown','0', NULL, 'Show a search field pulldown for \"Search the catalog\" boxes','YesNo'),
204
('IntranetCatalogSearchPulldown','0', NULL, 'Show a search field pulldown for \"Search the catalog\" boxes','YesNo'),
205
('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'),
206
('RecordedBooksDomain','','','RecordedBooks domain','Free'),
207
('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'),
205
('OnSiteCheckouts','0','','Enable/Disable the on-site checkouts feature','YesNo'),
208
('OnSiteCheckouts','0','','Enable/Disable the on-site checkouts feature','YesNo'),
206
('OnSiteCheckoutsForce','0','','Enable/Disable the on-site for all cases (Even if a user is debarred, etc.)','YesNo'),
209
('OnSiteCheckoutsForce','0','','Enable/Disable the on-site for all cases (Even if a user is debarred, etc.)','YesNo'),
207
('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'),
210
('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 372-377 Enhanced Content: Link Here
372
            - If you enable access, you must register auth return url of
372
            - If you enable access, you must register auth return url of
373
            - http(s)://my.opac.hostname/cgi-bin/koha/external/overdrive/auth.pl
373
            - http(s)://my.opac.hostname/cgi-bin/koha/external/overdrive/auth.pl
374
            - with OverDrive.
374
            - with OverDrive.
375
    RecordedBooks:
376
        -
377
            - Include RecordedBooks availability information with the client secret
378
            - pref: RecordedBooksClientSecret
379
            - .
380
        -
381
            - Show items from the RecordedBooks catalog of library ID
382
            - pref: RecordedBooksLibraryID
383
            - .
384
        -
385
            - RecordedBooks domain
386
            - pref: RecordedBooksDomain
375
    Coce Cover images cache:
387
    Coce Cover images cache:
376
        -
388
        -
377
            - pref: Coce
389
            - 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