Bugzilla – Attachment 95969 Details for
Bug 24151
Add a pseudonymization process for patrons and transactions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24151: Handle case where the setting is turned on later
Bug-24151-Handle-case-where-the-setting-is-turned-.patch (text/plain), 4.22 KB, created by
Jonathan Druart
on 2019-12-03 18:11:40 UTC
(
hide
)
Description:
Bug 24151: Handle case where the setting is turned on later
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-12-03 18:11:40 UTC
Size:
4.22 KB
patch
obsolete
>From af5c7fa501be6117ca47ab295db2462d19711806 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 26 Nov 2019 21:14:52 +0100 >Subject: [PATCH] Bug 24151: Handle case where the setting is turned on later > >Sponsored-by: Association KohaLa - https://koha-fr.org/ >--- > Koha/Anonymized/Transaction.pm | 6 ++++++ > Koha/Patron.pm | 14 ++++++++++---- > t/db_dependent/Koha/Pseudonymization.t | 27 ++++++++++++++++++++++++++- > 3 files changed, 42 insertions(+), 5 deletions(-) > >diff --git a/Koha/Anonymized/Transaction.pm b/Koha/Anonymized/Transaction.pm >index e57712c936..fcc5f06149 100644 >--- a/Koha/Anonymized/Transaction.pm >+++ b/Koha/Anonymized/Transaction.pm >@@ -42,6 +42,12 @@ sub new_from_statistic { > hashed_borrowernumber => Koha::Anonymized->get_hash($statistic->borrowernumber), > }; > >+ # In case the patron does not exist yet in the anonymized_borrowers table >+ unless ( Koha::Anonymized::Patrons->find($values->{hashed_borrowernumber}) ) { >+ my $patron = Koha::Patrons->find($statistic->borrowernumber); >+ Koha::Anonymized::Patron->new_from_patron($patron)->store; >+ } >+ > my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; > > if ( grep { $_ eq 'branchcode' } @fields_to_copy ) { >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 5894dedaac..834b6e120d 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -343,11 +343,17 @@ sub store { > } > > if ( C4::Context->preference('Pseudonymization') ) { >- unless ( $in_storage ) { >- Koha::Anonymized::Patron->new_from_patron($self)->store; >- } else { >- Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber)->update_from_patron($self)->store; >+ my $anonymized; >+ if ( $in_storage ) { >+ $anonymized = Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber); >+ $anonymized->update_from_patron($self)->store if $anonymized; > } >+ >+ # If not set at this point, either it's a new patron >+ # or the setting has been turned on after the patron has been created >+ $anonymized = Koha::Anonymized::Patron->new_from_patron($self) unless $anonymized; >+ >+ $anonymized->store; > } > > } >diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t >index b5297f3dc5..37e6de8f2d 100644 >--- a/t/db_dependent/Koha/Pseudonymization.t >+++ b/t/db_dependent/Koha/Pseudonymization.t >@@ -63,7 +63,7 @@ subtest 'Config does not exist' => sub { > > subtest 'Koha::Anonymized::Patrons tests' => sub { > >- plan tests => 9; >+ plan tests => 10; > > $schema->storage->txn_begin; > >@@ -98,6 +98,31 @@ subtest 'Koha::Anonymized::Patrons tests' => sub { > is( $patron->sort1, "another sort1", "correctly updated" ); > $patron->delete; > >+ subtest 'Patron was created before the Pseudonymization was actived' => sub { >+ >+ plan tests => 2; >+ >+ t::lib::Mocks::mock_preference( 'Pseudonymization', 0 ); >+ my $patron = Koha::Patron->new($patron_info)->store; >+ $patron->discard_changes; >+ >+ t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >+ $patron->sort1("another sort1")->store; >+ $anonymized = Koha::Anonymized::Patrons->find_from_borrowernumber( $patron->borrowernumber ); >+ is( $anonymized->sort1, "another sort1", "correctly updated" ); >+ $anonymized->delete; >+ >+ my $item = $builder->build_sample_item; >+ t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); >+ AddIssue( $patron->unblessed, $item->barcode, dt_from_string ); >+ AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); >+ $anonymized = Koha::Anonymized::Transactions->search( { itemnumber => $item->itemnumber } )->next; >+ like( $anonymized->hashed_borrowernumber, >+ qr{^\$2a\$08\$}, "The hashed_borrowernumber has been created (and so the corresponding anonymized_borrowers entry)" ); >+ >+ $patron->delete; >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >2.11.0
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 24151
:
95959
|
95960
|
95961
|
95962
|
95963
|
95964
|
95965
|
95966
|
95967
|
95968
|
95969
|
95970
|
95971
|
95972
|
95973
|
95974
|
95975
|
95976
|
97240
|
97241
|
97242
|
97243
|
97244
|
97245
|
97246
|
97247
|
97248
|
97249
|
97250
|
97251
|
97252
|
101034
|
101035
|
101036
|
101037
|
101038
|
101039
|
101040
|
101041
|
101042
|
101043
|
101044
|
101045
|
101046
|
101047
|
101048
|
101049
|
105801
|
105802
|
105803
|
105804
|
105805
|
105806
|
105807
|
105808
|
105809
|
105810
|
105811
|
105812
|
105813
|
105814
|
105815
|
105816
|
106032
|
106033
|
106034
|
106035
|
106036
|
106037
|
106038
|
106039
|
106040
|
106041
|
106042
|
106043
|
106044
|
106045
|
106046
|
106047
|
106048
|
106049
|
106195
|
106255
|
107127
|
107225