Bugzilla – Attachment 136975 Details for
Bug 31080
Block adding the bundle item to its own bundle
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31080: Prevent bundles from being nested
Bug-31080-Prevent-bundles-from-being-nested.patch (text/plain), 4.91 KB, created by
Martin Renvoize (ashimema)
on 2022-07-01 14:27:03 UTC
(
hide
)
Description:
Bug 31080: Prevent bundles from being nested
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-07-01 14:27:03 UTC
Size:
4.91 KB
patch
obsolete
>From cadb48e6e3ab078686a884928b7ac212767696cf Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 1 Jul 2022 15:02:58 +0100 >Subject: [PATCH] Bug 31080: Prevent bundles from being nested > >This is a follow-up for bug 28854 to prevent bundle type items from >being nested in to other bundles. >--- > Koha/Exceptions/Item/Bundle.pm | 49 +++++++++++++++++++ > Koha/Item.pm | 4 ++ > Koha/REST/V1/Items.pm | 8 +++ > .../prog/en/modules/catalogue/detail.tt | 7 +++ > 4 files changed, 68 insertions(+) > create mode 100644 Koha/Exceptions/Item/Bundle.pm > >diff --git a/Koha/Exceptions/Item/Bundle.pm b/Koha/Exceptions/Item/Bundle.pm >new file mode 100644 >index 0000000000..0ad0a2af00 >--- /dev/null >+++ b/Koha/Exceptions/Item/Bundle.pm >@@ -0,0 +1,49 @@ >+package Koha::Exceptions::Item::Bundle; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Exception; >+ >+use Exception::Class ( >+ >+ 'Koha::Exceptions::Item::Bundle' => { >+ isa => 'Koha::Exception', >+ }, >+ 'Koha::Exceptions::Item::Bundle::IsBundle' => { >+ isa => 'Koha::Exceptions::Item::Bundle', >+ description => "A bundle cannot be added to a bundle", >+ } >+); >+ >+=head1 NAME >+ >+Koha::Exceptions::Item::Bundle - Base class for Bundle exceptions >+ >+=head1 Exceptions >+ >+=head2 Koha::Exceptions::Item::Bundle >+ >+Generic Item::Bundle exception >+ >+=head2 Koha::Exceptions::Item::Bundle::IsBundle >+ >+Exception to be used when attempting to add one bundle into another. >+ >+=cut >+ >+1; >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 53d84a85f9..c51b88afc0 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -37,6 +37,7 @@ use Koha::CirculationRules; > use Koha::CoverImages; > use Koha::SearchEngine::Indexer; > use Koha::Exceptions::Item::Transfer; >+use Koha::Exceptions::Item::Bundle; > use Koha::Item::Transfer::Limits; > use Koha::Item::Transfers; > use Koha::Item::Attributes; >@@ -1548,6 +1549,9 @@ Adds the bundle_item passed to this item > sub add_to_bundle { > my ( $self, $bundle_item ) = @_; > >+ Koha::Exceptions::Item::Bundle::IsBundle->throw() >+ if $bundle_item->is_bundle; >+ > my $schema = Koha::Database->new->schema; > > my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue'); >diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm >index 88a0675257..515fcd91bf 100644 >--- a/Koha/REST/V1/Items.pm >+++ b/Koha/REST/V1/Items.pm >@@ -229,6 +229,14 @@ sub add_to_bundle { > } > ); > } >+ elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) { >+ return $c->render( >+ status => 400, >+ openapi => { >+ error => 'Bundles cannot be nested' >+ } >+ ); >+ } > else { > $c->unhandled_exception($_); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >index 3d481b1b46..cb1439d94a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >@@ -1617,6 +1617,13 @@ Note that permanent location is a code, and location may be an authval. > } > } else if ( data.status === 404 ) { > $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>'); >+ } else if ( data.status === 400 ) { >+ var response = data.responseJSON; >+ if ( response.error === "Bundles cannot be nested" ) { >+ $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' is a bundle and bundles cannot be nested").format(barcode)+'</div>'); >+ } else { >+ $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>'); >+ } > } else { > $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>'); > } >-- >2.20.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 31080
:
136975
|
137053
|
137054
|
140908
|
140909
|
143991
|
143992
|
144054
|
144055