Bug 38251 - "Remove selected items" button not removing single item in OPAC lists
Summary: "Remove selected items" button not removing single item in OPAC lists
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Lists (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Phil Ringnalda
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords:
Depends on: 37150
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-24 03:31 UTC by David Cook
Modified: 2024-10-29 07:54 UTC (History)
3 users (show)

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


Attachments
Bug 38251: Make 'Remove selected items' button work when there is one item (3.90 KB, patch)
2024-10-24 22:00 UTC, Phil Ringnalda
Details | Diff | Splinter Review
Bug 38251: Make 'Remove selected items' button work when there is one item (3.95 KB, patch)
2024-10-25 20:20 UTC, Roman Dolny
Details | Diff | Splinter Review
Bug 38251: Make 'Remove selected items' button work when there is one item (4.01 KB, patch)
2024-10-28 08:32 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2024-10-24 03:31:01 UTC
For some reason you can't remove items from lists in the OPAC using the "Remove selected items" button.

You can individually remove items from lists using the "Remove from this list" link though.
Comment 1 Phil Ringnalda 2024-10-24 06:04:22 UTC
You can remove items, what you can't do is remove an item: one fails, two or more works.

https://git.koha-community.org/Koha-community/Koha/src/commit/e74f10042d78a919fabab43f60e64d238686a33e/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt#L955 thinks that if  selected_titles.size() == 1 that means you clicked the Remove from this list and it can just stuff the biblionumber in its hidden form and submit that, but biblionumber isn't defined if you checked one checkbox and used Remove selected items.

Bonus, in #L967 single_bib is always undefined, it's a Reference error, so no matter what you do and whether it works or not you get a nice JS error in the console.
Comment 2 David Cook 2024-10-24 06:36:49 UTC
You're a legend, Phil. Thanks for troubleshooting that further. 

I love finding bugs when testing bug fixes for other things... 😭
Comment 3 Phil Ringnalda 2024-10-24 20:58:27 UTC
Ah, git archaeology failed me for the origin of the single_bib thing because it actually came from the obsoleted attachment 167965 [details] [review] for bug 37150, though it landed in a followup to bug 36557, because working on two patches to the same bit of code at the same time is hard.
Comment 4 Phil Ringnalda 2024-10-24 21:58:18 UTC
(In reply to David Cook from comment #2)
> I love finding bugs when testing bug fixes for other things... 😭

Oh, like bug 38268?
Comment 5 Phil Ringnalda 2024-10-24 22:00:21 UTC
Created attachment 173308 [details] [review]
Bug 38251: Make 'Remove selected items' button work when there is one item

There are two ways to remove items from a list: you can remove a single item
by clicking a 'Remove from this list' button below the item, or you can
remove one or more items by checking the checkboxes for them and clicking the
'Remove selected items' button.

Bug 37150 needed to fix 'Remove from this list' for CSRF, because in the wild
old days it just triggered a GET to delete, and instead it needed to POST.
The first patch to do that defined the JS var single_bib, checked the
checkbox for that bib and submitted the form, as though you had used the
checkbox yourself. But if you cancelled the confirmation prompt, it would
need to uncheck the checkbox it checked, so it added a function to do that
if (single_bib). That patch didn't land.

What landed instead was a patch with a separate hidden form that could be
populated with the single biblionumber from 'Remove from this list', but
without single_bib to define that state, it used selected_titles.size() == 1
as the condition to use the hidden form, forgetting that when the user checks
a single checkbox, selected_titles.size() is also 1. The right condition is
the same one used to tell where to get the titles for the confirmation dialog:
if the click event passed along a biblionumber, it's 'Remove from this list.'
Since checking that sets var biblionumber, we can just use that being truthy
as the condition.

Test plan:
 1. Without the patch, open the OPAC and log in
 2. Add any two biblios to a new list
 3. Lists - {your list name}
 4. Click the checkbox for one of the items, click 'Remove selected items'
    and click 'Yes, remove from list' in the confirmation dialog
 5. Note that it wasn't removed
 6. Click the checkboxes for both items, click 'Remove selected items' and
    click 'Yes, remove from list' in the confirmation dialog
 7. Note that both were removed
 8. Apply patch, restart_all
 9. Add any four items to your list
10. Lists - {your list name}
11. For the first item, click the 'Remove from this list' button below the
    details for the item, confirm, make sure it was deleted
12. Click the checkbox for what's now the first item, click 'Remove from
    this list,' confirm, make sure it was deleted
13. Click the checkboxes for what are now the first two items, click 'Remove
    from this list,' confirm, make sure both were deleted

Sponsored-by: Chetco Community Public Library
Comment 6 Roman Dolny 2024-10-25 20:20:07 UTC
Created attachment 173411 [details] [review]
Bug 38251: Make 'Remove selected items' button work when there is one item

There are two ways to remove items from a list: you can remove a single item
by clicking a 'Remove from this list' button below the item, or you can
remove one or more items by checking the checkboxes for them and clicking the
'Remove selected items' button.

Bug 37150 needed to fix 'Remove from this list' for CSRF, because in the wild
old days it just triggered a GET to delete, and instead it needed to POST.
The first patch to do that defined the JS var single_bib, checked the
checkbox for that bib and submitted the form, as though you had used the
checkbox yourself. But if you cancelled the confirmation prompt, it would
need to uncheck the checkbox it checked, so it added a function to do that
if (single_bib). That patch didn't land.

What landed instead was a patch with a separate hidden form that could be
populated with the single biblionumber from 'Remove from this list', but
without single_bib to define that state, it used selected_titles.size() == 1
as the condition to use the hidden form, forgetting that when the user checks
a single checkbox, selected_titles.size() is also 1. The right condition is
the same one used to tell where to get the titles for the confirmation dialog:
if the click event passed along a biblionumber, it's 'Remove from this list.'
Since checking that sets var biblionumber, we can just use that being truthy
as the condition.

Test plan:
 1. Without the patch, open the OPAC and log in
 2. Add any two biblios to a new list
 3. Lists - {your list name}
 4. Click the checkbox for one of the items, click 'Remove selected items'
    and click 'Yes, remove from list' in the confirmation dialog
 5. Note that it wasn't removed
 6. Click the checkboxes for both items, click 'Remove selected items' and
    click 'Yes, remove from list' in the confirmation dialog
 7. Note that both were removed
 8. Apply patch, restart_all
 9. Add any four items to your list
10. Lists - {your list name}
11. For the first item, click the 'Remove from this list' button below the
    details for the item, confirm, make sure it was deleted
12. Click the checkbox for what's now the first item, click 'Remove from
    this list,' confirm, make sure it was deleted
13. Click the checkboxes for what are now the first two items, click 'Remove
    from this list,' confirm, make sure both were deleted

Sponsored-by: Chetco Community Public Library
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 7 Martin Renvoize (ashimema) 2024-10-28 08:32:33 UTC
Created attachment 173435 [details] [review]
Bug 38251: Make 'Remove selected items' button work when there is one item

There are two ways to remove items from a list: you can remove a single item
by clicking a 'Remove from this list' button below the item, or you can
remove one or more items by checking the checkboxes for them and clicking the
'Remove selected items' button.

Bug 37150 needed to fix 'Remove from this list' for CSRF, because in the wild
old days it just triggered a GET to delete, and instead it needed to POST.
The first patch to do that defined the JS var single_bib, checked the
checkbox for that bib and submitted the form, as though you had used the
checkbox yourself. But if you cancelled the confirmation prompt, it would
need to uncheck the checkbox it checked, so it added a function to do that
if (single_bib). That patch didn't land.

What landed instead was a patch with a separate hidden form that could be
populated with the single biblionumber from 'Remove from this list', but
without single_bib to define that state, it used selected_titles.size() == 1
as the condition to use the hidden form, forgetting that when the user checks
a single checkbox, selected_titles.size() is also 1. The right condition is
the same one used to tell where to get the titles for the confirmation dialog:
if the click event passed along a biblionumber, it's 'Remove from this list.'
Since checking that sets var biblionumber, we can just use that being truthy
as the condition.

Test plan:
 1. Without the patch, open the OPAC and log in
 2. Add any two biblios to a new list
 3. Lists - {your list name}
 4. Click the checkbox for one of the items, click 'Remove selected items'
    and click 'Yes, remove from list' in the confirmation dialog
 5. Note that it wasn't removed
 6. Click the checkboxes for both items, click 'Remove selected items' and
    click 'Yes, remove from list' in the confirmation dialog
 7. Note that both were removed
 8. Apply patch, restart_all
 9. Add any four items to your list
10. Lists - {your list name}
11. For the first item, click the 'Remove from this list' button below the
    details for the item, confirm, make sure it was deleted
12. Click the checkbox for what's now the first item, click 'Remove from
    this list,' confirm, make sure it was deleted
13. Click the checkboxes for what are now the first two items, click 'Remove
    from this list,' confirm, make sure both were deleted

Sponsored-by: Chetco Community Public Library
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Katrin Fischer 2024-10-29 07:54:43 UTC
Pushed for 24.11!

Well done everyone, thank you!