Bugzilla – Attachment 170475 Details for
Bug 37513
Disable 'Delete' button if the record source cannot be deleted
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37513: Handle Koha::Exceptions::Object::FKConstraintDeletio in controller
Bug-37513-Handle-KohaExceptionsObjectFKConstraintD.patch (text/plain), 3.09 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-08-19 17:58:04 UTC
(
hide
)
Description:
Bug 37513: Handle Koha::Exceptions::Object::FKConstraintDeletio in controller
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-08-19 17:58:04 UTC
Size:
3.09 KB
patch
obsolete
>From f6727b22fa73a6afb584c672bd0adec1e1af175b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 19 Aug 2024 11:16:00 -0300 >Subject: [PATCH] Bug 37513: Handle > Koha::Exceptions::Object::FKConstraintDeletio in controller > >--- > Koha/REST/V1/RecordSources.pm | 12 +++++++++++- > api/v1/swagger/paths/record_sources.yaml | 7 +++++++ > t/db_dependent/api/v1/record_sources.t | 10 +++++++++- > 3 files changed, 27 insertions(+), 2 deletions(-) > >diff --git a/Koha/REST/V1/RecordSources.pm b/Koha/REST/V1/RecordSources.pm >index 46ce01b50ff..d51eaeacdac 100644 >--- a/Koha/REST/V1/RecordSources.pm >+++ b/Koha/REST/V1/RecordSources.pm >@@ -23,7 +23,8 @@ use Mojo::Base 'Mojolicious::Controller'; > > use Koha::RecordSources; > >-use Try::Tiny qw( catch try ); >+use Scalar::Util qw( blessed ); >+use Try::Tiny qw( catch try ); > > =head1 API > >@@ -121,6 +122,15 @@ sub delete { > $source->delete; > return $c->render_resource_deleted; > } catch { >+ if ( blessed($_) && ref($_) eq 'Koha::Exceptions::Object::FKConstraintDeletion' ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => 'Cannot delete record source linked to existing records', >+ error_code => 'cannot_delete_used', >+ } >+ ); >+ } > $c->unhandled_exception($_); > }; > } >diff --git a/api/v1/swagger/paths/record_sources.yaml b/api/v1/swagger/paths/record_sources.yaml >index 1e3da462733..7dbbf589d8d 100644 >--- a/api/v1/swagger/paths/record_sources.yaml >+++ b/api/v1/swagger/paths/record_sources.yaml >@@ -233,6 +233,13 @@ > description: Not found > schema: > $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: | >+ Conflict in deleting resource. Possible `error_code` attribute values: >+ >+ * `cannot_delete_used`: record source linked to a record cannot be deleted. >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" > "500": > description: | > Internal server error. Possible `error_code` attribute values: >diff --git a/t/db_dependent/api/v1/record_sources.t b/t/db_dependent/api/v1/record_sources.t >index 0fb37a90919..2ab1e5f1f43 100755 >--- a/t/db_dependent/api/v1/record_sources.t >+++ b/t/db_dependent/api/v1/record_sources.t >@@ -136,7 +136,7 @@ subtest 'get() tests' => sub { > > subtest 'delete() tests' => sub { > >- plan tests => 10; >+ plan tests => 12; > > $schema->storage->txn_begin; > >@@ -175,6 +175,14 @@ subtest 'delete() tests' => sub { > $source = $builder->build_object( { class => 'Koha::RecordSources' } ); > $id = $source->id; > >+ my $biblio = $builder->build_sample_biblio(); >+ my $metadata = $biblio->metadata; >+ $metadata->record_source_id( $source->id )->store(); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is( 409, 'REST3.2.4.1' ); >+ >+ $biblio->delete(); >+ > $t->delete_ok("//$userid:$password@/api/v1/record_sources/$id")->status_is( 204, 'REST3.2.4' ) > ->content_is( q{}, 'REST3.3.4' ); > >-- >2.46.0
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 37513
:
170475
|
170476
|
170477
|
170478
|
170479
|
170512
|
170513
|
170514
|
170515
|
170516
|
170544
|
170545
|
170546
|
170547
|
170548
|
171205
|
171236