Bug 11808 - When searching for a cardnumber in the intranet, also try to search for it on the LDAP server if one is configured and add/update user
Summary: When searching for a cardnumber in the intranet, also try to search for it on...
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Authentication (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Maryse Simard
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-20 21:39 UTC by Frédérick Capovilla
Modified: 2024-03-06 21:49 UTC (History)
14 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Medium patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Add the SearchCardnumberWithLDAP system preference. (7.01 KB, patch)
2014-02-20 21:39 UTC, Frédérick Capovilla
Details | Diff | Splinter Review
Fix system preference and add a note to the preference description. (9.14 KB, patch)
2014-03-14 21:04 UTC, Frédérick Capovilla
Details | Diff | Splinter Review
Bug 11808 - Add the SearchCardnumberWithLDAP system preference. (9.43 KB, patch)
2017-02-22 16:29 UTC, Mehdi Hamidi
Details | Diff | Splinter Review
Bug 11808: Add the SearchCardnumberWithLDAP system preference. (9.54 KB, patch)
2019-10-04 21:48 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 11808: (QA follow-up) Adds a third option to SearchCardnumberWithLDAP and other fixes (11.48 KB, patch)
2019-10-04 21:48 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 11808: (QA follow-up) Adds support for other patron searches (22.11 KB, patch)
2019-11-19 16:16 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 11808: Add the SearchCardnumberWithLDAP system preference (16.80 KB, patch)
2022-12-23 13:57 UTC, Shi Yao Wang
Details | Diff | Splinter Review
Bug 11808: Add the SearchCardnumberWithLDAP system preference (16.91 KB, patch)
2022-12-23 16:48 UTC, Shi Yao Wang
Details | Diff | Splinter Review
Bug 11808: Add the SearchCardnumberWithLDAP system preference (17.82 KB, patch)
2024-03-06 21:49 UTC, Phan Tung Bui
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Frédérick Capovilla 2014-02-20 21:39:04 UTC Comment hidden (obsolete)
Comment 1 Frédérick Capovilla 2014-02-20 21:50:48 UTC
To test this feature, you must have a LDAP server and configure it in your "koha-conf.xml" with at least mappings for the cardnumber and firstname fields. Make sure all required fields are mapped.

Test case 1 :
* Add a borrower with the cardnumber "12345" and the name "Test user" on your LDAP server. Make sure this cardnumber doesn't exist in your Koha database.
* Activate the "SearchCardnumberWithLDAP" system preference.
* Go to the "Circulation" section and search for the "12345" cardnumber to do a checkout.
* You should be redirected to the circulation page for the "Test user" borrower, which means the LDAP user was successfully added to the local database.
* Modify the "12345" user on your LDAP server. For example, change its name to "Bob".
* Go to the "Circulation" section and search for the "12345" cardnumber again.
* The user's name should now be "Bob" on the circulation page.

Test case 2 :
* Disable the "SearchCardnumberWithLDAP" system preference.
* Modify the "12345" user on your LDAP server. For example, change its name to "Lisa".
* Go to the "Circulation" section and search for the "12345" cardnumber again.
* The user's name should still be "Bob" because the account was not updated this time.
* Add a borrower with the cardnumber "123456" and the name "Test user 2" on your LDAP server. Make sure this cardnumber doesn't exist in your Koha database.
* Go to the "Circulation" section and search for the "123456" cardnumber to do a checkout.
* "No patron matched '123456'" should be shown.
Comment 2 Dobrica Pavlinusic 2014-03-12 11:25:24 UTC
Proposed solution in this patch is not compatible with auth_by_bind LDAP option.

I don't have a real solution here since auth_by_bind requires patron's password to bind to LDAP server which is not available if patron is not logging in.

This should not be total show-stopper since this option is a syspref, but it would be nice if users knew somehow that even if they turn on this option, but use auth_by_bind that it will not work.
Comment 3 Frédérick Capovilla 2014-03-14 21:04:56 UTC
Created attachment 26374 [details] [review]
Fix system preference and add a note to the preference description.

Here is a new version of the patch which adds a note on the fact that it won't work with auth_by_bind.

I also added the SQL updates I forgot in my first version of this patch.
Comment 4 Martin Renvoize 2014-12-17 11:00:29 UTC
Interesting patch... could we have this re-based so I may test it?
Comment 5 Mehdi Hamidi 2017-02-22 16:29:18 UTC
Created attachment 60562 [details] [review]
Bug 11808 - Add the SearchCardnumberWithLDAP system preference.

When activated, cardnumber searches in the intranet will also do a
search on the LDAP server if a user was not found in the local database.
If the cardnumber is found on the LDAP server, the user account is
imported in the local database.
Comment 6 Martin Renvoize 2019-02-04 12:23:30 UTC
I think we need a second syspref added here as it sneaks in an additional LDAP lookup per local search result to allow for a Sync operation.  This could add a not insignificant additional load to the remote LDAP server which some users may wish to avoid.
Comment 7 Katrin Fischer 2019-02-06 06:28:48 UTC
+('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')

Could we maybe wrap it into 3 options for the one suggested? add, add and update, don't do anything (not sure how to phrase that to make it work)
Comment 8 Martin Renvoize 2019-02-13 14:30:44 UTC
Hmm.. I would love to see this in.. but I don't think it's really ready as it stands.. it's not comprehensive (only works in circulation, not patron searching in general and even within circulation it's not updating in the case where a borrower is found by their cardnumber rather than any other search fields).

The routines are also not especially generalised, expecting the return of a datatables centric method call rather than a Koha::Patron (or even borrower row) structure.

