Bug 32418: Can't call method 'unblessed' on an undefined value at cataloguing/additem.pl

Check whether the current op is edititem or dupeitem and if so check
whether the itemnumber supplied as a query param actually exists.

If it doesn't, redirect to the additem op and hide all UI elements except
for a dialog that gives options to add a new item to the record or to
view the records holdings.

This behaviour was adapted from the addbiblio view, as suggested by
Fridolin.

To test:
1. Go to any record
2. Hit the edit button on an item in the holdings table
3. Modify the URL so that the query param for the itemnumber is either
    3.1 empty: /cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=384&itemnumber=
    3.2 an itemnumber that doesn't exist:
      /cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=384&itemnumber=9999999999
    3.3 whatever else you come up with..
4. Check the same thing for the dupe option (op=dupeitem)
5. Sign off

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Paul Derscheid 2023-02-20 11:06:32 +01:00 committed by Tomas Cohen Arazi
parent a509d34182
commit ef803755f5
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 25 additions and 7 deletions

View file

@ -156,6 +156,14 @@ my ($template, $loggedinuser, $cookie)
flagsrequired => {editcatalogue => $userflags},
});
if ( $op eq 'edititem' || $op eq 'dupeitem' ) {
my $item = Koha::Items->find($itemnumber);
if ( !$item ) {
$itemnumber = undef;
$template->param( item_doesnt_exist => 1 );
output_and_exit( $input, $cookie, $template, 'unknown_item' );
}
}
# Does the user have a restricted item editing permission?
my $patron = Koha::Patrons->find( $loggedinuser );
@ -471,20 +479,18 @@ if ($op eq "additem") {
#-------------------------------------------------------------------------------
# retrieve item if exist => then, it's a modif
$current_item = Koha::Items->find($itemnumber)->unblessed;
# FIXME Handle non existent item
$nextop = "saveitem";
$nextop = "saveitem";
#-------------------------------------------------------------------------------
} elsif ($op eq "dupeitem") {
#-------------------------------------------------------------------------------
# retrieve item if exist => then, it's a modif
$current_item = Koha::Items->find($itemnumber)->unblessed;
# FIXME Handle non existent item
if (C4::Context->preference('autoBarcode') eq 'incremental') {
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
my ($barcode) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
$current_item->{barcode} = $barcode;
}
else {
$current_item->{barcode} = undef; # Don't save it!
$current_item->{barcode} = undef; # Don't save it!
}
$nextop = "additem";

View file

@ -26,7 +26,14 @@
[% INCLUDE 'str/cataloging_additem.inc' %]
[% Asset.js("js/cataloging_additem.js") | $raw %]
<script>
var has_item_groups = "[% item_groups.size | html %]";
var has_item_groups = "[% item_groups.size | html %]";
$(document).ready(function() {
[% IF item_doesnt_exist %]
$("#itemst_wrapper").hide();
$("#menu").hide();
$("#cataloguing_additem_newitem").hide();
[% END %]
});
</script>
</head>
@ -59,6 +66,11 @@
<div class="row">
<div class="col-sm-12">
<main>
[% IF item_doesnt_exist %]
<div class="dialog alert">
<a href="/cgi/bin/koha/catloguing/additem.pl?biblionumber=[% biblio.biblionumber | uri %]">Add a new item</a> or <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]#holdings">go to the records holdings</a>.
</div>
[% END %]
[% INCLUDE 'blocking_errors.inc' %]
<h1>Items for [% biblio.title | html %] [% IF ( biblio.author ) %] by [% biblio.author | html %][% END %] (Record #[% biblio.biblionumber | html %])</h1>