Bug 38010: Add protection logic to the DELETE endpoint

Amended-by: Jonathan Druart
typo: subsicriptions => subscriptions

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2025-04-30 16:07:29 +01:00 committed by Katrin Fischer
parent bbc3041a6c
commit 48592d9d3d
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 14 additions and 1 deletions

View File

@ -171,7 +171,16 @@ sub delete {
my $c = shift->openapi->valid_input or return;
return try {
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
my $basket_count = $vendor->baskets->count;
my $subscription_count = $vendor->subscriptions->count;
my $invoice_count = $vendor->invoices->count;
my $safe_to_delete = ( $basket_count == 0 && $subscription_count == 0 && $invoice_count == 0 ) ? 1 : 0;
return $c->render(
status => 409,
openapi => { error => "Vendor cannot be deleted with existing baskets, subscriptions or invoices" }
) unless $safe_to_delete;
return $c->render_resource_not_found("Vendor")
unless $vendor;

View File

@ -272,6 +272,10 @@
description: Vendor not found
schema:
$ref: "../swagger.yaml#/definitions/error"
"409":
description: Unable to perform action on vendor
schema:
$ref: "../swagger.yaml#/definitions/error"
"500":
description: |
Internal server error. Possible `error_code` attribute values: