Bug 34069

Summary: Add ability to restore a recently deleted borrower from deletedborrowers
Product: Koha Reporter: Liz Rea <wizzyrea>
Component: CirculationAssignee: Lucas Gass (lukeg) <lucas>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: andrew, gmcharlt, kebliss, kyle, lucas, matthias.meusburger
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Medium patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 34069: Add restore_deleted_borrowers permission
Bug 34069: Implement tool for restoring deleted patrons
Bug 34069: Log patron restoration
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add restore_deleted_borrowers permission and new system preference
Bug 34069: Implement tool for restoring deleted patrons
Bug 34069: Log patron restoration
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add ability to search on updated_on dates
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Bug 34069: Add information about what can and cannot be restored
Bug 34069: Add restore_deleted_borrowers permission and new system preference
Bug 34069: Implement tool for restoring deleted patrons
Bug 34069: Log patron restoration
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add ability to search on updated_on dates
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Bug 34069: Add information about what can and cannot be restored
Bug 34069: Move permission from borrower to tools
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints
Bug 34069: Add unit tests
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes
Bug 34069: Adjust before and after date search
Bug 34069: Prevent search if no search critrea
Bug 34069: Allow for multiselection of branch and category
Bug 34069: Logaction should not be in all caps
Bug 34069: Add restore_deleted_borrowers permission and new system preference
Bug 34069: Implement tool for restoring deleted patrons
Bug 34069: Log patron restoration
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add ability to search on updated_on dates
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Bug 34069: Add information about what can and cannot be restored
Bug 34069: Move permission from borrower to tools
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints
Bug 34069: Add unit tests
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes
Bug 34069: Adjust before and after date search
Bug 34069: Prevent search if no search critrea
Bug 34069: Allow for multiselection of branch and category
Bug 34069: Logaction should not be in all caps
Bug 34069: Add restore_deleted_borrowers permission and new system preference
Bug 34069: Implement tool for restoring deleted patrons
Bug 34069: Log patron restoration
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Bug 34069: Add ability to search on updated_on dates
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Bug 34069: Add information about what can and cannot be restored
Bug 34069: Move permission from borrower to tools
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints
Bug 34069: Add unit tests
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes
Bug 34069: Adjust before and after date search
Bug 34069: Prevent search if no search critrea
Bug 34069: Allow for multiselection of branch and category
Bug 34069: Logaction should not be in all caps

Description Liz Rea 2023-06-20 16:10:38 UTC
It would be awesome to have the ability to restore a deleted borrower from deletedborrowers. 

Of course, if the borrower you need has been purged from that table for whatever reason, it wouldn't work, but it feels like an essential missing feature since we keep the data for Reasons anyway.

