Koha/t
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
Biblio
Budgets
Circulation
cypress Bug 34587: Updated cypress tests 2023-10-31 16:46:32 -03:00
data Bug 31393: Koha::Config: handle the special case for 'content' attribute 2023-10-30 09:02:17 -03:00
db_dependent Bug 26170: Add protected status for patrons 2023-11-01 17:23:06 -03:00
edi_testfiles
etc
External
Koha Bug 31393: Tidy 2023-10-30 09:02:18 -03:00
lib Bug 26170: Add protected status for patrons 2023-11-01 17:23:06 -03:00
Number
Search Bug 34969: Remove unneeded module from buildQuery.t 2023-10-04 09:15:42 -04:00
Serials
SIP
Template Bug 33030: Add unit tests 2023-07-14 16:52:06 -03:00
Test
00-check-atomic-updates.t Bug 31479: Option to skip t/00-check-atomic-updates.t when building custom packages 2023-05-10 15:26:20 -03:00
00-deprecated.t
00-load.t
00-merge-conflict-markers.t
00-testcritic.t Bug 34911: Test files from HEAD instead of 'master' 2023-10-04 09:15:35 -04:00
00-valid-xml.t
Auth.t
AuthoritiesMarc_MARC21.t Bug 31023: Unit tests 2022-09-07 13:52:35 -07:00
AuthoritiesMarc_UNIMARC.t
Barcodes_annual.t
Barcodes_EAN13.t
Barcodes_hbyymmincr.t
Barcodes_incremental.t
Biblio.t Bug 29697: Use flag embed_items 2022-07-22 15:24:11 -03:00
Biblio2.t
Budgets.t
Charset.t
Circulation_barcodedecode.t
ClassSortRoutine.t
ClassSortRoutine_Dewey.t
ClassSortRoutine_Generic.t
ClassSortRoutine_LCC.t
ClassSource.t
Context.t Bug 29033: Add C4::Context->multivalue_preference 2023-10-10 10:53:59 -03:00
Contract.t
CookieManager.t Bug 31250: (QA follow-up) The future will be easier 2022-09-12 15:34:11 -03:00
Creators.t
DateUtils.t
dummy.t
Edifact.t
EdiInvoice.t
Ediorder.t Bug 31134: Mock EdifactLSQ for t/Edifact.t 2022-07-18 10:20:44 -03:00
Ediordrsp.t
Form_MessagingPreferences.t
HtmlTags.t
ImportBatch.t
Installer_PerlModules.t
ItemCirculationAlertPreference.t
Koha_MetadataRecord.t Bug 30358: Strip leading/trailing whitespace characters from input fields when cataloguing 2023-05-16 15:17:26 -03:00
Koha_SearchEngine_Elasticsearch_Browse.t
Koha_Template_Plugin_Cache.t
Koha_Template_Plugin_HtmlId.t
Koha_Template_Plugin_Koha.t Bug 31401: (QA follow-up) Remove Koha.ArePluginsEnabled, it is no longer needed 2022-09-07 13:55:37 -07:00
Koha_Util_FrameworkPlugin.t
Koha_Util_MARC.t
Koha_XSLT_HTTPS.t Bug 12758: Introduce Koha::XSLT::HTTPS 2022-11-09 09:52:17 -03:00
Labels.t
Labels_split_ccn.t
Labels_split_ddcn.t
Labels_split_lccn.t
Labels_split_Regex.t
Languages.t
Logger.t Bug 32979: Skip test if running as root 2023-02-20 09:44:16 -03:00
Makefile.t Bug 31528: (QA follow-up) Exclude .stylelintrc.json in Makefile.t 2022-10-03 09:54:34 -03:00
Members_Messaging.t
OpenLibrarySearch.t
Output.t Bug 30524: Unit tests 2023-08-07 20:59:59 -03:00
Output_JSONStream.t
Patroncards.t
Patroncards_Batch.t
Patroncards_Lib.t
Patroncards_Patroncard.t
Patroncards_Profile.t
Patroncards_Template.t
RecordProcessor.t
Ris.t
Scheduler.t
Scrubber.t
Search.t Bug 34968: Remove unneeded module from Search.t 2023-10-04 09:32:46 -04:00
Search_PazPar2.t
SimpleMARC.t Bug 31644: (QA follow-up) Add two missing shebang lines 2022-10-24 11:53:19 -03:00
SMS.t
SuggestionEngine.t
SuggestionEngine_AuthorityFile.t Bug 34970: Remove most modules from SuggestionEngine_AuthorityFile.t 2023-10-04 09:15:41 -04:00
template_filters.t
timezones.t
TmplToken.t
Token.t Bug 34163: Handle both anonymous userenv when generating CSRF tokens 2023-09-12 09:45:01 -03:00