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.14',
864
    },
864
    },
865
};
865
};
866
866
(-)a/Koha/ExternalContent/OneClickDigital.pm (+106 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::OneClickDigital;
19
20
use Modern::Perl;
21
use Carp;
22
23
use base qw(Koha::ExternalContent);
24
use WebService::ILS::OneClickDigital::PartnerPatron;
25
use WebService::ILS::OneClickDigital::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::OneClickDigital
36
37
=head1 SYNOPSIS
38
39
    use Koha::ExternalContent::OneClickDigital;
40
    my $od_client = Koha::ExternalContent::OneClickDigital->new();
41
    my $od_auth_url = $od_client->auth_url();
42
43
=head1 DESCRIPTION
44
45
A (very) thin wrapper around C<WebService::ILS::OneClickDigital::Patron>
46
47
Takes "OneClickDigital*" 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('OneClickDigitalClientSecret')
58
          or croak("OneClickDigitalClientSecret pref not set");
59
        my $library_id     = C4::Context->preference('OneClickDigitalLibraryID')
60
          or croak("OneClickDigitalLibraryID pref not set");
61
        my $domain         = C4::Context->preference('OneClickDigitalDomain');
62
        my $patron = $params->{koha_session_id} ? $self->koha_patron : undef;
63
        my $client;
64
        if ($patron) {
65
            local $@;
66
            $client = eval { WebService::ILS::OneClickDigital::PartnerPatron->new(
67
                client_secret     => $client_secret,
68
                library_id        => $library_id,
69
                domain            => $domain,
70
                user_id           => $patron->email,
71
                user_agent_params => { agent => $class->agent_string }
72
            ) };
73
            $self->logger->warn("Invalid OneClickDigital user ".$patron->email." ($@)") if $@;
74
            $self->is_identified($client);
75
        }
76
        $client ||= WebService::ILS::OneClickDigital::Partner->new(
77
                client_secret     => $client_secret,
78
                library_id        => $library_id,
79
                domain            => $domain,
80
        );
81
        $self->client( $client );
82
    }
83
    return $self;
84
}
85
86
=head1 METHODS
87
88
L<WebService::ILS::OneClickDigital::PartnerPatron> methods used without mods:
89
90
=over 4
91
92
=item C<error_message()>
93
94
=back
95
96
=cut
97
98
use vars qw{$AUTOLOAD};
99
sub AUTOLOAD {
100
    my $self = shift;
101
    (my $method = $AUTOLOAD) =~ s/.*:://;
102
    return $self->client->$method(@_);
103
}
104
sub DESTROY { }
105
106
1;
(-)a/installer/data/mysql/atomicupdate/oneclickdigital.sql (+4 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
2
VALUES ('OneClickDigitalClientSecret','','30','Client key for OneClickDigital integration','YesNo'),
3
       ('OneClickDigitalLibraryID','','','Library ID for OneClickDigital integration','Integer'),
4
       ('OneClickDigitalDomain','','','OneClickDigital 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
('OneClickDigitalClientSecret','','30','Client key for OneClickDigital integration','YesNo'),
206
('OneClickDigitalDomain','','','OneClickDigital domain','Free'),
207
('OneClickDigitalLibraryID','','','Library ID for OneClickDigital 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
    OneClickDigital:
376
        -
377
            - Include OneClickDigital availability information with the client secret
378
            - pref: OneClickDigitalClientSecret
379
            - .
380
        -
381
            - "Show items from the OneClickDigital catalog of library #"
382
            - pref: OneClickDigitalLibraryID
383
            - .
384
        -
385
            - OneClickDigital domain
386
            - pref: OneClickDigitalDomain
375
    Coce Cover images cache:
387
    Coce Cover images cache:
376
        -
388
        -
377
            - pref: Coce
389
            - pref: Coce
(-)a/t/db_dependent/Koha_ExternalContent_OneClickDigital.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::OneClickDigital::PartnerPatron", 3
12
      unless can_load( modules => {'WebService::ILS::OneClickDigital::PartnerPatron' => undef} );
13
14
    use_ok('Koha::ExternalContent::OneClickDigital');
15
16
    my $ocd_user_email = $ENV{ONECLICKDIGITAL_TEST_USER_EMAIL};
17
    SKIP: {
18
        skip "Env ONECLICKDIGITAL_TEST_USER_EMAIL not set", 2 unless $ocd_user_email;
19
20
        my $ocd_secret = $ENV{ONECLICKDIGITAL_TEST_CLIENT_SECRET}
21
          || C4::Context->preference('OneClickDigitalClientSecret');
22
        my $ocd_library_id = $ENV{ONECLICKDIGITAL_TEST_LIBRARY_ID}
23
          || C4::Context->preference('OneClickDigitalLibraryID');
24
        my $ocd_domain = $ENV{ONECLICKDIGITAL_TEST_DOMAIN}
25
          || C4::Context->preference('OneClickDigitalDomain');
26
        skip "Env ONECLICKDIGITAL_TEST_CLIENT_SECRET ONECLICKDIGITAL_TEST_LIBRARY_ID ONECLICKDIGITAL_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('OneClickDigitalClientSecret', $ocd_secret);
34
        t::lib::Mocks::mock_preference('OneClickDigitalLibraryID', $ocd_library_id);
35
        t::lib::Mocks::mock_preference('OneClickDigitalDomain', $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::OneClickDigital->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