Bugzilla – Attachment 91103 Details for
Bug 17003
Add API route to get checkout's renewability
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17003: Adapt to OpenAPI
Bug-17003-Adapt-to-OpenAPI.patch (text/plain), 4.54 KB, created by
Kyle M Hall (khall)
on 2019-06-28 15:29:11 UTC
(
hide
)
Description:
Bug 17003: Adapt to OpenAPI
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2019-06-28 15:29:11 UTC
Size:
4.54 KB
patch
obsolete
>From a50dcac0605029e82b9eaf8c7c1ee3d942efd3d8 Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Thu, 21 Feb 2019 02:30:00 +0000 >Subject: [PATCH] Bug 17003: Adapt to OpenAPI > >Test plan: >prove t/db_dependent/api/v1/checkouts.t > >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Michal Denar <black23@gmail.com> >Signed-off-by: Johanna Raisa <johanna.raisa@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/V1/Checkouts.pm | 40 +++++++++++------------------ > api/v1/swagger/paths/checkouts.json | 3 +-- > t/db_dependent/api/v1/checkouts.t | 8 ++---- > 3 files changed, 18 insertions(+), 33 deletions(-) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index a45974369a..b1bc8632e6 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -129,37 +129,27 @@ sub renew { > } > > sub renewability { >- my ($c, $args, $cb) = @_; >- >- my $user = $c->stash('koha.user'); >- >- my $OpacRenewalAllowed; >- if ($user->borrowernumber == $borrowernumber) { >- $OpacRenewalAllowed = C4::Context->preference('OpacRenewalAllowed'); >- } >- >- unless ($user && ($OpacRenewalAllowed >- || haspermission($user->userid, { circulate => "circulate_remaining_permissions" }))) { >- return $c->$cb({error => "You don't have the required permission"}, 403); >- } >+ my $c = shift->openapi->valid_input or return; > >- my $checkout_id = $args->{checkout_id}; >- my $checkout = Koha::Issues->find($checkout_id); >+ my $checkout_id = $c->validation->param('checkout_id'); >+ my $checkout = Koha::Checkouts->find( $checkout_id ); > >- if (!$checkout) { >- return $c->$cb({ >- error => "Checkout doesn't exist" >- }, 404); >+ unless ($checkout) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Checkout doesn't exist" } >+ ); > } > >- my $borrowernumber = $checkout->borrowernumber; >- my $itemnumber = $checkout->itemnumber; >- > my ($can_renew, $error) = C4::Circulation::CanBookBeRenewed( >- $borrowernumber, $itemnumber); >+ $checkout->borrowernumber, $checkout->itemnumber); > >- return $c->$cb({ renewable => Mojo::JSON->true, error => undef }, 200) if $can_renew; >- return $c->$cb({ renewable => Mojo::JSON->false, error => $error }, 200); >+ my $renewable = Mojo::JSON->false; >+ $renewable = Mojo::JSON->true if $can_renew; >+ return $c->render( >+ status => 200, >+ openapi => { renewable => $renewable, error => $error } >+ ); > } > > =head3 _to_api >diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json >index 76e7151824..342aa5a7ac 100644 >--- a/api/v1/swagger/paths/checkouts.json >+++ b/api/v1/swagger/paths/checkouts.json >@@ -99,6 +99,7 @@ > }, > "/checkouts/{checkout_id}/renewability": { > "get": { >+ "x-mojo-to": "Checkout#renewability", > "operationId": "renewabilityCheckout", > "tags": ["patrons", "checkouts"], > "parameters": [{ >@@ -120,8 +121,6 @@ > } > }, > "x-koha-authorization": { >- "allow-owner": true, >- "allow-guarantor": true, > "permissions": { > "circulate": "circulate_remaining_permissions" > } >diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t >index e4c0f2102e..5c92694ee4 100644 >--- a/t/db_dependent/api/v1/checkouts.t >+++ b/t/db_dependent/api/v1/checkouts.t >@@ -169,9 +169,7 @@ $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i > required_permissions => { circulate => "circulate_remaining_permissions" } > }); > >-$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/" . $issue2->issue_id . "/renewability"); >-$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id}); >-$t->request_ok($tx) >+$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability") > ->status_is(200) > ->json_is({ renewable => Mojo::JSON->true, error => undef }); > >@@ -185,8 +183,6 @@ $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/re > ->status_is(403) > ->json_is({ error => 'Renewal not authorized (too_many)' }); > >-$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/" . $issue2->issue_id . "/renewability"); >-$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id}); >-$t->request_ok($tx) >+$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewability") > ->status_is(200) > ->json_is({ renewable => Mojo::JSON->false, error => 'too_many' }); >-- >2.20.1 (Apple Git-117)
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 17003
:
54709
|
54710
|
56507
|
57489
|
57493
|
58099
|
85475
|
85476
|
87155
|
87156
|
87157
|
87445
|
87446
|
88260
|
88261
|
88262
|
88589
|
88590
|
88591
|
91102
| 91103 |
91104
|
91105