Bugzilla – Attachment 95463 Details for
Bug 18795
REST API: DELETE (anonymize) checkout history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18795: DELETE (anonymize) checkout history
Bug-18795-DELETE-anonymize-checkout-history.patch (text/plain), 4.35 KB, created by
Bouzid Fergani
on 2019-11-15 20:34:31 UTC
(
hide
)
Description:
Bug 18795: DELETE (anonymize) checkout history
Filename:
MIME Type:
Creator:
Bouzid Fergani
Created:
2019-11-15 20:34:31 UTC
Size:
4.35 KB
patch
obsolete
>From 6e74e3dcc8629e0cd7e8b6289a17d6005f6147b8 Mon Sep 17 00:00:00 2001 >From: Johanna Raisa <johanna.raisa@gmail.com> >Date: Tue, 22 Oct 2019 14:41:38 +0300 >Subject: [PATCH] Bug 18795: DELETE (anonymize) checkout history >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Anonymize patron's checkout history via REST API > >DELETE /checkouts/history?patron_id=123 > >To test: >1. prove t/db_dependent/api/v1/checkouts.t >2. Manually send DELETE request to /api/v1/checkouts/history?patron_id=123 where 123 is your patron's borrowernumber > >Sponsored-by: Koha-Suomi Oy >Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> >Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com> >--- > Koha/REST/V1/Checkouts.pm | 26 ++++++++++++++++++++++++++ > api/v1/swagger/paths.json | 3 +++ > api/v1/swagger/paths/checkouts.json | 28 ++++++++++++++++++++++++++++ > t/db_dependent/api/v1/checkouts.t | 19 ++++++++++++++++++- > 4 files changed, 75 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index c8ded14..26d1da0 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -182,6 +182,32 @@ sub allows_renewal { > ); > } > >+=head3 delete_history >+ >+Anonymize patron's checkout history. >+ >+=cut >+ >+sub delete_history { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $patron_id = $c->validation->param('patron_id'); >+ >+ my $patrons = Koha::Patrons->search({ >+ 'me.borrowernumber' => $patron_id >+ }); >+ >+ $patrons->anonymise_issue_history; >+ >+ unless ($patrons->count) { >+ return $c->render( status => 404, openapi => { >+ error => "Patron doesn't exist" >+ }); >+ } >+ >+ return $c->render( status => 204, openapi => "" ); >+} >+ > =head3 _to_api > > Helper function that maps a hashref of Koha::Checkout attributes into REST api >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index 95278ec..803e3b5 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -20,6 +20,9 @@ > "/checkouts/{checkout_id}/renewal": { > "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal" > }, >+ "/checkouts/history": { >+ "$ref": "paths/checkouts.json#/~1checkouts~1history" >+ }, > "/cities": { > "$ref": "paths/cities.json#/~1cities" > }, >diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json >index ca6d970..9634e0c 100644 >--- a/api/v1/swagger/paths/checkouts.json >+++ b/api/v1/swagger/paths/checkouts.json >@@ -135,5 +135,33 @@ > } > } > } >+ }, >+ "/checkouts/history": { >+ "delete": { >+ "x-mojo-to": "Checkouts#delete_history", >+ "operationId": "delete_historyCheckouts", >+ "tags": ["patrons", "checkouts"], >+ "parameters": [{ >+ "$ref": "../parameters.json#/patron_id_qp" >+ }], >+ "produces": ["application/json"], >+ "responses": { >+ "204": { >+ "description": "Checkout history deleted successfully", >+ "schema": { >+ "type": "string" >+ } >+ }, >+ "404": { >+ "description": "Patron not found", >+ "schema": { "$ref": "../definitions.json#/error" } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "circulate": "circulate_remaining_permissions" >+ } >+ } >+ } > } > } >diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t >index 5a34474..a1df3a6 100644 >--- a/t/db_dependent/api/v1/checkouts.t >+++ b/t/db_dependent/api/v1/checkouts.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 93; >+use Test::More tests => 99; > use Test::MockModule; > use Test::Mojo; > use t::lib::Mocks; >@@ -216,3 +216,20 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/all > current_renewals => 1, > error => 'too_many' > }); >+ >+$t->delete_ok( "//$userid:$password@/api/v1/checkouts/history?patron_id=$patron_id") >+ ->status_is(204) >+ ->content_is(''); >+ >+my $patron_to_delete = $builder->build_object({ >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+}); >+ >+my $patron_to_delete_id = $patron_to_delete->borrowernumber; >+ >+$patron_to_delete->delete; >+ >+$t->delete_ok( "//$userid:$password@/api/v1/checkouts/history?patron_id=$patron_to_delete_id") >+ ->status_is(404) >+ ->json_is({error => "Patron doesn't exist"}); >-- >2.7.4
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 18795
:
64255
|
94533
|
94547
|
94548
|
94549
|
94552
|
94555
|
95246
|
95247
|
95248
|
95265
|
95266
|
95267
| 95463 |
95464
|
95465