From b1541c7da575be447ab9e483aad6675c908250c9 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Fri, 4 Oct 2019 11:37:47 -0400 Subject: [PATCH] Bug 11808: (QA follow-up) Adds a third option to SearchCardnumberWithLDAP and other fixes This patch does a few things: - Adds a third option to the new system preference to choose between: never use ldap, make a request (and add) only when no patron is found, and always make a request (add/update). - Adds search and update with ldap in the case the patron is found by it's cardnumber in circulation. - Use Patron object in the new subs in C4/Auth_with_ldap.pm. To test: 0. You need to have an ldap server containing patron informations configured in Koha. 1. Apply patch and update database. 2. Check that the new system preference SearchCardnumberWithLDAP has been added and set as 'never'. 3. Choose a patron who exists in your ldap server but not in Koha. (you can delete an existing patron from Koha if needed) 4. Search for the patron by both it's cardnumber and any other attributes (results should be the same in both case) in the search bar in circ/circulation.pl.Do not choose from the dropdown list, use the submit button. => Should return cardnumber not found 5. Change SearchCardnumberWithLDAP to 'if not found locally'. 6. Repeat step 4. => The patron should be added to Koha. 7. Edit the patron and change any of the existing information. 8. Repeat step 4. => The patron has not been updated (the change made in step 7 is still there) 9. Change SearchCardnumberWithLDAP to 'always'. 10. Repeat step 4. => The patron has been updated. Change made in step 7 has been rewritten and patron informations is the same as in step 6. --- C4/Auth_with_ldap.pm | 6 +++--- circ/circulation.pl | 15 ++++++++++++--- installer/data/mysql/atomicupdate/bug_11808.perl | 10 ++++++++++ .../bug_11808_SearchCardnumberWithLDAP_sys_pref.sql | 2 -- installer/data/mysql/sysprefs.sql | 4 ++-- .../prog/en/modules/admin/preferences/patrons.pref | 7 ++++--- .../intranet-tmpl/prog/en/modules/circ/circulation.tt | 7 ++++++- 7 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_11808.perl delete mode 100644 installer/data/mysql/atomicupdate/bug_11808_SearchCardnumberWithLDAP_sys_pref.sql diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 3a707ee..57faab9 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -398,8 +398,8 @@ sub update_local { # Subroutine to update a user with LDAP using its cardnumber. sub updateborrower_ldap { - my $local_borrower = shift; - my $cardnumber = $local_borrower->{'cardnumber'}; + my $patron = shift; + my $cardnumber = $patron->cardnumber; return 0 unless ($config{update}); @@ -425,7 +425,7 @@ sub updateborrower_ldap { if ($count == 1) { # User was found, update! my %borrower = ldap_entry_2_hash($search->shift_entry,$cardnumber); - &update_local($local_borrower->{userid},$local_borrower->{password},$local_borrower->{borrowernumber},\%borrower); + &update_local($patron->userid, $patron->password, $patron->borrowernumber, \%borrower); return 1; } diff --git a/circ/circulation.pl b/circ/circulation.pl index 10338f6..fd23f1d 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -252,6 +252,11 @@ if ($findborrower) { my $patron = Koha::Patrons->find( { cardnumber => $findborrower } ); if ( $patron ) { $borrowernumber = $patron->borrowernumber; + # Update the user with LDAP if we need to + if(C4::Context->config('useldapserver') and C4::Context->preference("SearchCardnumberWithLDAP") eq "always") { + my ($result, $ldap_error) = C4::Auth_with_ldap::updateborrower_ldap($patron); + $template->param(ldap_error => $ldap_error) if $ldap_error; + } } else { my $dt_params = { iDisplayLength => -1 }; my $results = C4::Utils::DataTables::Members::search( @@ -265,8 +270,9 @@ if ($findborrower) { if ( scalar @$borrowers == 1 ) { $borrowernumber = $borrowers->[0]->{borrowernumber}; # Update the user with LDAP if we need to - if(C4::Context->config('useldapserver') and C4::Context->preference("SearchCardnumberWithLDAP")) { - my ($result, $ldap_error) = C4::Auth_with_ldap::updateborrower_ldap($borrowers->[0]); + if(C4::Context->config('useldapserver') and C4::Context->preference("SearchCardnumberWithLDAP") eq "always") { + my $patron_obj = Koha::Patrons->find( $borrowernumber ); + my ($result, $ldap_error) = C4::Auth_with_ldap::updateborrower_ldap($patron_obj); $template->param(ldap_error => $ldap_error) if $ldap_error; } $query->param( 'borrowernumber', $borrowernumber ); @@ -275,8 +281,11 @@ if ($findborrower) { # Try to find a user using LDAP if we couldn't find it locally my $borrowernumber_ldap; my $ldap_error; - if (C4::Context->config('useldapserver') and C4::Context->preference("SearchCardnumberWithLDAP")) { + if (C4::Context->config('useldapserver') and + (C4::Context->preference("SearchCardnumberWithLDAP") eq "always" or C4::Context->preference("SearchCardnumberWithLDAP") eq "not_found") + ) { ($borrowernumber_ldap, $ldap_error) = C4::Auth_with_ldap::findcardnumber_ldap($findborrower); + $template->param(ldap_error => $ldap_error) if $ldap_error; } if ($borrowernumber_ldap) { diff --git a/installer/data/mysql/atomicupdate/bug_11808.perl b/installer/data/mysql/atomicupdate/bug_11808.perl new file mode 100644 index 0000000..f871d28 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_11808.perl @@ -0,0 +1,10 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('SearchCardnumberWithLDAP', 'never', 'Search for a cardnumber with LDAP when searching for a patron that does not exist locally. If the cardnumber is found via LDAP, the user is added or updated.', 'always|not_found|never', 'Choice'); + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 11808 - Search cardnumber on the LDAP server if one is configured and add/update user.)\n"; +} \ No newline at end of file diff --git a/installer/data/mysql/atomicupdate/bug_11808_SearchCardnumberWithLDAP_sys_pref.sql b/installer/data/mysql/atomicupdate/bug_11808_SearchCardnumberWithLDAP_sys_pref.sql deleted file mode 100644 index 5ccf071..0000000 --- a/installer/data/mysql/atomicupdate/bug_11808_SearchCardnumberWithLDAP_sys_pref.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO systempreferences (variable,value,explanation,options,type) -VALUES('SearchCardnumberWithLDAP','','Search for a cardnumber with LDAP when trying to do a checkout with a cardnumber that does not exist locally. If the cardnumber is found via LDAP, the user is added locally.','','YesNo'); \ No newline at end of file diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 08c6a00..433f5d7 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -533,6 +533,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'), ('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded