Bugzilla – Attachment 130254 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: Add Koha::Old::Holds->filter_by_anonymizable
Bug-29525-Add-KohaOldHolds-filterbyanonymizable.patch (text/plain), 5.78 KB, created by
Martin Renvoize (ashimema)
on 2022-02-08 08:11:44 UTC
(
hide
)
Description:
Bug 29525: Add Koha::Old::Holds->filter_by_anonymizable
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-02-08 08:11:44 UTC
Size:
5.78 KB
patch
obsolete
>From 9c5b1ab3c5fab83f9f6928d74c535beff8a969b2 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 3 Jan 2022 15:06:23 -0300 >Subject: [PATCH] Bug 29525: Add Koha::Old::Holds->filter_by_anonymizable > >This patch adds the 'filter_by_anonymizable' method, and tests for it. A >new DBIC relationship is added as well to the OldReserve schema file. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ t/db_dependent/Koha/Old/Holds.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Old/Holds.pm | 33 ++++++++++++- > Koha/Schema/Result/OldReserve.pm | 12 +++++ > t/db_dependent/Koha/Old/Holds.t | 80 +++++++++++++++++++++++++++++++- > 3 files changed, 123 insertions(+), 2 deletions(-) > >diff --git a/Koha/Old/Holds.pm b/Koha/Old/Holds.pm >index 40bf2dcdf2..1a7cb0d5a7 100644 >--- a/Koha/Old/Holds.pm >+++ b/Koha/Old/Holds.pm >@@ -19,7 +19,6 @@ package Koha::Old::Holds; > > use Modern::Perl; > >- > use Koha::Database; > > use Koha::Old::Hold; >@@ -36,6 +35,38 @@ This object represents a set of holds that have been filled or canceled > > =head2 Class methods > >+=head3 filter_by_anonymizable >+ >+ my $holds = $patron->old_holds; >+ my $anonymizable_holds = $holds->filter_by_anonymizable; >+ >+This method filters a I<Koha::Old::Holds> resultset, so it only contains holds that can be >+anonymized given the patron privacy settings. >+ >+=cut >+ >+sub filter_by_anonymizable { >+ my ( $self, $params ) = @_; >+ >+ my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; >+ >+ return $self->search( >+ { >+ 'me.borrowernumber' => { 'not' => undef }, >+ 'patron.privacy' => { '<>' => 0 }, >+ ( >+ $anonymous_patron >+ ? ( 'me.borrowernumber' => { '!=' => $anonymous_patron } ) >+ : () >+ ), >+ }, >+ { >+ join => ['patron'], >+ order_by => ['me.reserve_id'], >+ } >+ ); >+} >+ > =head3 anonymize > > $patron->old_holds->anonymize(); >diff --git a/Koha/Schema/Result/OldReserve.pm b/Koha/Schema/Result/OldReserve.pm >index 484760e6e5..96c7373c16 100644 >--- a/Koha/Schema/Result/OldReserve.pm >+++ b/Koha/Schema/Result/OldReserve.pm >@@ -404,6 +404,18 @@ __PACKAGE__->belongs_to( > }, > ); > >+__PACKAGE__->belongs_to( >+ "patron", >+ "Koha::Schema::Result::Borrower", >+ { borrowernumber => "borrowernumber" }, >+ { >+ is_deferrable => 1, >+ join_type => "LEFT", >+ on_delete => "SET NULL", >+ on_update => "SET NULL", >+ }, >+); >+ > __PACKAGE__->add_columns( > '+item_level_hold' => { is_boolean => 1 }, > '+lowestPriority' => { is_boolean => 1 }, >diff --git a/t/db_dependent/Koha/Old/Holds.t b/t/db_dependent/Koha/Old/Holds.t >index fc1f5592cd..befaefe7d1 100755 >--- a/t/db_dependent/Koha/Old/Holds.t >+++ b/t/db_dependent/Koha/Old/Holds.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; > > use Koha::Database; > use Koha::DateUtils qw(dt_from_string); >@@ -85,3 +85,81 @@ subtest 'anonymize() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'filter_by_anonymizable() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ # patron_1 => keep records forever >+ my $patron_1 = $builder->build_object( >+ { class => 'Koha::Patrons', value => { privacy => 0 } } ); >+ >+ # patron_2 => never keep records >+ my $patron_2 = $builder->build_object( >+ { class => 'Koha::Patrons', value => { privacy => 1 } } ); >+ >+ is( $patron_1->old_holds->count, 0, 'patron_1 has no old holds' ); >+ is( $patron_2->old_holds->count, 0, 'patron_2 has no old holds' ); >+ >+ my $hold_1 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_1->id, >+ } >+ } >+ )->_move_to_old; >+ my $hold_2 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_2->id, >+ } >+ } >+ )->_move_to_old; >+ my $hold_3 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_1->id, >+ } >+ } >+ )->_move_to_old; >+ my $hold_4 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_2->id, >+ } >+ } >+ )->_move_to_old; >+ >+ $hold_1 = Koha::Old::Holds->find( $hold_1->id ) >+ ->set( { timestamp => dt_from_string() } )->store; >+ $hold_2 = Koha::Old::Holds->find( $hold_2->id ) >+ ->set( { timestamp => dt_from_string()->subtract( days => 1 ) } )->store; >+ $hold_3 = Koha::Old::Holds->find( $hold_3->id ) >+ ->set( { timestamp => dt_from_string()->subtract( days => 2 ) } )->store; >+ $hold_4 = Koha::Old::Holds->find( $hold_4->id ) >+ ->set( { timestamp => dt_from_string()->subtract( days => 3 ) } )->store; >+ >+ is( $patron_1->old_holds->count, 2, 'patron_1 has 2 completed holds' ); >+ is( $patron_2->old_holds->count, 2, 'patron_2 has 2 completed holds' ); >+ >+ # filter them so only the older two are part of the resultset >+ my $holds = Koha::Old::Holds->search( >+ { 'me.borrowernumber' => [ $patron_1->id, $patron_2->id ] } ); >+ is( $holds->count, 4, 'Total of 4 holds returned correctly' ); >+ my $rs = $holds->filter_by_anonymizable; >+ is( $rs->count, 2, 'Only 2 can be anonymized' ); >+ >+ $rs = $holds >+ ->filter_by_anonymizable >+ ->filter_by_last_update( { days => 1 } ); >+ >+ is( $rs->count, 1, 'Only 1 can be anonymized with date filter applied' ); >+ >+ $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