Bug 36786 - (Bug 31791 follow-up) Koha explodes when trying to edit a bibliographic record with an invalid biblionumber
Summary: (Bug 31791 follow-up) Koha explodes when trying to edit a bibliographic recor...
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal
Assignee: Janusz Kaczmarek
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
Depends on: 31791
Blocks:
  Show dependency treegraph
 
Reported: 2024-05-06 09:07 UTC by Janusz Kaczmarek
Modified: 2024-07-05 10:33 UTC (History)
4 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00
Circulation function:


Attachments
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (1.65 KB, patch)
2024-05-06 09:19 UTC, Janusz Kaczmarek
Details | Diff | Splinter Review
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (1.70 KB, patch)
2024-05-06 15:43 UTC, Roman Dolny
Details | Diff | Splinter Review
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (1.94 KB, patch)
2024-05-07 12:01 UTC, Janusz Kaczmarek
Details | Diff | Splinter Review
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (2.00 KB, patch)
2024-05-07 12:17 UTC, Janusz Kaczmarek
Details | Diff | Splinter Review
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (2.08 KB, patch)
2024-05-07 13:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber (2.12 KB, patch)
2024-05-07 18:09 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Janusz Kaczmarek 2024-05-06 09:07:12 UTC
After changes made to addbiblio with the bug 31791, when trying to open the editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber) Koha explodes with a message << Can't call method "can_be_edited" on an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>
Comment 1 Janusz Kaczmarek 2024-05-06 09:19:06 UTC
Created attachment 166190 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get the 403 error page.

Sponsored-by: Ignatianum University in Cracow
Comment 2 Roman Dolny 2024-05-06 15:43:38 UTC
Created attachment 166233 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get the 403 error page.

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 3 Tomás Cohen Arazi (tcohen) 2024-05-07 11:46:41 UTC
Hi, I felt tempted to rewrite all those conditionals on adding this feature. I didn't do it because I didn't intend to change other behaviors.
One of those is the fact this page has some custom handling of the record not found use case. I don't think it is THAT important, but with your patch, that part of the template becomes unreachable, and thus requires a cleanup.

That said, I'd suggest you make the condition be checked as an else of the previous one:

```perl
    if ($biblio) {
        if ( !$biblio->can_be_edited($logged_in_patron) ) {
            print $input->redirect("/cgi-bin/koha/errors/403.pl");    # escape early
            exit;
    } else {
        $biblionumber = undef;
        $template->param( bib_doesnt_exist => 1 );
    }
```

Otherwise you will be returning 403 when the record doesn't exist, which should be a 404 and has specific code for handling it.
Comment 4 Janusz Kaczmarek 2024-05-07 12:01:13 UTC
(In reply to Tomás Cohen Arazi from comment #3)
> That said, I'd suggest you make the condition be checked as an else of the
> previous one:
> 

Thank you, Tomás, you are right--that would be much better!  A new version follows.
Comment 5 Janusz Kaczmarek 2024-05-07 12:01:51 UTC
Created attachment 166260 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get the 403 error page.

Sponsored-by: Ignatianum University in Cracow
Comment 6 Janusz Kaczmarek 2024-05-07 12:17:59 UTC
Created attachment 166262 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get a page with the info: "The record you are trying
   to edit doesn't exist...".

Sponsored-by: Ignatianum University in Cracow
Comment 7 Matt Blenkinsop 2024-05-07 13:46:39 UTC
Created attachment 166285 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get a page with the info: "The record you are trying
   to edit doesn't exist...".

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Comment 8 Tomás Cohen Arazi (tcohen) 2024-05-07 18:09:02 UTC
Created attachment 166328 [details] [review]
Bug 36786: (Bug 31791 follow-up) Koha explodes when trying to edit a biblio with invalid biblionumber

After changes made to addbiblio with the bug 31791, when trying to open the
editor with biblionumber=<invalid_number> (e.g. a deleted biblionumber)
Koha explodes with a message << Can't call method "can_be_edited" on
an undefined value at /kohadevbox/koha/cataloguing/addbiblio.pl line 555 >>

Test plan:
==========
1. Try to edit a biblio giving as a biblionumber (in URL) a non-existing
   biblionumber, e.g. in ktd, with standard ktd test data:
   http://your_ktd:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=1234567
   Koha should explode with the message:
   Can't call method "can_be_edited" on an undefined value at
   /kohadevbox/koha/cataloguing/addbiblio.pl line 555
2. Apply the patch; restart_all.
3. Repeat p.1.  You should get a page with the info: "The record you are trying
   to edit doesn't exist...".

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 9 Katrin Fischer 2024-05-08 16:25:27 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 10 Fridolin Somers 2024-05-24 14:53:11 UTC
Depends on Bug 31791 not in 23.11.x
Comment 11 David Nind 2024-07-05 10:33:34 UTC
No changes required to the manual.