Bugzilla – Attachment 76181 Details for
Bug 17602
Integrate support for RecordedBooks (formerly OneClickDigital) API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17602: RecordedBooks Integration to Koha
Bug-17602-RecordedBooks-Integration-to-Koha.patch (text/plain), 10.16 KB, created by
Jonathan Druart
on 2018-06-19 18:55:33 UTC
(
hide
)
Description:
Bug 17602: RecordedBooks Integration to Koha
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2018-06-19 18:55:33 UTC
Size:
10.16 KB
patch
obsolete
>From 7ba8ece1534bbbcecfb5b3dedbeb597813732a3d Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Fri, 23 Sep 2016 18:08:30 +1200 >Subject: [PATCH] Bug 17602: RecordedBooks Integration to Koha > >This patch introduces the required sysprefs and Koha::ExternalContent::RecordedBooks > >Koha::ExternalContent::RecordedBooks - a wrapper around >WebService::ILS::RecordedBooks::PartnerPatron > >RecordedBooks* sysprefs > >Nothing functional to test with this patch yet. >But you can run the tests that come with it > > t/db_dependent/Koha_ExternalContent_RecordedBooks.t > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/ExternalContent/RecordedBooks.pm | 111 +++++++++++++++++++++ > .../data/mysql/atomicupdate/recordedbooks.sql | 4 + > installer/data/mysql/sysprefs.sql | 3 + > .../admin/preferences/enhanced_content.pref | 12 +++ > .../Koha_ExternalContent_RecordedBooks.t | 55 ++++++++++ > 5 files changed, 185 insertions(+) > create mode 100644 Koha/ExternalContent/RecordedBooks.pm > create mode 100644 installer/data/mysql/atomicupdate/recordedbooks.sql > create mode 100755 t/db_dependent/Koha_ExternalContent_RecordedBooks.t > >diff --git a/Koha/ExternalContent/RecordedBooks.pm b/Koha/ExternalContent/RecordedBooks.pm >new file mode 100644 >index 0000000000..20a8fe46cf >--- /dev/null >+++ b/Koha/ExternalContent/RecordedBooks.pm >@@ -0,0 +1,111 @@ >+# Copyright 2016 Catalyst >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+package Koha::ExternalContent::RecordedBooks; >+ >+use Modern::Perl; >+use Carp; >+ >+use base qw(Koha::ExternalContent); >+use WebService::ILS::RecordedBooks::PartnerPatron; >+use WebService::ILS::RecordedBooks::Partner; >+use C4::Context; >+use Koha::Logger; >+ >+use constant logger => Koha::Logger->get(); >+ >+__PACKAGE__->mk_accessors(qw(domain is_identified)); >+ >+=head1 NAME >+ >+Koha::ExternalContent::RecordedBooks >+ >+=head1 SYNOPSIS >+ >+ use Koha::ExternalContent::RecordedBooks; >+ my $od_client = Koha::ExternalContent::RecordedBooks->new(); >+ my $od_auth_url = $od_client->auth_url(); >+ >+=head1 DESCRIPTION >+ >+A (very) thin wrapper around C<WebService::ILS::RecordedBooks::Patron> >+ >+Takes "RecordedBooks*" Koha preferences >+ >+=cut >+ >+sub new { >+ my $class = shift; >+ my $params = shift || {}; >+ >+ my $self = $class->SUPER::new($params); >+ unless ($params->{client}) { >+ my $client_secret = C4::Context->preference('RecordedBooksClientSecret') >+ or croak("RecordedBooksClientSecret pref not set"); >+ my $library_id = C4::Context->preference('RecordedBooksLibraryID') >+ or croak("RecordedBooksLibraryID pref not set"); >+ my $domain = C4::Context->preference('RecordedBooksDomain'); >+ my $patron = $params->{koha_session_id} ? $self->koha_patron : undef; >+ my $email; >+ if ($patron) { >+ $email = $patron->email >+ or $self->logger->warn("User with no email, cannot identify with RecordedBooks"); >+ } >+ my $client; >+ if ($email) { >+ local $@; >+ $client = eval { WebService::ILS::RecordedBooks::PartnerPatron->new( >+ client_secret => $client_secret, >+ library_id => $library_id, >+ domain => $domain, >+ user_id => $email, >+ user_agent_params => { agent => $class->agent_string } >+ ) }; >+ $self->logger->warn("Invalid RecordedBooks user $email ($@)") if $@; >+ $self->is_identified($client); >+ } >+ $client ||= WebService::ILS::RecordedBooks::Partner->new( >+ client_secret => $client_secret, >+ library_id => $library_id, >+ domain => $domain, >+ ); >+ $self->client( $client ); >+ } >+ return $self; >+} >+ >+=head1 METHODS >+ >+L<WebService::ILS::RecordedBooks::PartnerPatron> methods used without mods: >+ >+=over 4 >+ >+=item C<error_message()> >+ >+=back >+ >+=cut >+ >+use vars qw{$AUTOLOAD}; >+sub AUTOLOAD { >+ my $self = shift; >+ (my $method = $AUTOLOAD) =~ s/.*:://; >+ return $self->client->$method(@_); >+} >+sub DESTROY { } >+ >+1; >diff --git a/installer/data/mysql/atomicupdate/recordedbooks.sql b/installer/data/mysql/atomicupdate/recordedbooks.sql >new file mode 100644 >index 0000000000..2caa4006e5 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/recordedbooks.sql >@@ -0,0 +1,4 @@ >+INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) >+VALUES ('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'), >+ ('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'), >+ ('RecordedBooksDomain','','','RecordedBooks domain','Free'); >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 2ea76a48dc..e4e8b90beb 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -212,6 +212,9 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'), > ('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'), > ('IntranetCatalogSearchPulldown','0', NULL, 'Show a search field pulldown for \"Search the catalog\" boxes','YesNo'), >+('RecordedBooksClientSecret','','30','Client key for RecordedBooks integration','YesNo'), >+('RecordedBooksDomain','','','RecordedBooks domain','Free'), >+('RecordedBooksLibraryID','','','Library ID for RecordedBooks integration','Integer'), > ('OnSiteCheckouts','0','','Enable/Disable the on-site checkouts feature','YesNo'), > ('OnSiteCheckoutsForce','0','','Enable/Disable the on-site for all cases (Even if a user is debarred, etc.)','YesNo'), > ('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'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref >index 81e96c6147..f34818cfc9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref >@@ -378,6 +378,18 @@ Enhanced Content: > - If you enable access, you must register auth return url of > - http(s)://my.opac.hostname/cgi-bin/koha/external/overdrive/auth.pl > - with OverDrive. >+ RecordedBooks: >+ - >+ - Include RecordedBooks availability information with the client secret >+ - pref: RecordedBooksClientSecret >+ - . >+ - >+ - Show items from the RecordedBooks catalog of library ID >+ - pref: RecordedBooksLibraryID >+ - . >+ - >+ - RecordedBooks domain >+ - pref: RecordedBooksDomain > Coce Cover images cache: > - > - pref: Coce >diff --git a/t/db_dependent/Koha_ExternalContent_RecordedBooks.t b/t/db_dependent/Koha_ExternalContent_RecordedBooks.t >new file mode 100755 >index 0000000000..7f21be9721 >--- /dev/null >+++ b/t/db_dependent/Koha_ExternalContent_RecordedBooks.t >@@ -0,0 +1,55 @@ >+use Modern::Perl; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+use Test::More tests => 3; # last test to print >+use C4::Auth; >+use Koha::Database; >+ >+use Module::Load::Conditional qw( can_load ); >+SKIP: { >+ skip "cannot filnd WebService::ILS::RecordedBooks::PartnerPatron", 3 >+ unless can_load( modules => {'WebService::ILS::RecordedBooks::PartnerPatron' => undef} ); >+ >+ use_ok('Koha::ExternalContent::RecordedBooks'); >+ >+ my $ocd_user_email = $ENV{RECORDEDBOOKS_TEST_USER_EMAIL}; >+ SKIP: { >+ skip "Env RECORDEDBOOKS_TEST_USER_EMAIL not set", 2 unless $ocd_user_email; >+ >+ my $ocd_secret = $ENV{RECORDEDBOOKS_TEST_CLIENT_SECRET} >+ || C4::Context->preference('RecordedBooksClientSecret'); >+ my $ocd_library_id = $ENV{RECORDEDBOOKS_TEST_LIBRARY_ID} >+ || C4::Context->preference('RecordedBooksLibraryID'); >+ my $ocd_domain = $ENV{RECORDEDBOOKS_TEST_DOMAIN} >+ || C4::Context->preference('RecordedBooksDomain'); >+ skip "Env RECORDEDBOOKS_TEST_CLIENT_SECRET RECORDEDBOOKS_TEST_LIBRARY_ID RECORDEDBOOKS_TEST_DOMAIN not set", 2 >+ unless $ocd_secret && $ocd_library_id && $ocd_domain; >+ >+ my $schema = Koha::Database->schema; >+ $schema->storage->txn_begin; >+ my $builder = t::lib::TestBuilder->new(); >+ >+ t::lib::Mocks::mock_preference('RecordedBooksClientSecret', $ocd_secret); >+ t::lib::Mocks::mock_preference('RecordedBooksLibraryID', $ocd_library_id); >+ t::lib::Mocks::mock_preference('RecordedBooksDomain', $ocd_domain); >+ >+ my $patron = $builder->build({ >+ source => 'Borrower', >+ value => { >+ email => $ocd_user_email, >+ } >+ }); >+ >+ my $session = C4::Auth::get_session(""); >+ $session->param('number', $patron->{borrowernumber}); >+ $session->flush; >+ my $client = Koha::ExternalContent::RecordedBooks->new({koha_session_id => $session->id}); >+ >+ my $user_agent_string = $client->user_agent->agent(); >+ ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set') >+ or diag("User Agent string: $user_agent_string"); >+ >+ ok ($client->search({query => "school"}), 'search()'); >+ } >+} >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17602
:
57402
|
57403
|
57404
|
60855
|
60856
|
60857
|
61866
|
61932
|
62247
|
62248
|
62249
|
62250
|
63392
|
63778
|
63779
|
63780
|
63857
|
64070
|
64071
|
64095
|
64096
|
64098
|
64099
|
64100
|
65988
|
65989
|
66341
|
66342
|
66343
|
67236
|
67237
|
67238
|
67240
|
67859
|
67860
|
69019
|
69020
|
69021
|
69022
|
69023
|
69024
|
69025
|
69026
|
69027
|
69101
|
69357
|
69358
|
69359
|
73708
|
73709
|
73710
|
73711
|
73712
|
73713
|
73714
|
73715
|
73716
|
73717
|
73718
|
73719
|
73725
|
76180
|
76181
|
76182
|
76183
|
76184
|
76185
|
76186
|
76187
|
76188
|
76189
|
76190
|
76191
|
76192
|
76193
|
78602
|
78603
|
78604
|
78605
|
78606
|
78607
|
78608
|
78609
|
78610
|
78611
|
78612
|
78613
|
78614
|
78615
|
79247
|
79668
|
79669
|
79670
|
79671
|
79672
|
79673
|
79674
|
79675
|
79676
|
79677
|
79678
|
79679
|
79680
|
79681
|
79682
|
79752