From 08b04fa69dbaa4f3215cff6e066fc298ec9fa5e1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 29 Oct 2018 14:15:50 +0100 Subject: [PATCH] Bug 21712: Report anonymized patron records Content-Type: text/plain; charset=utf-8 The solution is rather limited but effective on itself. It only needs an enabled pref BorrowersLog. We log a specific ANONYMIZE action in Koha::Patron::anonymize. Now we only need to add a SQL report like: select object AS borrowernumber, timestamp AS date_anonymized from action_logs where module='MEMBERS' and action='ANONYMIZE' Depending on your needs, you could give this report a date parameter to show all actions from a given date onwards. Test plan: [1] Add a patron. [2] Enable BorrowersLog [3] Run in perl this line: use Koha::Patrons; Koha::Patrons->find(BORROWERNUMBER)->anonymize; Or (much more work): enable GDPR, unsubscribe, set reflection delay to zero and anonymize delay to zero and run cleanup_database.pl. [4] Check if the log contains a ANONYMIZE action for this patron. Signed-off-by: Marcel de Rooy --- Koha/Patron.pm | 2 ++ t/db_dependent/Koha/Patrons.t | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 6dce539..7c63a4a 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1205,6 +1205,8 @@ sub anonymize { } } $self->flgAnonymized(1)->store; + logaction( "MEMBERS", "ANONYMIZE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); + } sub _anonymize_column { diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 40962b6..7c30f7f 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1582,7 +1582,7 @@ subtest 'lock' => sub { }; subtest 'anonymize' => sub { - plan tests => 9; + plan tests => 10; my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } ); my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -1593,10 +1593,12 @@ subtest 'anonymize' => sub { $issue->delete; t::lib::Mocks::mock_preference( 'BorrowerMandatoryField', 'surname|email|cardnumber' ); + t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); my $surname = $patron1->surname; # expect change, no clear my $branchcode = $patron1->branchcode; # expect skip $patron1->anonymize; is($patron1->flgAnonymized, 1, 'Check flag' ); + is( $schema->resultset('ActionLog')->search({ object => $patron1->borrowernumber, module => 'MEMBERS', action => 'ANONYMIZE' })->count, 1, 'Action has been logged too' ); is( $patron1->dateofbirth, undef, 'Birth date cleared' ); is( $patron1->firstname, undef, 'First name cleared' ); -- 2.1.4