Bugzilla – Attachment 101044 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: Sync patron's attributes
Bug-24151-Sync-patrons-attributes.patch (text/plain), 5.55 KB, created by
Jonathan Druart
on 2020-03-19 16:24:37 UTC
(
hide
)
Description:
Bug 24151: Sync patron's attributes
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-19 16:24:37 UTC
Size:
5.55 KB
patch
obsolete
>From ae19e8086b5e86279faad85b7505dda9ec221edb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Sat, 11 Jan 2020 16:43:40 +0100 >Subject: [PATCH] Bug 24151: Sync patron's attributes > >Signed-off-by: Signed-off-by: Sonia Bouis <sonia.bouis@univ-lyon3.fr> >--- > Koha/PseudonymizedTransaction.pm | 15 +++- > t/db_dependent/Koha/Pseudonymization.t | 99 +++++++++++++++++++++++++- > 2 files changed, 111 insertions(+), 3 deletions(-) > >diff --git a/Koha/PseudonymizedTransaction.pm b/Koha/PseudonymizedTransaction.pm >index 04aab176df..c5b0e8836f 100644 >--- a/Koha/PseudonymizedTransaction.pm >+++ b/Koha/PseudonymizedTransaction.pm >@@ -79,7 +79,20 @@ sub new_from_statistic { > > $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; > >- return $class->SUPER::new($values); >+ my $self = $class->SUPER::new($values); >+ >+ my $extended_attributes = $patron->extended_attributes->unblessed; >+ for my $attribute (@$extended_attributes) { >+ next unless Koha::Patron::Attribute::Types->find( >+ $attribute->{code} )->keep_for_pseudonymization; >+ >+ delete $attribute->{id}; >+ delete $attribute->{borrowernumber}; >+ >+ $self->_result->create_related('pseudonymized_borrower_attributes', $attribute); >+ } >+ >+ return $self; > } > > sub get_hash { >diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t >index 6c8031224b..4e29dcbd47 100644 >--- a/t/db_dependent/Koha/Pseudonymization.t >+++ b/t/db_dependent/Koha/Pseudonymization.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Try::Tiny; > > use C4::Circulation; >@@ -54,11 +54,12 @@ subtest 'Config does not exist' => sub { > C4::Stats::UpdateStats( > { > type => 'issue', >- branch => 'BBB', >+ branch => $library->branchcode, > itemnumber => $item->itemnumber, > borrowernumber => $patron->borrowernumber, > itemtype => $item->effective_itemtype, > location => $item->location, >+ ccode => $item->ccode, > } > ); > >@@ -113,3 +114,97 @@ subtest 'Koha::Anonymized::Transactions tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'PseudonymizedBorrowerAttributes tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_config( 'key', '$2a$08$9lmorEKnwQloheaCLFIfje' ); >+ t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >+ t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', >+ 'branchcode,categorycode,sort1' ); >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron_info = $patron->unblessed; >+ delete $patron_info->{borrowernumber}; >+ $patron->delete; >+ >+ my $attribute_type1 = Koha::Patron::Attribute::Type->new( >+ { >+ code => 'my code1', >+ description => 'my description1', >+ repeatable => 1, >+ keep_for_pseudonymization => 1, >+ } >+ )->store; >+ my $attribute_type2 = Koha::Patron::Attribute::Type->new( >+ { >+ code => 'my code2', >+ description => 'my description2', >+ keep_for_pseudonymization => 0, >+ } >+ )->store; >+ my $attribute_type3 = Koha::Patron::Attribute::Type->new( >+ { >+ code => 'my code3', >+ description => 'my description3', >+ keep_for_pseudonymization => 1, >+ } >+ )->store; >+ >+ $patron = Koha::Patron->new($patron_info)->store->get_from_storage; >+ my $attribute_values = [ >+ { >+ attribute => 'attribute for code1', >+ code => $attribute_type1->code, >+ }, >+ { >+ attribute => 'attribute for code2', >+ code => $attribute_type2->code >+ }, >+ { >+ attribute => 'attribute for code3', >+ code => $attribute_type3->code >+ }, >+ ]; >+ >+ $patron->extended_attributes($attribute_values); >+ >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $item = $builder->build_sample_item; >+ >+ C4::Stats::UpdateStats( >+ { >+ type => 'issue', >+ branch => $library->branchcode, >+ itemnumber => $item->itemnumber, >+ borrowernumber => $patron->borrowernumber, >+ itemtype => $item->effective_itemtype, >+ location => $item->location, >+ ccode => $item->ccode, >+ } >+ ); >+ >+ my $p = Koha::PseudonymizedTransactions->search({itemnumber => $item->itemnumber})->next; >+ my $attributes = Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute')->search({transaction_id => $p->id }); >+ is( $attributes->count, 2, >+ 'Only the 2 attributes that have a type with keep_for_pseudonymization set should be kept' >+ ); >+ my $attribute_1 = $attributes->next; >+ is_deeply( >+ { attribute => $attribute_1->attribute, code => $attribute_1->code->code }, >+ $attribute_values->[0], >+ 'Attribute 1 should be retrieved correctly' >+ ); >+ my $attribute_2 = $attributes->next; >+ is_deeply( >+ { attribute => $attribute_2->attribute, code => $attribute_2->code->code }, >+ $attribute_values->[2], >+ 'Attribute 2 should be retrieved correctly' >+ ); >+ >+ $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 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