Bug 22030: Use preference to determine username sent to overdrive
authorNick Clemens <nick@bywatersolutions.com>
Wed, 19 Dec 2018 17:53:08 +0000 (17:53 +0000)
committerJesse Maseto <jesse@bywatersolutions.com>
Fri, 11 Jan 2019 18:54:41 +0000 (18:54 +0000)
Overdrive configuration generally defaults to cardnumber, however, they
have confirmed that some libraries use usernames. We need to allow for
both scenarios.

To test:
1 - Have an OverDrive account setup with SIP authentication
    Note: You can apply for a testing account at developer.overdrive.com
    and setup an environment
2 - Fill in all your OverDrive system preferences
3 - Test with a patron whose username is their cardnumber
4 - Confirm their overdrive account tab on opac loads
5 - Change the username to be another value like "borked_wont_work"
6 - Note the overdrive account tab won't load
7 - Apply patch, update database, not new system preference
OverDriveUsername (default to 'cardnumber)
8 - Note the OD account loads successfully
9 - Change the system preference to 'user name' - the account load fails

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 96adab7af8999da7f351169e1265d4be5e59742f)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 274271b59d5491dc44ebe7bbfb12da13e96d2ceb)

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>

installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
opac/svc/overdrive

diff --git a/installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl b/installer/data/mysql/atomicupdate/bug_22030_add_OverDriveUsername_system_preference.perl
new file mode 100644 (file)
index 0000000..7304778
--- /dev/null
@@ -0,0 +1,9 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('OverDriveUsername','cardnumber','cardnumber|userid','Which patron information should be passed as OverDrive username','Choice')
+    });
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug XXXXX - description)\n";
+}
index 9da8c1a..0623715 100644 (file)
@@ -415,6 +415,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('OverDriveClientSecret','','Client key for OverDrive integration','30','YesNo'),
 ('OverDriveLibraryID','','Library ID for OverDrive integration','','Integer'),
 ('OverDrivePasswordRequired','',NULL,'Does the library require passwords for OverDrive SIP authentication','YesNo'),
+('OverDriveUsername','cardnumber','cardnumber|userid','Which patron information should be passed as OverDrive username','Choice'),
 ('OverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating overdue notices','YesNo'),
 ('OverduesBlockCirc','noblock','noblock|confirmation|block','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','Choice'),
 ('OverduesBlockRenewing','allow','allow|blockitem|block','If any of patron checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','Choice'),
index 49c5ea0..0cbd082 100644 (file)
@@ -367,6 +367,12 @@ Enhanced Content:
                   yes: Enable
                   no: "Don't enable"
             - users to access their OverDrive circulation history, and circulate items.<br />
+            - Overdrive uses the patron's
+            - pref: OverDriveUsername
+              choices:
+                  cardnumber: cardnumber
+                  userid: user name
+            - for user access to OverDrive. <br />
             - A password is
             - pref: OverDrivePasswordRequired
               choices:
index 3ede3f4..57333f0 100755 (executable)
@@ -48,9 +48,15 @@ eval {
                 my $password = $cgi->param("password") // q{} ;
                 my $patron = Koha::Patrons->find({ userid => $user });
                 my $branch_info = $patron ? Koha::Library::OverDriveInfos->find( $patron->branchcode ) : undef;
+                my $od_username;
+                if ( C4::Context->preference('OverDriveUsername') eq 'cardnumber' ){
+                    $od_username = $patron ? $patron->cardnumber : undef;
+                } else {
+                    $od_username = $user;
+                }
                 my $branch_authname = $branch_info ? $branch_info->authname : undef;
                 my $authname = $branch_authname || C4::Context->preference('OverDriveAuthname');
-                $od->auth_by_userid($user, $password,C4::Context->preference('OverDriveWebsiteID'),$authname);
+                $od->auth_by_userid($od_username, $password,C4::Context->preference('OverDriveWebsiteID'),$authname);
                 $data{login_success} = 1;
                 last;
             };