|
Lines 20-25
use Modern::Perl;
Link Here
|
| 20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
| 21 |
|
21 |
|
| 22 |
use Koha::Database; |
22 |
use Koha::Database; |
|
|
23 |
use Koha::Exceptions; |
| 23 |
use Koha::Patrons; |
24 |
use Koha::Patrons; |
| 24 |
|
25 |
|
| 25 |
use Scalar::Util qw( blessed ); |
26 |
use Scalar::Util qw( blessed ); |
|
Lines 330-369
sub delete {
Link Here
|
| 330 |
|
331 |
|
| 331 |
return try { |
332 |
return try { |
| 332 |
|
333 |
|
| 333 |
if ( $patron->checkouts->count > 0 ) { |
334 |
my $safe_to_delete = $patron->safe_to_delete; |
|
|
335 |
|
| 336 |
if ( $safe_to_delete eq 'ok' ) { |
| 337 |
$patron->_result->result_source->schema->txn_do( |
| 338 |
sub { |
| 339 |
$patron->move_to_deleted; |
| 340 |
$patron->delete; |
| 341 |
|
| 342 |
return $c->render( |
| 343 |
status => 204, |
| 344 |
openapi => q{} |
| 345 |
); |
| 346 |
} |
| 347 |
); |
| 348 |
} |
| 349 |
elsif ( $safe_to_delete eq 'has_checkouts' ) { |
| 334 |
return $c->render( |
350 |
return $c->render( |
| 335 |
status => 409, |
351 |
status => 409, |
| 336 |
openapi => { error => 'Pending checkouts prevent deletion' } |
352 |
openapi => { error => 'Pending checkouts prevent deletion' } |
| 337 |
); |
353 |
); |
| 338 |
} |
354 |
} |
| 339 |
|
355 |
elsif ( $safe_to_delete eq 'has_debt' ) { |
| 340 |
my $account = $patron->account; |
|
|
| 341 |
|
| 342 |
if ( $account->outstanding_debits->total_outstanding > 0 ) { |
| 343 |
return $c->render( |
356 |
return $c->render( |
| 344 |
status => 409, |
357 |
status => 409, |
| 345 |
openapi => { error => 'Pending debts prevent deletion' } |
358 |
openapi => { error => 'Pending debts prevent deletion' } |
| 346 |
); |
359 |
); |
| 347 |
} |
360 |
} |
| 348 |
|
361 |
elsif ( $safe_to_delete eq 'has_guarantees' ) { |
| 349 |
if ( $patron->guarantee_relationships->count > 0 ) { |
|
|
| 350 |
return $c->render( |
362 |
return $c->render( |
| 351 |
status => 409, |
363 |
status => 409, |
| 352 |
openapi => { error => 'Patron is a guarantor and it prevents deletion' } |
364 |
openapi => { error => 'Patron is a guarantor and it prevents deletion' } |
| 353 |
); |
365 |
); |
| 354 |
} |
366 |
} |
| 355 |
|
367 |
elsif ( $safe_to_delete eq 'is_anonymous_patron' ) { |
| 356 |
$patron->_result->result_source->schema->txn_do( |
368 |
return $c->render( |
| 357 |
sub { |
369 |
status => 403, |
| 358 |
$patron->move_to_deleted; |
370 |
openapi => { error => 'Anonymous patron cannot be deleted' } |
| 359 |
$patron->delete; |
371 |
); |
| 360 |
|
372 |
} |
| 361 |
return $c->render( |
373 |
else { |
| 362 |
status => 204, |
374 |
Koha::Exceptions::Exception->throw( "Koha::Patron->safe_to_delete returned an unexpected value: $safe_to_delete" ); |
| 363 |
openapi => q{} |
375 |
} |
| 364 |
); |
|
|
| 365 |
} |
| 366 |
); |
| 367 |
} catch { |
376 |
} catch { |
| 368 |
if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { |
377 |
if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { |
| 369 |
return $c->render( |
378 |
return $c->render( |