Liz
Comment 1 Katrin Fischer 2023-06-22 19:18:59 UTC
Just a note that we keep some, but not all data. For example we delete the patron attributes, alerts etc. But it could still be helpful of course and some links remain.
Comment 2 Lucas Gass (lukeg) 2025-10-22 15:19:07 UTC Comment hidden (obsolete)
Comment 3 Lucas Gass (lukeg) 2025-10-22 19:32:09 UTC Comment hidden (obsolete)
Comment 4 Lucas Gass (lukeg) 2025-10-23 14:18:38 UTC
I think we want both a permission and a system preference to control this feature.
Comment 5 Lucas Gass (lukeg) 2025-11-03 18:17:01 UTC Comment hidden (obsolete)
Comment 6 Lucas Gass (lukeg) 2025-11-03 18:35:12 UTC Comment hidden (obsolete)
Comment 7 Lucas Gass (lukeg) 2025-11-03 18:37:30 UTC Comment hidden (obsolete)
Comment 8 Lucas Gass (lukeg) 2025-11-04 15:36:34 UTC Comment hidden (obsolete)
Comment 9 Lucas Gass (lukeg) 2025-11-04 15:36:36 UTC Comment hidden (obsolete)
Comment 10 Lucas Gass (lukeg) 2025-11-04 15:36:39 UTC Comment hidden (obsolete)
Comment 11 Lucas Gass (lukeg) 2025-11-04 15:36:42 UTC Comment hidden (obsolete)
Comment 12 Lucas Gass (lukeg) 2025-11-04 16:07:40 UTC Comment hidden (obsolete)
Comment 13 Lucas Gass (lukeg) 2025-11-04 21:46:05 UTC Comment hidden (obsolete)
Comment 14 Lucas Gass (lukeg) 2025-11-04 22:05:20 UTC Comment hidden (obsolete)
Comment 15 Lucas Gass (lukeg) 2025-11-07 20:22:05 UTC
Created attachment 189370 [details] [review]
Bug 34069: Add restore_deleted_borrowers permission and new system preference
Comment 16 Lucas Gass (lukeg) 2025-11-07 20:22:07 UTC
Created attachment 189371 [details] [review]
Bug 34069: Implement tool for restoring deleted patrons
Comment 17 Lucas Gass (lukeg) 2025-11-07 20:22:10 UTC
Created attachment 189372 [details] [review]
Bug 34069: Log patron restoration
Comment 18 Lucas Gass (lukeg) 2025-11-07 20:22:13 UTC
Created attachment 189373 [details] [review]
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Comment 19 Lucas Gass (lukeg) 2025-11-07 20:22:16 UTC
Created attachment 189374 [details] [review]
Bug 34069: Add ability to search on updated_on dates
Comment 20 Lucas Gass (lukeg) 2025-11-07 20:22:19 UTC
Created attachment 189375 [details] [review]
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Comment 21 Lucas Gass (lukeg) 2025-11-07 20:22:21 UTC
Created attachment 189376 [details] [review]
Bug 34069: Add information about what can and cannot be restored
Comment 22 Lucas Gass (lukeg) 2025-11-07 20:22:24 UTC
Created attachment 189377 [details] [review]
Bug 34069: Move permission from borrower to tools
Comment 23 Owen Leonard 2025-11-12 12:59:20 UTC
I know this isn't done but I took a look and wanted to mention that you probably want <div class="alert alert-info"> instead of "dialog alert bg-info-subtle". I also think the heading inside the alert should be <h2> instead of <h3>
Comment 24 Lucas Gass (lukeg) 2025-11-17 18:08:20 UTC
Created attachment 189642 [details] [review]
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints
Comment 25 Lucas Gass (lukeg) 2025-11-17 21:06:09 UTC
Created attachment 189645 [details] [review]
Bug 34069: Add unit tests
Comment 26 Andrew Fuerste-Henry 2025-11-18 20:54:07 UTC
A handful of small-ish things that should be addressed:
 - Deletin from patron record gives a message "this cannot be undone," but that won't be true anymore with these patches

- Submitting a blank search in the Restore Borrowers tool returns no patrons. We should either disallow blank search OR give clear message that blank search doesn't work

- Categorycode and branchcode are blank in deleted patron list (even though they have values in deletedborrowers)

- After restoration, "View patron" should open in new tab

- Restore Borrowers tool is not in the Tools sidebar

- Search by date should only look at date portion of updated_on -- currently a search for date range 11/17/2025 - 11/18/2025 does not return patrons deleted on 11/18/2025, but a search 11/18 - 11/19 does

- When user is limited to only see patrons in their library group they should be able to select "All libraries" and get only those they have access to -- currently such a user can restore borrowers for any library in their group, but only 1 library at a time

- RESTORE action should not be all caps in action logs
Comment 27 Lucas Gass (lukeg) 2025-11-19 19:55:01 UTC
Created attachment 189718 [details] [review]
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes
Comment 28 Lucas Gass (lukeg) 2025-11-20 13:30:21 UTC
Created attachment 189773 [details] [review]
Bug 34069: Adjust before and after date search
Comment 29 Lucas Gass (lukeg) 2025-11-20 13:57:16 UTC
Created attachment 189774 [details] [review]
Bug 34069: Prevent search if no search critrea
Comment 30 Lucas Gass (lukeg) 2025-11-20 14:38:39 UTC
Created attachment 189779 [details] [review]
Bug 34069: Allow for multiselection of branch and category
Comment 31 Lucas Gass (lukeg) 2025-11-20 14:40:05 UTC
Created attachment 189780 [details] [review]
Bug 34069: Logaction should not be in all caps
Comment 32 Lucas Gass (lukeg) 2025-11-20 14:42:17 UTC
Created attachment 189781 [details] [review]
Bug 34069: Add restore_deleted_borrowers permission and new system preference

