Bugzilla – Attachment 148197 Details for
Bug 33229
Patron reading history should be cleared when privacy set to never
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33229: Clear patron reading history when privacy is set to never
Bug-33229-Clear-patron-reading-history-when-privac.patch (text/plain), 4.54 KB, created by
ByWater Sandboxes
on 2023-03-15 09:34:27 UTC
(
hide
)
Description:
Bug 33229: Clear patron reading history when privacy is set to never
Filename:
MIME Type:
Creator:
ByWater Sandboxes
Created:
2023-03-15 09:34:27 UTC
Size:
4.54 KB
patch
obsolete
>From a594d1ab67cfe414663bca72edd852f6d9b9c623 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 14 Mar 2023 20:02:10 +0000 >Subject: [PATCH] Bug 33229: Clear patron reading history when privacy is set > to never > >This patch adds a check to patron store routine. When privacy is changed >to 'Never' we should immediately clear their history > >To test: >1 - Set system preferences: > AnonymousPatron - to a valid borrowernumber > OPACPrivacy - Allow >2 - Checkout some items to a patron with priacy set to default, return them >3 - Log in to opac as patron >4 - Confirm you can see your history >5 - Change history to Never >6 - Confirm history still viewable >7 - Apply patch, restart all >8 - Set privacy to Default >9 - Confirm you can still see history, not deleted when not set as Never >10 - Set privacy to 'Never' >11 - Confirm history is anonymized > >Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk> >--- > Koha/Exceptions/Patron.pm | 4 ++++ > Koha/Patron.pm | 16 ++++++++++++++++ > t/db_dependent/Koha/Patron.t | 34 +++++++++++++++++++++++++++++++++- > 3 files changed, 53 insertions(+), 1 deletion(-) > >diff --git a/Koha/Exceptions/Patron.pm b/Koha/Exceptions/Patron.pm >index 596f28c94c..52fb6c69b6 100644 >--- a/Koha/Exceptions/Patron.pm >+++ b/Koha/Exceptions/Patron.pm >@@ -15,6 +15,10 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Patron', > description => "Deleting patron failed" > }, >+ 'Koha::Exceptions::Patron::FailedAnonymizing' => { >+ isa => 'Koha::Exceptions::Patron', >+ description => "Anonymizing patron reading history failed" >+ }, > 'Koha::Exceptions::Patron::FailedDeleteAnonymousPatron' => { > isa => 'Koha::Exceptions::Patron', > description => "Deleting patron failed, AnonymousPatron is not deleteable" >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 9282b38307..561b2a50ca 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -298,6 +298,22 @@ sub store { > $self->userid($stored_userid); > } > >+ # If a borrower has set their privacy to never we should immediately anonymize >+ # their checkouts >+ if( $self->privacy() == 2 && $self_from_storage->privacy() != 2 ){ >+ try{ >+ my $schema = Koha::Database->new()->schema(); >+ $schema->txn_do( >+ sub { $self->old_checkouts->anonymize; } >+ ); >+ } >+ catch { >+ Koha::Exceptions::Patron::FailedAnonymizing->throw( >+ error => @_ >+ ); >+ }; >+ } >+ > # Password must be updated using $self->set_password > $self->password($self_from_storage->password); > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index eee0ec9527..6007589ae9 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 20; >+use Test::More tests => 21; > use Test::Exception; > use Test::Warn; > >@@ -1398,3 +1398,35 @@ subtest 'get_savings tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'update privacy tests' => sub { >+ >+ plan tests => 5; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { privacy => 1 } }); >+ >+ my $old_checkout = $builder->build_object({ class => 'Koha::Old::Checkouts', value => { borrowernumber => $patron->id } }); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', '0' ); >+ >+ $patron->privacy(2); #set to never >+ >+ throws_ok{ $patron->store } 'Koha::Exceptions::Patron::FailedAnonymizing', 'We throw an exception when anonymizing fails'; >+ >+ $old_checkout->discard_changes; #refresh from db >+ $patron->discard_changes; >+ >+ is( $old_checkout->borrowernumber, $patron->id, "When anonymizing fails, we don't clear the checkouts"); >+ is( $patron->privacy(), 1, "When anonymizing fails, we don't chaneg the privacy"); >+ >+ my $anon_patron = $builder->build_object({ class => 'Koha::Patrons'}); >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anon_patron->id ); >+ >+ $patron->privacy(2)->store(); #set to never >+ >+ $old_checkout->discard_changes; #refresh from db >+ $patron->discard_changes; >+ >+ is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized"); >+ is( $patron->privacy(), 2, "Patron privacy is successfully updated"); >+}; >-- >2.30.2
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 33229
:
148186
|
148197
|
148546
|
148547
|
149753