Bugzilla – Attachment 94547 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.20 KB, created by
Joonas Kylmälä
on 2019-10-22 12:59:15 UTC
(
hide
)
Description:
Bug 18795: DELETE (anonymize) checkout history
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2019-10-22 12:59:15 UTC
Size:
4.20 KB
patch
obsolete
>From b03ca38666ecd1932be92bdacca53f8fa44ca7b2 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 > >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 >--- > 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 b3a0699006..ba3c615a2a 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 d705760f63..62ad73b824 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -53,6 +53,9 @@ > "/checkouts/{checkout_id}/allows_renewal": { > "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1allows_renewal" > }, >+ "/checkouts/history": { >+ "$ref": "paths/checkouts.json#/~1checkouts~1history" >+ }, > "/items/{item_id}": { > "$ref": "paths/items.json#/~1items~1{item_id}" > }, >diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json >index ca6d970dbb..9634e0c139 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 5a3447412e..a1df3a6254 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.17.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 18795
:
64255
|
94533
|
94547
|
94548
|
94549
|
94552
|
94555
|
95246
|
95247
|
95248
|
95265
|
95266
|
95267
|
95463
|
95464
|
95465