Bugzilla – Attachment 174810 Details for
Bug 38050
Add REST endpoints for working with "lists"/"virtual shelves"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38050: create methods for public CRUD list endpoints
Bug-38050-create-methods-for-public-CRUD-list-endp.patch (text/plain), 4.49 KB, created by
Jacob O'Mara
on 2024-11-19 19:17:58 UTC
(
hide
)
Description:
Bug 38050: create methods for public CRUD list endpoints
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2024-11-19 19:17:58 UTC
Size:
4.49 KB
patch
obsolete
>From f012bae2ed8b4d4ab16e09e908db6e33ed48ce08 Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <jacobomara901@gmail.com> >Date: Tue, 29 Oct 2024 11:00:36 +0000 >Subject: [PATCH] Bug 38050: create methods for public CRUD list endpoints > >This patch creates the methods for the public CRUD enpoints for lists/virtualshelves >--- > Koha/REST/V1/Lists.pm | 146 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 146 insertions(+) > >diff --git a/Koha/REST/V1/Lists.pm b/Koha/REST/V1/Lists.pm >index 2fef438abc..8f1126252d 100644 >--- a/Koha/REST/V1/Lists.pm >+++ b/Koha/REST/V1/Lists.pm >@@ -132,6 +132,152 @@ sub delete { > }; > } > >+=head3 public_create >+ >+Create a public virtual shelf >+ >+=cut >+ >+sub public_create { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $user = $c->stash('koha.user'); >+ my $json_body = $c->req->json; >+ >+ $json_body->{owner} = $user->id; >+ >+ return try { >+ >+ my $list = Koha::Virtualshelf->new_from_api($json_body); >+ $list->store->discard_changes; >+ $c->res->headers->location( $c->req->url->to_string . '/' . $list->id ); >+ return $c->render( >+ status => 201, >+ openapi => $c->objects->to_api($list), >+ ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 public_read >+ >+List the contents of a public virtual shelf or a virtual shelf you own >+ >+=cut >+ >+sub public_read { >+ my $c = shift->openapi->valid_input or return; >+ my $user = $c->stash('koha.user'); >+ >+ my $list = Koha::Virtualshelves->find( $c->param('list_id') ); >+ >+ #if the list owner != to the user id, return 403 >+ unless ( $list->owner == $user->id || $list->public == 1 ) { >+ return $c->render( >+ status => 403, >+ openapi => { >+ error => "Forbidden - you can only view your own lists or lists that are public.", >+ error_code => "forbidden", >+ }, >+ ); >+ } >+ return $c->render_resource_not_found("List") >+ unless $list; >+ >+ return $c->render( status => 200, openapi => $c->objects->to_api($list), ); >+} >+ >+=head3 public_update >+ >+Update a public virtual shelf or a shelf you own >+ >+=cut >+ >+sub public_update { >+ my $c = shift->openapi->valid_input or return; >+ my $user = $c->stash('koha.user'); >+ >+ my $list = Koha::Virtualshelves->find( $c->param('list_id') ); >+ >+ #if the list owner != to the user id, return 403 >+ if ( $list->owner != $user->id ) { >+ return $c->render( >+ status => 403, >+ openapi => { >+ error => "Forbidden - you can only update your own lists", >+ error_code => "forbidden", >+ }, >+ ); >+ } >+ >+ #if the allow_change_from_owner is false, return 403 >+ if ( $list->allow_change_from_owner == 0 ) { >+ return $c->render( >+ status => 403, >+ openapi => { >+ error => "Forbidden - you can't update this list", >+ error_code => "forbidden", >+ }, >+ ); >+ } >+ >+ return $c->render_resource_not_found("List") >+ unless $list; >+ >+ return try { >+ $list->set_from_api( $c->req->json ); >+ $list->store(); >+ return $c->render( status => 200, openapi => $c->objects->to_api($list), ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 public_delete >+ >+Delete a public virtual shelf you own >+ >+=cut >+ >+sub public_delete { >+ my $c = shift->openapi->valid_input or return; >+ my $user = $c->stash('koha.user'); >+ >+ my $list = Koha::Virtualshelves->find( $c->param('list_id') ); >+ return $c->render_resource_not_found("List") >+ unless $list; >+ >+ #if the list owner != to the user id, return 403 >+ if ( $list->owner != $user->id ) { >+ return $c->render( >+ status => 403, >+ openapi => { >+ error => "Forbidden - you can only update your own lists", >+ error_code => "forbidden", >+ }, >+ ); >+ } >+ >+ #if the allow_change_from_owner is false, return 403 >+ if ( $list->allow_change_from_owner == 0 ) { >+ return $c->render( >+ status => 403, >+ openapi => { >+ error => "Forbidden - you can't update this list", >+ error_code => "forbidden", >+ }, >+ ); >+ } >+ >+ return try { >+ $list->delete; >+ return $c->render_resource_deleted; >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > =head3 list_public > > =cut >-- >2.39.2
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 38050
:
174807
|
174808
|
174809
|
174810
|
176462
|
176463
|
176464
|
176465
|
176466
|
176467
|
176769
|
176770
|
176771
|
176772
|
176773
|
176774
|
180788
|
180789
|
180790
|
180791
|
180792
|
180793
|
180838
|
180839
|
180840
|
180841
|
180842
|
180843
|
180879
|
180880
|
180881
|
180882
|
180883
|
180884