Bugzilla – Attachment 52682 Details for
Bug 15165
REST API routes to list, edit and pay borrower's accountlines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15165 - Add API route to edit accountlines
Bug-15165---Add-API-route-to-edit-accountlines.patch (text/plain), 6.73 KB, created by
Lari Taskula
on 2016-06-22 12:12:13 UTC
(
hide
)
Description:
Bug 15165 - Add API route to edit accountlines
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2016-06-22 12:12:13 UTC
Size:
6.73 KB
patch
obsolete
>From d9d88931e0a33e24c4a90dda36a61d7ff97c08e1 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 10 Nov 2015 16:43:35 +0100 >Subject: [PATCH] Bug 15165 - Add API route to edit accountlines > >PUT /accountlines/{accountlines_id} (edit) > >Test plan: >1. Open a browser tab on Koha staff and log in (to create CGISESSID > cookie). You should have permission updatecharges. >2. Send PUT request to http://yourlibrary/api/v1/accountlines/YYY > where YYY is one of your accountlines_id. See the body definition > in definitions/editAccountlineBody.json and use this in your PUT request. >3. Run unit tests in t/db_dependent/api/v1/accountlines.t >--- > Koha/REST/V1/Accountline.pm | 22 +++++++++++++ > api/v1/definitions/editAccountlineBody.json | 17 ++++++++++ > api/v1/definitions/index.json | 1 + > api/v1/swagger.json | 48 +++++++++++++++++++++++++++++ > t/db_dependent/api/v1/accountlines.t | 40 +++++++++++++++++++++++- > 5 files changed, 127 insertions(+), 1 deletion(-) > create mode 100644 api/v1/definitions/editAccountlineBody.json > >diff --git a/Koha/REST/V1/Accountline.pm b/Koha/REST/V1/Accountline.pm >index 04a92de..7f33511 100644 >--- a/Koha/REST/V1/Accountline.pm >+++ b/Koha/REST/V1/Accountline.pm >@@ -36,4 +36,26 @@ sub list { > return $c->$cb($accountlines->unblessed, 200); > } > >+ >+sub edit { >+ my ($c, $args, $cb) = @_; >+ >+ my $user = $c->stash('koha.user'); >+ unless ($user && haspermission($user->userid, {updatecharges => 1})) { >+ return $c->$cb({error => "You don't have the required permission"}, 403); >+ } >+ >+ my $accountline = Koha::Accountlines->find($args->{accountlines_id}); >+ unless ($accountline) { >+ return $c->$cb({error => "Accountline not found"}, 404); >+ } >+ >+ my $body = $c->req->json; >+ >+ $accountline->set( $body ); >+ $accountline->store(); >+ >+ return $c->$cb($accountline->unblessed(), 200); >+} >+ > 1; >diff --git a/api/v1/definitions/editAccountlineBody.json b/api/v1/definitions/editAccountlineBody.json >new file mode 100644 >index 0000000..6cb2f2f >--- /dev/null >+++ b/api/v1/definitions/editAccountlineBody.json >@@ -0,0 +1,17 @@ >+{ >+ "type": "object", >+ "properties": { >+ "amount": { >+ "description": "Amount" >+ }, >+ "amountoutstanding": { >+ "description": "Amount outstanding" >+ }, >+ "note": { >+ "description": "Accountline note" >+ }, >+ "meansofpayment": { >+ "description": "Means of payment" >+ } >+ } >+} >diff --git a/api/v1/definitions/index.json b/api/v1/definitions/index.json >index b881583..198349a 100644 >--- a/api/v1/definitions/index.json >+++ b/api/v1/definitions/index.json >@@ -1,5 +1,6 @@ > { > "accountline": { "$ref": "accountline.json" }, >+ "editAccountlineBody": { "$ref": "editAccountlineBody.json" }, > "patron": { "$ref": "patron.json" }, > "holds": { "$ref": "holds.json" }, > "hold": { "$ref": "hold.json" }, >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index 17b5bc5..e74cd66 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -257,6 +257,47 @@ > } > } > } >+ }, >+ "/accountlines/{accountlines_id}": { >+ "put": { >+ "operationId": "editAccountlines", >+ "tags": ["accountlines"], >+ "produces": [ >+ "application/json" >+ ], >+ "parameters": [ >+ { "$ref": "#/parameters/accountlinesIdPathParam" }, >+ { >+ "name": "body", >+ "in": "body", >+ "description": "A JSON object containing fields to modify", >+ "required": true, >+ "schema": { "$ref": "#/definitions/editAccountlineBody" } >+ } >+ ], >+ "consumes": ["application/json"], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Updated accountline", >+ "schema": { "$ref": "#/definitions/accountline" } >+ }, >+ "400": { >+ "description": "Missing or wrong parameters", >+ "schema": { "$ref": "#/definitions/error" } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { >+ "$ref": "#/definitions/error" >+ } >+ }, >+ "404": { >+ "description": "Accountline not found", >+ "schema": { "$ref": "#/definitions/error" } >+ } >+ } >+ } > } > }, > "definitions": { >@@ -276,6 +317,13 @@ > "description": "Internal hold identifier", > "required": true, > "type": "integer" >+ }, >+ "accountlinesIdPathParam": { >+ "name": "accountlines_id", >+ "in": "path", >+ "description": "Internal accountline identifier", >+ "required": true, >+ "type": "integer" > } > } > } >diff --git a/t/db_dependent/api/v1/accountlines.t b/t/db_dependent/api/v1/accountlines.t >index cbe98c8..30b7a08 100644 >--- a/t/db_dependent/api/v1/accountlines.t >+++ b/t/db_dependent/api/v1/accountlines.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 18; > use Test::Mojo; > use t::lib::TestBuilder; > >@@ -41,6 +41,9 @@ my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; > $t->get_ok('/api/v1/accountlines') > ->status_is(403); > >+$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) >+ ->status_is(403); >+ > my $loggedinuser = $builder->build({ > source => 'Borrower', > value => { >@@ -101,4 +104,39 @@ $json = $t->tx->res->json; > ok(ref $json eq 'ARRAY', 'response is a JSON array'); > ok(scalar @$json == 4, 'response array contains 3 elements'); > >+# Editing accountlines tests >+my $put_data = { >+ 'amount' => -19, >+ 'amountoutstanding' => -19 >+}; >+ >+ >+$tx = $t->ua->build_tx( >+ PUT => "/api/v1/accountlines/11224409" >+ => {Accept => '*/*'} >+ => json => $put_data); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(404); >+ >+my $accountline_to_edit = Koha::Accountlines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; >+ >+$tx = $t->ua->build_tx( >+ PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" >+ => {Accept => '*/*'} >+ => json => $put_data); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(200); >+ >+my $accountline_edited = Koha::Accountlines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; >+ >+is($accountline_edited->{amount}, '-19.000000'); >+is($accountline_edited->{amountoutstanding}, '-19.000000'); >+ >+ >+# Payment tests >+ > $dbh->rollback; >-- >1.9.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 15165
:
44804
|
44805
|
44806
|
45259
|
50189
|
50190
|
50191
|
50790
|
52681
|
52682
|
52683
|
55033
|
55034
|
55035
|
56694
|
56695
|
56696
|
57843
|
57844
|
57845
|
57846
|
59239
|
59240
|
59241
|
59242
|
59932
|
59933
|
59934
|
60180
|
62769
|
62770
|
62771
|
62772
|
62773
|
62774
|
62775