1. APPLY PATCH, updatedatabase, restart_all
2. Now setup two users for testing, a superlibrarian and a limited permission user. The limited permission should have staff access and the restore_deleted_borrowers (tools) permission.
/* SUPERLIBRARIAN */
3. As superlibrarian, find the 'AllowDeletedPatronRestoration' system preference and enable it. Also make sure BorrowersLog is turned on.
4. Go to Tools -> Restore deleted patrons
5. Read the warning/information about what can and cannot be restored. Ensure it all makes sense.
6. Now we must delete some borrowers, either 1 by 1 or with the batch deletion tool.
7. Back to the deletion tool ( Tools -> Restore deleted patrons )
8. Search for some of your deleted patrons by any of the critrea available. ( Cardnumber, borrowernumber, first name, surname, category, branch, or date )
9. Ensure that searching works well.
10. Now bring up a deleted patron, check the checbox to the left and click "Restore deleted patrons"
11. Now you should be able to see the that the patron was restored.
12. Click "View patron" to look at the restored patron record.
13. Go to the action logs and make sure that the restoration was logged.
/* LIMITED PERMISSION USER */
14. Now log in as your limited permission user.
15. Go to Tools -> Restore deleted patrons
16. As a limited permssion user you should only be able to search for deleted borrowers from your branch, or branches in your library group.
17. Repeat all the steps to restore a patron, ensuring everything works.
Comment 33 Lucas Gass (lukeg) 2025-11-20 14:42:19 UTC
Created attachment 189782 [details] [review]
Bug 34069: Implement tool for restoring deleted patrons
Comment 34 Lucas Gass (lukeg) 2025-11-20 14:42:22 UTC
Created attachment 189783 [details] [review]
Bug 34069: Log patron restoration
Comment 35 Lucas Gass (lukeg) 2025-11-20 14:42:25 UTC
Created attachment 189784 [details] [review]
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use
Comment 36 Lucas Gass (lukeg) 2025-11-20 14:42:28 UTC
Created attachment 189785 [details] [review]
Bug 34069: Add ability to search on updated_on dates
Comment 37 Lucas Gass (lukeg) 2025-11-20 14:42:30 UTC
Created attachment 189786 [details] [review]
Bug 34069: Deal with view_borrower_infos_from_any_libraries
Comment 38 Lucas Gass (lukeg) 2025-11-20 14:42:33 UTC
Created attachment 189787 [details] [review]
Bug 34069: Add information about what can and cannot be restored
Comment 39 Lucas Gass (lukeg) 2025-11-20 14:42:36 UTC
Created attachment 189788 [details] [review]
Bug 34069: Move permission from borrower to tools
Comment 40 Lucas Gass (lukeg) 2025-11-20 14:42:39 UTC
Created attachment 189789 [details] [review]
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints
Comment 41 Lucas Gass (lukeg) 2025-11-20 14:42:42 UTC
Created attachment 189790 [details] [review]
Bug 34069: Add unit tests
Comment 42 Lucas Gass (lukeg) 2025-11-20 14:42:45 UTC
Created attachment 189791 [details] [review]
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes
Comment 43 Lucas Gass (lukeg) 2025-11-20 14:42:48 UTC
Created attachment 189792 [details] [review]
Bug 34069: Adjust before and after date search
Comment 44 Lucas Gass (lukeg) 2025-11-20 14:42:51 UTC
Created attachment 189793 [details] [review]
Bug 34069: Prevent search if no search critrea
Comment 45 Lucas Gass (lukeg) 2025-11-20 14:42:54 UTC
Created attachment 189794 [details] [review]
Bug 34069: Allow for multiselection of branch and category
Comment 46 Lucas Gass (lukeg) 2025-11-20 14:42:57 UTC
Created attachment 189795 [details] [review]
Bug 34069: Logaction should not be in all caps
Comment 47 Matthias Meusburger 2025-11-22 02:30:18 UTC
Hi!

Here are a few remarks:

I'm wondering if we should add "from the deletedborrowers table" in the syspref and tool description. It sounds more like a developer thing than a user one. It's okay to have it in the tool itself with the explanation of why not everything is restored though.

It could be useful to say in the syspref description that the option will be available on the tools page once it is enabled.

In members-home.pl, searching without any criteria brings all the patrons. I would expect the same behavior here (return all the deleted patrons instead of the "Please fill out at least one search field." message). It should not be an issue since the search results are paginated.

