Bugzilla – Attachment 172201 Details for
Bug 35797
REST API: Add GET route for patronimage
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35797: REST API Add GET route for patronimage
Bug-35797-REST-API-Add-GET-route-for-patronimage.patch (text/plain), 5.73 KB, created by
David Nind
on 2024-09-29 20:55:01 UTC
(
hide
)
Description:
Bug 35797: REST API Add GET route for patronimage
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-09-29 20:55:01 UTC
Size:
5.73 KB
patch
obsolete
>From 120d1d9e9a04d3028a7c1ef716f8005bdff839fb Mon Sep 17 00:00:00 2001 >From: Shi Yao Wang <shi-yao.wang@inlibro.com> >Date: Wed, 7 Aug 2024 09:46:10 -0400 >Subject: [PATCH] Bug 35797: REST API Add GET route for patronimage > >Api changes adding GET route for patronimage > >Test plan: >1- Apply the patch >2- Run `npm run api:bundle` >2- Go to administration -> sys.pref. -> set patronimages to allow >3- Log in koha using a user with "list_borrowers" or "edit_borrowers" privileges >4- Have a patron with a profile image (add an image if necessary by >searching for a patron and then clicking on the default profile image on >the top left) >5- Open a an API testing tool (such as postman), write >{intranet_url}/api/v1/patrons/{borrowernumber}/default_image >where {intranet_url} is the base intranet url of koha and {borrowernumber} >is the borrowernumber of a borrower that has an image >6- Add OAuth 2.0 credentials coming from koha (patron -> more -> manage >api keys) and generate a token >7- Send the request and notice the image of the patron is returned >8- Do step 5-7 with a borrowernumber of a patron without an image and a >borrowernumber of a patron that doesn't exist (and other edge cases >where there should be an error message displayed such as "Access >forbidden", "Authentication required", etc.) >9- Notice an appropriate error message is displayed > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/REST/V1/Patrons/Image.pm | 74 +++++++++++++++++++++++++ > api/v1/swagger/paths/patrons_image.yaml | 42 ++++++++++++++ > api/v1/swagger/swagger.yaml | 2 + > 3 files changed, 118 insertions(+) > create mode 100644 Koha/REST/V1/Patrons/Image.pm > create mode 100644 api/v1/swagger/paths/patrons_image.yaml > >diff --git a/Koha/REST/V1/Patrons/Image.pm b/Koha/REST/V1/Patrons/Image.pm >new file mode 100644 >index 0000000000..3cba4612a9 >--- /dev/null >+++ b/Koha/REST/V1/Patrons/Image.pm >@@ -0,0 +1,74 @@ >+package Koha::REST::V1::Patrons::Image; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Patrons; >+ >+use Try::Tiny qw( catch try ); >+ >+use MIME::Base64 qw( encode_base64 ); >+ >+=head1 NAME >+ >+Koha::REST::V1::Patrons::Image >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 get >+ >+Controller method that gets a patron's image >+ >+=cut >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $patron = Koha::Patrons->find( $c->param('patron_id') ); >+ >+ unless ($patron) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Patron not found." } >+ ); >+ } >+ >+ return try { >+ my $image = $patron->image; >+ >+ unless ($image) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Patron image not found." } >+ ); >+ } >+ >+ return $c->render( >+ status => 200, >+ format => "png", # currently all patron images are converted to png upon upload >+ data => $image->imagefile >+ ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/api/v1/swagger/paths/patrons_image.yaml b/api/v1/swagger/paths/patrons_image.yaml >new file mode 100644 >index 0000000000..38fb7b6b90 >--- /dev/null >+++ b/api/v1/swagger/paths/patrons_image.yaml >@@ -0,0 +1,42 @@ >+--- >+"/patrons/{patron_id}/default_image": >+ get: >+ x-mojo-to: Patrons::Image#get >+ operationId: getPatronImage >+ tags: >+ - patrons >+ summary: Get image of a patron >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/patron_id_pp" >+ produces: >+ - image/png >+ responses: >+ "200": >+ description: Patron's image >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Patron not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ - borrowers: "list_borrowers" >+ - borrowers: "edit_borrowers" >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index dd72361380..51aba7776c 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -459,6 +459,8 @@ paths: > $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds" > "/patrons/{patron_id}/checkouts": > $ref: "./paths/patrons_checkouts.yaml#/~1patrons~1{patron_id}~1checkouts" >+ "/patrons/{patron_id}/default_image": >+ $ref: "./paths/patrons_image.yaml#/~1patrons~1{patron_id}~1default_image" > "/patrons/{patron_id}/password": > $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password" > "/patrons/{patron_id}/password/expiration_date": >-- >2.39.5
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 35797
:
160993
|
161273
|
161610
|
170137
|
170186
| 172201 |
176695
|
176696