From 7f13f49ff9f2129a133470b3585d74a040df6650 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 3 Jan 2022 11:53:32 -0300 Subject: [PATCH] Bug 29526: Add a way for patrons to delete their hold history The same way we have a button to immediately delete the checkouts history in the OPAC, we should have a similar option for the holds history. This patch implements that. To test: 1. Have a patron with some old checkouts and old holds. 2. Have OPACPrivacy, OPACHoldsHistory and opacreadinghistory enabled. 3. Notice in the OPAC the patron has some old checkouts and holds. 4. Use the Privacy tab to clean checkouts => SUCCESS: They are still cleaned as before this patch 5. Try to clean the old holds => SUCCESS: They are cleaned! 6. Add some old checkouts and holds 7. Use the new 'All' button => SUCCESS: All cleaned 8. Sign off :-D Signed-off-by: Barbara Johnson Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- .../bootstrap/en/modules/opac-privacy.tt | 52 +++++++++++--- opac/opac-privacy.pl | 71 ++++++++++++------- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt index edeffaac19..adede9145a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt @@ -37,12 +37,26 @@

Your privacy management

- [% IF deleted %] -
Your checkout history has been deleted.
- [% ELSIF history_not_deleted %] -
The deletion of your checkout history failed, because there is a problem with the configuration of this feature. Please help to fix the system by informing your library of this error
- [% ELSIF nothing_to_delete %] -
No checkout history to delete
+ [% IF delete_all_requested || delete_checkouts_requested || delete_holds_requested %] + [% IF delete_all_requested || delete_checkouts_requested %] + [% IF deleted_checkouts %] +
Your checkout history has been deleted.
+ [% ELSIF error_deleting_checkouts_history %] +
The deletion of your checkout history failed, because there is a problem with the configuration of this feature. Please help to fix the system by informing your library of this error
+ [% ELSIF no_checkouts_to_delete %] +
No checkout history to delete
+ [% END %] + [% END %] + + [% IF delete_all_requested || delete_holds_requested %] + [% IF deleted_holds %] +
Your hold history has been deleted.
+ [% ELSIF error_deleting_holds_history %] +
The deletion of your hold history failed. Please help to fix the system by informing your library of this error
+ [% ELSIF no_holds_to_delete %] +
No hold history to delete
+ [% END %] + [% END %] [% END %] [% IF ( privacy_updated ) %] @@ -140,12 +154,32 @@

Immediate deletion

+

Whatever your privacy rule you choose, you can delete all your checkout and hold history immediately by clicking here. BE CAREFUL. Once you've confirmed the deletion, no one can retrieve the list!

+ +
+ Checkout history deletion + + +
+ +
+
+ +
+ Hold history deletion + + +
+ +
+
+
- Immediate deletion + Checkout and hold history deletion -

Whatever your privacy rule you choose, you can delete all your checkout history immediately by clicking here. BE CAREFUL. Once you've confirmed the deletion, no one can retrieve the list!

+
- +
diff --git a/opac/opac-privacy.pl b/opac/opac-privacy.pl index 8ea6b12066..2c96b7ffa9 100755 --- a/opac/opac-privacy.pl +++ b/opac/opac-privacy.pl @@ -32,8 +32,6 @@ if ( ! C4::Context->preference('OPACPrivacy') || ! C4::Context->preference('opac exit; } -my $dbh = C4::Context->dbh; - my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-privacy.tt", @@ -42,13 +40,14 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); +my $patron = Koha::Patrons->find( $borrowernumber ); + my $op = $query->param("op"); my $privacy = $query->param("privacy"); my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts"); my $privacy_guarantor_fines = $query->param("privacy_guarantor_fines"); if ( $op eq "update_privacy" ) { - my $patron = Koha::Patrons->find( $borrowernumber ); if ( $patron ) { $patron->set({ privacy => $privacy, @@ -60,30 +59,54 @@ if ( $op eq "update_privacy" ) { } elsif ( $op eq "delete_record" ) { - # delete all reading records for items returned - my $rows = eval { - Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history; - }; - $template->param( - ( - $@ ? ( history_not_deleted => 1 ) - : $rows ? ( deleted => int($rows) ) - : ( nothing_to_delete => 1 ) - ) - ); -} + my $holds = $query->param('holds'); + my $checkouts = $query->param('checkouts'); + my $all = $query->param('all'); + + $template->param( delete_all_quested => 1 ) + if $all; + + if ( $all or $checkouts ) { + + # delete all reading records for items returned + my $rows = eval { + Koha::Patrons->search( { 'me.borrowernumber' => $borrowernumber } ) + ->anonymise_issue_history; + }; -# get borrower privacy .... -my $borrower = Koha::Patrons->find( $borrowernumber );; + $template->param( + ( + $@ ? ( error_deleting_checkouts_history => 1 ) + : $rows ? ( deleted_checkouts => int($rows) ) + : ( no_checkouts_to_delete => 1 ) + ), + delete_checkouts_requested => 1, + ); + } + + if ( $all or $holds ) { + + my $rows = eval { $patron->old_holds->anonymize + 0 }; + + $template->param( + ( + $@ ? ( error_deleting_holds_history => 1 ) + : $rows ? ( deleted_holds => int($rows) ) + : ( no_holds_to_delete => 1 ) + ), + delete_holds_requested => 1, + ); + } +} $template->param( - 'Ask_data' => 1, - 'privacy' . $borrower->privacy() => 1, - 'privacyview' => 1, - 'borrower' => $borrower, - 'surname' => $borrower->surname, - 'firstname' => $borrower->firstname, - 'has_guarantor_flag' => $borrower->guarantor_relationships->guarantors->_resultset->count + 'Ask_data' => 1, + 'privacy' . $patron->privacy() => 1, + 'privacyview' => 1, + 'borrower' => $patron, + 'surname' => $patron->surname, + 'firstname' => $patron->firstname, + 'has_guarantor_flag' => $patron->guarantor_relationships->guarantors->_resultset->count ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5