Otherwise, it works as expected and I'd be happy to sign-off.
Comment 48 Andrew Fuerste-Henry 2025-11-25 19:28:24 UTC
Created attachment 189940 [details] [review]
Bug 34069: Add restore_deleted_borrowers permission and new system preference

1. APPLY PATCH, updatedatabase, restart_all
2. Now setup two users for testing, a superlibrarian and a limited permission user. The limited permission should have staff access and the restore_deleted_borrowers (tools) permission.
/* SUPERLIBRARIAN */
3. As superlibrarian, find the 'AllowDeletedPatronRestoration' system preference and enable it. Also make sure BorrowersLog is turned on.
4. Go to Tools -> Restore deleted patrons
5. Read the warning/information about what can and cannot be restored. Ensure it all makes sense.
6. Now we must delete some borrowers, either 1 by 1 or with the batch deletion tool.
7. Back to the deletion tool ( Tools -> Restore deleted patrons )
8. Search for some of your deleted patrons by any of the critrea available. ( Cardnumber, borrowernumber, first name, surname, category, branch, or date )
9. Ensure that searching works well.
10. Now bring up a deleted patron, check the checbox to the left and click "Restore deleted patrons"
11. Now you should be able to see the that the patron was restored.
12. Click "View patron" to look at the restored patron record.
13. Go to the action logs and make sure that the restoration was logged.
/* LIMITED PERMISSION USER */
14. Now log in as your limited permission user.
15. Go to Tools -> Restore deleted patrons
16. As a limited permssion user you should only be able to search for deleted borrowers from your branch, or branches in your library group.
17. Repeat all the steps to restore a patron, ensuring everything works.

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 49 Andrew Fuerste-Henry 2025-11-25 19:28:27 UTC
Created attachment 189941 [details] [review]
Bug 34069: Implement tool for restoring deleted patrons

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 50 Andrew Fuerste-Henry 2025-11-25 19:28:30 UTC
Created attachment 189942 [details] [review]
Bug 34069: Log patron restoration

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 51 Andrew Fuerste-Henry 2025-11-25 19:28:32 UTC
Created attachment 189943 [details] [review]
Bug 34069: Add a CannotRestore exception and throw when the userid, borrowernumber, or cardnumber is already in use

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 52 Andrew Fuerste-Henry 2025-11-25 19:28:35 UTC
Created attachment 189944 [details] [review]
Bug 34069: Add ability to search on updated_on dates

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 53 Andrew Fuerste-Henry 2025-11-25 19:28:38 UTC
Created attachment 189945 [details] [review]
Bug 34069: Deal with view_borrower_infos_from_any_libraries

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 54 Andrew Fuerste-Henry 2025-11-25 19:28:41 UTC
Created attachment 189946 [details] [review]
Bug 34069: Add information about what can and cannot be restored

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 55 Andrew Fuerste-Henry 2025-11-25 19:28:45 UTC
Created attachment 189947 [details] [review]
Bug 34069: Move permission from borrower to tools

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 56 Andrew Fuerste-Henry 2025-11-25 19:28:48 UTC
Created attachment 189948 [details] [review]
Bug 34069: Fix HTML, Bootstrap classes, and QA complaints

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 57 Andrew Fuerste-Henry 2025-11-25 19:28:51 UTC
Created attachment 189949 [details] [review]
Bug 34069: Add unit tests

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 58 Andrew Fuerste-Henry 2025-11-25 19:28:54 UTC
Created attachment 189950 [details] [review]
Bug 34069: Fix categorycode/branch info, open in new tab, and other fixes

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 59 Andrew Fuerste-Henry 2025-11-25 19:28:57 UTC
Created attachment 189951 [details] [review]
Bug 34069: Adjust before and after date search

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 60 Andrew Fuerste-Henry 2025-11-25 19:29:00 UTC
Created attachment 189952 [details] [review]
Bug 34069: Prevent search if no search critrea

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 61 Andrew Fuerste-Henry 2025-11-25 19:29:03 UTC
Created attachment 189953 [details] [review]
Bug 34069: Allow for multiselection of branch and category

Signed-off-by: Katie Bliss <kebliss@dmpl.org>
Comment 62 Andrew Fuerste-Henry 2025-11-25 19:29:06 UTC
Created attachment 189954 [details] [review]
Bug 34069: Logaction should not be in all caps

Signed-off-by: Katie Bliss <kebliss@dmpl.org>