Bugzilla – Attachment 128914 Details for
Bug 29765
Make Koha::Patron->safe_to_delete return a Koha::Result::Boolean object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29765: Adjust DELETE /patrons/:patron_id controller
Bug-29765-Adjust-DELETE-patronspatronid-controller.patch (text/plain), 4.37 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-12-27 10:25:46 UTC
(
hide
)
Description:
Bug 29765: Adjust DELETE /patrons/:patron_id controller
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-12-27 10:25:46 UTC
Size:
4.37 KB
patch
obsolete
>From 28e95bd1645841813fa7ca9f02e3d7f46ff5a7f4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 23 Dec 2021 11:47:19 -0300 >Subject: [PATCH] Bug 29765: Adjust DELETE /patrons/:patron_id controller > >This patch adjusts the only current place using the >Koha::Patron->safe_to_delete method to the new return value. There >should be no behavior change > >To test: >1. Apply the previous patches >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/patrons.t >=> FAIL: Tests fail, because of the change, the controller is broken >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! No test tweak required, no behavior change >5. Sign off :-D >--- > Koha/REST/V1/Patrons.pm | 81 +++++++++++++++++++++-------------------- > 1 file changed, 42 insertions(+), 39 deletions(-) > >diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm >index 122b99a2ce..469d9536b4 100644 >--- a/Koha/REST/V1/Patrons.pm >+++ b/Koha/REST/V1/Patrons.pm >@@ -333,46 +333,49 @@ sub delete { > > my $safe_to_delete = $patron->safe_to_delete; > >- if ( $safe_to_delete eq 'ok' ) { >- $patron->_result->result_source->schema->txn_do( >- sub { >- $patron->move_to_deleted; >- $patron->delete; >- >- return $c->render( >- status => 204, >- openapi => q{} >- ); >- } >- ); >- } >- elsif ( $safe_to_delete eq 'has_checkouts' ) { >- return $c->render( >- status => 409, >- openapi => { error => 'Pending checkouts prevent deletion' } >- ); >- } >- elsif ( $safe_to_delete eq 'has_debt' ) { >- return $c->render( >- status => 409, >- openapi => { error => 'Pending debts prevent deletion' } >- ); >- } >- elsif ( $safe_to_delete eq 'has_guarantees' ) { >- return $c->render( >- status => 409, >- openapi => { error => 'Patron is a guarantor and it prevents deletion' } >- ); >- } >- elsif ( $safe_to_delete eq 'is_anonymous_patron' ) { >- return $c->render( >- status => 403, >- openapi => { error => 'Anonymous patron cannot be deleted' } >- ); >- } >- else { >- Koha::Exceptions::Exception->throw( "Koha::Patron->safe_to_delete returned an unexpected value: $safe_to_delete" ); >+ if ( !$safe_to_delete ) { >+ # Pick the first error, if any >+ my ( $error ) = grep { $_->type eq 'error' } @{ $safe_to_delete->messages }; >+ unless ( $error ) { >+ Koha::Exceptions::Exception->throw('Koha::Patron->safe_to_delete returned false but carried no error message'); >+ } >+ >+ if ( $error->message eq 'has_checkouts' ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Pending checkouts prevent deletion' } >+ ); >+ } elsif ( $error->message eq 'has_debt' ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Pending debts prevent deletion' } >+ ); >+ } elsif ( $error->message eq 'has_guarantees' ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Patron is a guarantor and it prevents deletion' } >+ ); >+ } elsif ( $error->message eq 'is_anonymous_patron' ) { >+ return $c->render( >+ status => 403, >+ openapi => { error => 'Anonymous patron cannot be deleted' } >+ ); >+ } else { >+ Koha::Exceptions::Exception->throw( 'Koha::Patron->safe_to_delete carried an unexpected message: ' . $error->message ); >+ } > } >+ >+ return $patron->_result->result_source->schema->txn_do( >+ sub { >+ $patron->move_to_deleted; >+ $patron->delete; >+ >+ return $c->render( >+ status => 204, >+ openapi => q{} >+ ); >+ } >+ ); > } catch { > if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { > return $c->render( >-- >2.34.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 29765
:
128887
|
128888
|
128914
|
128928
|
128929
|
128999
|
129000