Koha-clms/Koha/Exceptions
Magnus Enger 6fec4ea0df
Bug 26170: Add protected status for patrons
This set of patches makes it possible to protect patrons from being accidetally
deleted or merged with other patrons, from the UI and from (well behaved) cron
jobs. The following subroutines are affected:
- Koha::Patron::delete
- Koha::Patron::merge_with
- Koha::Patron::safe_to_delete
- C4::Members::GetBorrowersToExpunge

Please note:
- This does not intend to protect patrons from being edited, only from being
  deleted

To test:

* Tests
- Run the affected tests:
  prove t/db_dependent/Members.t
  prove t/db_dependent/Koha/Patrons.t

* Editing protected status and manual deletion
- Add a new user, note the presence of the "Protected" field under "Library
  management", but leave it at the default "No", for now.
- Note that "Protected" is displayed in the "Library use" section of the patron
  details.
- Note that More > Delete is avaiable as an action when the patron is saved
- Edit the user and set "Protected" to "Yes"
- Note that More > Delete is now disabled, with a note that the patron is protected

* Batch patron deletion
- Go to Tools > Batch patron deletion and anonymization
- Check the box for "Verify you want to delete patrons"
- Choose the category of your protected patron for "whose patron category is"
  and click "Next" to run the actual deletion
- Check that your protected patron was not deleted

* Merging patrons
- Make sure you have two patrons with similar names or the same category, so
  you can find them with one search. One should be protected, one not.
- Search for the patrons, tick their boxes and click on "Merge selected patrons"
- Select one of the patrons as the "patron to keep".
. Click on "Merge patrons"
- "No valid patrons to merge were found" should be shown
- Repeat this with the other patron as the "patron to keep"
(A future enhancement could be to not allow a protected patron to be selected for
merging in the first place.)

* misc/cronjobs/delete_patrons.pl
- Make sure you have a protected patron, in a category with at least one more
  patron.
- Run something like this (at least in ktd):
  $ perl misc/cronjobs/delete_patrons.pl --category_code <code> -v --confirm
  (Replace <code> with the actual categorycode.)
- Make sure the borrowernumber of the protected patron is not mentioned in the
  output of the script.
- Check the protected patron was not deleted
- Check the non-protected patrons were deleted

* REST API (with ktd)
- Make sure you still have a protected patron, and note their borrowernumber
- Enable RESTBasicAuth and restart all the things
- Run these two commands from the command line on the host:
  $ curl -u koha:koha --request GET "http://localhost:8081/api/v1/patrons/54"
  $ curl -u koha:koha --request DELETE "http://localhost:8081/api/v1/patrons/54"
  (Replace 54 with the actual borrowernumber of your protected patron.)
- The first curl command should give you the patron details. The second should
  give this output:
  {"error":"Protected patrons cannot be deleted","error_code":"is_protected"}

There could be more functions/scripts where patrons are deleted that I have not
thought about. Please report them on the bug if you find any!

Update 2023-10-19: Fix "More > Delete" on patron, so link can not be clicked.
Update 2023-10-19: Rebase

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-11-01 17:23:06 -03:00
..
Acquisition Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Checkouts Bug 30275: (follow-up) Drop renewer_id constraint 2022-07-05 09:46:18 -03:00
ERM/EUsage Bug 34587: Move everything into a ERM/EUsage subfolder 2023-10-31 16:46:18 -03:00
Item Bug 33817: Enforce server-side 2023-07-10 15:43:09 -03:00
Patron Bug 17499: (follow-up) Rename to Koha::Patron::MessagePreference 2023-09-12 10:16:11 -03:00
Account.pm Bug 33176: Enforce bad values 2023-06-12 11:52:07 -03:00
ArticleRequest.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Auth.pm Bug 31378: Add Auth mojo plugin 2022-11-08 14:30:33 -03:00
Authentication.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Authorization.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
BackgroundJob.pm Bug 30360: Add helper methods to Koha::BackgroundJobs 2022-05-05 16:11:36 +01:00
Calendar.pm Bug 27249: Add missing POD for Koha::Exceptions::Calendar 2023-10-17 14:45:33 -03:00
Checkin.pm Bug 32121: Show an alert when adding a checked out item to an item bundle 2023-03-27 12:50:02 +02:00
Checkout.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
CirculationRule.pm Bug 33028: (follow-up) Add POD to new Exception 2023-07-19 12:06:49 -03:00
ClubHold.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Config.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
CurbsidePickup.pm Bug 30650: Prevent pickup to be created on holiday 2022-07-29 15:00:51 -03:00
Elasticsearch.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Hold.pm Bug 31692: Add Koha::Hold::change_type and unit tests 2023-10-10 09:58:57 -03:00
Ill.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Library.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
MarcOverlayRule.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Metadata.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Object.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Password.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Patron.pm Bug 26170: Add protected status for patrons 2023-11-01 17:23:06 -03:00
Plugin.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Preservation.pm Bug 30708: Tidy perl files 2023-10-18 15:42:04 -03:00
Suggestion.pm Bug 32942: (QA follow-up) Moving Suggestion->STATUS check to Suggestion::store 2023-09-18 15:31:45 -03:00
SysPref.pm Bug 30007: Add Koha::Exceptions::SysPref 2022-03-01 22:47:47 -10:00
Token.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
TransferLimit.pm Bug 29857: Rename base class as Koha::Exception 2022-03-01 22:47:47 -10:00
Virtualshelf.pm Bug 30057: Move virtualshelf-related exceptions to a separate library 2022-06-06 14:30:37 -03:00
XSLT.pm Bug 12758: (QA follow-up) Enhance POD 2022-11-09 09:58:56 -03:00