Bugzilla – Attachment 130257 Details for
Bug 29525
Privacy settings for patrons should also affect holds history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29525: Make Koha::Hold->cancel anonymize if required
Bug-29525-Make-KohaHold-cancel-anonymize-if-requir.patch (text/plain), 4.63 KB, created by
Martin Renvoize (ashimema)
on 2022-02-08 08:11:58 UTC
(
hide
)
Description:
Bug 29525: Make Koha::Hold->cancel anonymize if required
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-02-08 08:11:58 UTC
Size:
4.63 KB
patch
obsolete
>From 93c94504570febf0b0edc0cc1fcc40884422d2bf Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 12 Jan 2022 16:32:24 -0300 >Subject: [PATCH] Bug 29525: Make Koha::Hold->cancel anonymize if required > >This patch makes cancelling a hold anonymize it on the same call, if >settings require it (i.e. if borrowers.privacy is set to 2). > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Hold.t >=> SUCCESS: The code actually does what it is meant to >3. Try on the UI, cancelling a hold, noticing it gets anonymized if the > patron has privacy == always/2. >4. Sign off :-D > >Note: AnonymousPatron should be set. Otherwise it would set NULL. But >that's fine, that's what Koha does already. > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Hold.pm | 8 ++++- > t/db_dependent/Koha/Hold.t | 72 ++++++++++++++++++++++++++++++++++++++ > 2 files changed, 79 insertions(+), 1 deletion(-) > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 46605213b7..405dd0978f 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -517,6 +517,8 @@ sub cancel { > my ( $self, $params ) = @_; > $self->_result->result_source->schema->txn_do( > sub { >+ my $patron = $self->patron; >+ > $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) ); > $self->priority(0); > $self->cancellation_reason( $params->{cancellation_reason} ); >@@ -550,7 +552,11 @@ sub cancel { > } > } > >- $self->_move_to_old; >+ my $old_me = $self->_move_to_old; >+ # anonymize if required >+ $old_me->anonymize >+ if $patron->privacy == 2; >+ > $self->SUPER::delete(); # Do not add a DELETE log > > # now fix the priority on the others.... >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 636c32715a..51626272b6 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -24,12 +24,14 @@ use Test::More tests => 5; > use Test::Exception; > use Test::MockModule; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > use t::lib::Mocks; > > use Koha::ActionLogs; > use Koha::Holds; > use Koha::Libraries; >+use Koha::Old::Holds; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -382,3 +384,73 @@ subtest 'is_pickup_location_valid() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'cancel() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ # reduce the tests noise >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', >+ undef ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ >+ # 0 == keep forever >+ $patron->privacy(0)->store; >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { borrowernumber => $patron->id, status => undef } >+ } >+ ); >+ $hold->cancel(); >+ is( Koha::Old::Holds->find( $hold->id )->borrowernumber, >+ $patron->borrowernumber, 'Patron link is kept' ); >+ >+ # 1 == "default", meaning it is not protected from removal >+ $patron->privacy(1)->store; >+ $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { borrowernumber => $patron->id, status => undef } >+ } >+ ); >+ $hold->cancel(); >+ is( Koha::Old::Holds->find( $hold->id )->borrowernumber, >+ $patron->borrowernumber, 'Patron link is kept' ); >+ >+ # 2 == delete immediately >+ $patron->privacy(2)->store; >+ $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { borrowernumber => $patron->id, status => undef } >+ } >+ ); >+ $hold->cancel(); >+ is( Koha::Old::Holds->find( $hold->id )->borrowernumber, >+ undef, 'Patron link is deleted immediately' ); >+ >+ my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ >+ $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { borrowernumber => $patron->id, status => undef } >+ } >+ ); >+ $hold->cancel(); >+ is( >+ Koha::Old::Holds->find( $hold->id )->borrowernumber, >+ $anonymous_patron->id, >+ 'Patron link is set to the configured anonymous patron immediately' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29525
:
128975
|
128976
|
128977
|
129258
|
129259
|
129260
|
129265
|
129266
|
129267
|
129268
|
129273
|
129321
|
129322
|
129323
|
129363
|
129364
|
129424
|
129425
|
129426
|
129427
|
129428
|
129432
|
129433
|
129434
|
129435
|
129436
|
129544
|
129545
|
130254
|
130255
|
130256
| 130257 |
130258