From f0c8b02c61631d9be068769635c30bd11856dd0a Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 22 Jul 2024 23:41:46 +0000 Subject: [PATCH] Bug 37383: Use libraries_where_can_edit_items to check if items are editable To test: 1 - have a system with 2+ branches 2 - have a bib with 2+ items, all with holdingbranch=A 3 - set logged in library to A 4 - go to bib details page, confirm each item has an Edit button in the holdings table 5 - edit one item, set holdingbranch=B 6 - reload bib details page 7 - confirm the item now at branch B does not have an edit button 8 - APPLY PATCH and restart_all 9 - Try 1 - 6 again, this time you should see the proper edit buttons 10 - Set up library group: * Create a library group for library A + B * Action: Limit item editing by group 11 - Set up test user: * Create a staff patron with these permissions: * catalogue * fast_cataloguing * edit_items * view_borrower_infos_from_any_libraries * edit borrowers * Home library: library A 12 - Set up test items: * Create a record with 3 items with different home libraries: * A * B * C 13 - We expect the use to be able to edit A and B, but not C. 14 - With the same user turn OFF the view_borrower_infos_from_any_libraries permission 15 - Behavior should not change, we expect the use to be able to edit A and B, but not C. 16 - Make sure StaffDetailItemSelection still works as expected for all users. With the sys pref on the checkbox should show up for superlibrarians and users with 'tools' permissions. Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit 66c332a78977b97c753bdc0e1acf60b243df9eca) Signed-off-by: Lucas Gass --- catalogue/detail.pl | 7 ++----- .../html_helpers/tables/items/catalogue_detail.inc | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 9a1306cf05..dd0802c025 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -495,11 +495,8 @@ if ( C4::Context->preference('UseCourseReserves') ) { $template->param( course_reserves => $course_reserves ); } -my @libraries = $biblio->items($items_params)->get_column('homebranch'); -my %can_edit_items_from = map { - $_ => $patron->can_edit_items_from($_) -} @libraries; -$template->param(can_edit_items_from => \%can_edit_items_from); +my @libraries = $patron->libraries_where_can_edit_items; +$template->param(can_edit_items_from => \@libraries); my @itemtypes = Koha::ItemTypes->search->as_list; my %item_type_image_locations = map { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index eaf1790549..722ab6521a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -190,7 +190,7 @@ }); const item_types_notforloan = new Map(all_item_types.map( it => [it.itemtype, it.notforloan] )); - const can_edit_items_from = [% To.json(can_edit_items_from || {}) | $raw %]; + const can_edit_items_from = [% To.json(can_edit_items_from || []) | $raw %]; const item_type_image_locations = [% To.json(item_type_image_locations) | $raw %]; const av_loc = new Map([% To.json(AuthorisedValues.Get('LOC')) | $raw %].map( av => [av.authorised_value, av.lib])); const av_lost = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.itemlost' })) | $raw %].map( av => [av.authorised_value, av.lib])); @@ -300,7 +300,7 @@ searchable: false, orderable: false, render: function (data, type, row, meta) { - if ( can_edit_items_from[row.holding_library_id] ){ + if ( can_edit_items_from.includes(row.home_library_id) || !can_edit_items_from.length ){ if ( items_selection[tab_id].includes(row.item_id) ) { return ''.format(row.item_id); } else { @@ -752,7 +752,7 @@ { data: function( row, type, val, meta ) { let nodes = ''; - if ( can_edit_items_from[row.holding_library_id] ){ + if ( can_edit_items_from.includes(row.home_library_id) || !can_edit_items_from.length ){ [% IF Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %] nodes += '
'; nodes += ' %s'.format(row.biblio_id, row.item_id, _("Edit")); -- 2.39.5