I'm afraid I'd have to Fail QA on it for those reasons.  Not sure I'm going to get around to proposing an alternate solution any time soon though :(
Comment 9 Maryse Simard 2019-10-04 21:48:47 UTC
Created attachment 93767 [details] [review]
Bug 11808: Add the SearchCardnumberWithLDAP system preference.

When activated, cardnumber searches in the intranet will also do a
search on the LDAP server if a user was not found in the local database.
If the cardnumber is found on the LDAP server, the user account is
imported in the local database.
Comment 10 Maryse Simard 2019-10-04 21:48:50 UTC
Created attachment 93768 [details] [review]
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.
Comment 11 Maryse Simard 2019-10-04 21:54:02 UTC
For now, I've rebased the patch on current master and started to fix the problems reported. Among those fixes, I've added a third option, as Katrin suggested, for the system preference.
Comment 12 Katrin Fischer 2019-11-02 11:55:16 UTC
(In reply to Maryse Simard from comment #11)
> For now, I've rebased the patch on current master and started to fix the
> problems reported. Among those fixes, I've added a third option, as Katrin
> suggested, for the system preference.

Hi Maryse, is this ready for testing again yet? If so, please remember to switch the status!
Comment 13 Rui 2019-11-14 10:55:23 UTC
This functionality is absolutely essential in some institutional/corporate environments, and is a much better idea than using scripts to synchronize all users. 

We've just tested the patches and all is working as expected from a user perspective. However, there is room for improvement:

a) when the user doesn't exist locally, if you checkout using circulation introducing cardnumber, the user is added as expected. However, in my opinion, it should be added as well if "Search patrons" is used and cardnumber is introduced in that form, which doesn't happen at the moment.
b) if the user doesn't have branch code defined in the AD an error regarding FK constraints is produced. Koha should deal with that gracefully.

Thanks a lot for your work.
Comment 14 Maryse Simard 2019-11-19 16:16:38 UTC
Created attachment 95573 [details] [review]
Bug 11808: (QA follow-up) Adds support for other patron searches

This patch add supports to other pages where patron search is
possible: patron search, hold and article requests.

Removes the code that tried to support searching for
search fields other than cardnumber in circulation.pl

Catch exception on broken FK contraint if information on the LDAP
server can't be added to the database as to not interrupt
execution. The error message is shown on the UI.

Revised test plan:
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 it's cardnumber in the following locations.
Do not choose from the dropdown list, use the submit button.
    - circ/circulation.pl
    - circ/article-request.pl
    - reserve/request.pl
    - members/member.pl both at the top and in the filter box
    - any page using common/patron_search.tt, for example adding a
    guarantor with the members/guarantor_search.pl popup
    => Should return cardnumber/patron not found or no results

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.

11. Try searching for a patron who doesn't exist in Koha and has a
nonexistant branch on the LDAP server. An error message should
appear accompanying the absence of results.
Comment 15 Maryse Simard 2019-11-19 16:21:28 UTC
Thank you very much for testing and for your feedback!

I added support for the functionality to other pages where patron search is possible, the list is in the patch description. I also added error handling, showing the error in the user interface if there is a problem when creating the new borrower in Koha.
Comment 16 Blou 2020-10-14 13:38:51 UTC
Any love?
Comment 17 Shi Yao Wang 2022-12-23 13:57:49 UTC
Created attachment 144823 [details] [review]
Bug 11808: Add the SearchCardnumberWithLDAP system preference

Add option to search patrons on ldap server when not found in local
database and import it

Test plan:
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 it's cardnumber in the following locations.
Do not choose from the dropdown list, use the submit button.
    - circ/circulation.pl
    - circ/article-request.pl
    - reserve/request.pl
    - members/member.pl both at the top and in the filter box
    - any page using common/patron_search.tt, for example adding a
    guarantor with the members/guarantor_search.pl popup
    => Should return cardnumber/patron not found or no results

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.

11. Try searching for a patron who doesn't exist in Koha and has a
nonexistant branch on the LDAP server. An error message should
appear accompanying the absence of results.
Comment 18 Shi Yao Wang 2022-12-23 14:00:34 UTC
Old patches didn't apply anymore so I made a new one with hopefully the same changes
Comment 19 Shi Yao Wang 2022-12-23 16:48:31 UTC
Created attachment 144826 [details] [review]
Bug 11808: Add the SearchCardnumberWithLDAP system preference

Add option to search patrons on ldap server when not found in local
database and import it

Test plan:
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 it's cardnumber in the following locations.
Do not choose from the dropdown list, use the submit button.
    - circ/circulation.pl
    - circ/article-request.pl
    - reserve/request.pl
    - members/member.pl both at the top and in the filter box
    - any page using common/patron_search.tt, for example adding a
    guarantor with the members/guarantor_search.pl popup
    => Should return cardnumber/patron not found or no results

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.

11. Try searching for a patron who doesn't exist in Koha and has a
nonexistant branch on the LDAP server. An error message should
appear accompanying the absence of results.
Comment 20 Phan Tung Bui 2024-03-06 21:49:52 UTC
Created attachment 162857 [details] [review]
Bug 11808: Add the SearchCardnumberWithLDAP system preference

Add option to search patrons on ldap server when not found in local
database and import it

Test plan:
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 it's cardnumber in the following locations.
Do not choose from the dropdown list, use the submit button.
    - circ/circulation.pl
    - circ/article-request.pl
    - reserve/request.pl
    - members/member.pl both at the top and in the filter box
    - any page using common/patron_search.tt, for example adding a
    guarantor with the members/guarantor_search.pl popup
    => Should return cardnumber/patron not found or no results

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.

11. Try searching for a patron who doesn't exist in Koha and has a
nonexistant branch on the LDAP server. An error message should
appear accompanying the absence of results.