Bugzilla – Attachment 173625 Details for
Bug 28965
Add public routes for lists
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28965: Add /public/lists
Bug-28965-Add-publiclists.patch (text/plain), 8.45 KB, created by
Kyle M Hall (khall)
on 2024-10-29 12:17:27 UTC
(
hide
)
Description:
Bug 28965: Add /public/lists
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2024-10-29 12:17:27 UTC
Size:
8.45 KB
patch
obsolete
>From 5f2f99699e9ada516332204010be92a5685e5a75 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 7 Sep 2021 13:35:13 -0300 >Subject: [PATCH] Bug 28965: Add /public/lists > >This patch adds a route for publicly retrieving lists. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/V1/Lists.pm | 71 ++++++++++++++++++++++++++++ > Koha/Schema/Result/Virtualshelve.pm | 4 +- > Koha/Virtualshelf.pm | 32 +++++++++++++ > api/v1/swagger/definitions/list.yaml | 38 +++++++++++++++ > api/v1/swagger/paths/lists.yaml | 52 ++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 5 ++ > 6 files changed, 201 insertions(+), 1 deletion(-) > create mode 100644 Koha/REST/V1/Lists.pm > create mode 100644 api/v1/swagger/definitions/list.yaml > create mode 100644 api/v1/swagger/paths/lists.yaml > >diff --git a/Koha/REST/V1/Lists.pm b/Koha/REST/V1/Lists.pm >new file mode 100644 >index 00000000000..ffe3977a215 >--- /dev/null >+++ b/Koha/REST/V1/Lists.pm >@@ -0,0 +1,71 @@ >+package Koha::REST::V1::Lists; >+ >+# 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::Virtualshelves; >+ >+use Try::Tiny qw( catch try ); >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 list_public >+ >+=cut >+ >+sub list_public { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $user = $c->stash('koha.user'); >+ >+ my $only_mine = delete $c->param('only_mine'); >+ my $only_public = delete $c->param('only_public'); >+ >+ return $c->render( >+ status => 400, >+ openapi => { error => "only_mine and only_public are mutually exclussive" } >+ ) if $only_mine and $only_public; >+ >+ if ( !$user and $only_mine ) { >+ $c->render( >+ status => 200, >+ openapi => [], >+ ); >+ } >+ >+ return try { >+ my $lists_set = Koha::Virtualshelves->new; >+ if ($only_mine) { >+ $lists_set = $lists_set->search( { owner => $user->id } ); >+ } elsif ($only_public) { >+ $lists_set = $lists_set->filter_by_public; >+ } else { >+ $lists_set = $lists_set->filter_by_readable( { patron_id => $user->id } ); >+ } >+ >+ my $lists = $c->objects->search($lists_set); >+ return $c->render( status => 200, openapi => $lists ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/Koha/Schema/Result/Virtualshelve.pm b/Koha/Schema/Result/Virtualshelve.pm >index b2cd76ec4f5..06d3978fd77 100644 >--- a/Koha/Schema/Result/Virtualshelve.pm >+++ b/Koha/Schema/Result/Virtualshelve.pm >@@ -230,7 +230,9 @@ sub koha_objects_class { > } > > __PACKAGE__->add_columns( >- '+public' => { is_boolean => 1 }, >+ '+allow_change_from_others' => { is_boolean => 1 }, >+ '+allow_change_from_owner' => { is_boolean => 1 }, >+ '+public' => { is_boolean => 1 }, > ); > > __PACKAGE__->add_columns( >diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm >index 2cea7e61e88..fea70466f35 100644 >--- a/Koha/Virtualshelf.pm >+++ b/Koha/Virtualshelf.pm >@@ -398,6 +398,38 @@ sub transfer_ownership { > return $self; > } > >+=head3 to_api_mapping >+ >+This method returns the mapping for representing a Koha::Virtualshelf object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ created_on => 'creation_date', >+ lastmodified => 'updated_on_date', >+ owner => 'owner_id', >+ shelfname => 'name', >+ shelfnumber => 'list_id', >+ sortfield => 'default_sort_field', >+ }; >+} >+ >+=head3 public_read_list >+ >+This method returns the list of publicly readable database fields for both API and UI output purposes >+ >+=cut >+ >+sub public_read_list { >+ return [ >+ 'created_on', 'lastmodified', 'shelfname', >+ 'shelfnumber', 'public', 'sortfield', >+ 'allow_change_from_owner', 'allow_change_from_others' >+ ]; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/api/v1/swagger/definitions/list.yaml b/api/v1/swagger/definitions/list.yaml >new file mode 100644 >index 00000000000..c17f9da4856 >--- /dev/null >+++ b/api/v1/swagger/definitions/list.yaml >@@ -0,0 +1,38 @@ >+--- >+type: object >+properties: >+ list_id": >+ description: Interal identifier for the list >+ type: integer >+ name: >+ description: List name >+ type: string >+ creation_date: >+ description: Date the list was created >+ type: string >+ format: date-time >+ updated_on_date: >+ description: Date the list was last updated >+ type: string >+ format: date-time >+ owner_id: >+ description: Internal identifier for the owning patron >+ type: integer >+ allow_change_from_owner: >+ description: If the owner can change the contents >+ type: boolean >+ allow_change_from_others: >+ description: If others can change the contents >+ type: boolean >+ public: >+ description: If the list is public >+ type: boolean >+additionalProperties: false >+required: >+ - list_id >+ - name >+ - creation_date >+ - updated_on_date >+ - allow_change_from_owner >+ - allow_change_from_others >+ - public >diff --git a/api/v1/swagger/paths/lists.yaml b/api/v1/swagger/paths/lists.yaml >new file mode 100644 >index 00000000000..f6fa88f501b >--- /dev/null >+++ b/api/v1/swagger/paths/lists.yaml >@@ -0,0 +1,52 @@ >+--- >+"/public/lists": >+ get: >+ x-mojo-to: Lists#list_public >+ operationId: listListsPublic >+ description: "This resource returns a list of existing bibliographic lists." >+ summary: List bibliographic lists >+ tags: >+ - lists >+ parameters: >+ - name: only_mine >+ in: query >+ description: Only return the users' lists >+ required: false >+ type: string >+ - name: only_public >+ in: query >+ description: Only return public lists >+ required: false >+ type: string >+ - $ref: "../swagger.yaml#/parameters/match" >+ - $ref: "../swagger.yaml#/parameters/order_by" >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/q_param" >+ - $ref: "../swagger.yaml#/parameters/q_body" >+ - $ref: "../swagger.yaml#/parameters/request_id_header" >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: A list of transfer limits >+ schema: >+ type: array >+ "400": >+ description: Bad parameter >+ 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: >+ catalogue: 1 >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index e6292df58bb..6d6fe1d917a 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -507,6 +507,8 @@ paths: > $ref: ./paths/libraries.yaml#/~1public~1libraries > "/public/libraries/{library_id}": > $ref: "./paths/libraries.yaml#/~1public~1libraries~1{library_id}" >+ "/public/lists": >+ $ref: "./paths/lists.yaml#/~1public~1lists" > "/public/oauth/login/{provider_code}/{interface}": > $ref: ./paths/public_oauth.yaml#/~1public~1oauth~1login~1{provider_code}~1{interface} > "/public/patrons/{patron_id}/article_requests/{article_request_id}": >@@ -1230,6 +1232,9 @@ tags: > - description: "Manage libraries\n" > name: libraries > x-displayName: Libraries >+ - description: "Manage lists" >+ name: "lists" >+ x-displayName: Lists > - description: "Manage macros\n" > name: macros > x-displayName: Macros >-- >2.39.5 (Apple Git-154)
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 28965
:
124635
|
124636
|
165976
|
165977
|
173624
|
173625
|
173626
|
173627
|
173687
|
173688
|
173689
|
173690
|
173780
|
173781
|
173782
|
173783