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 <michaela.sieber@kit.edu>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Lucas Gass 2024-07-22 23:41:46 +00:00 committed by Martin Renvoize
parent 83966f4273
commit 66c332a789
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 5 additions and 8 deletions

View file

@ -495,11 +495,8 @@ if ( C4::Context->preference('UseCourseReserves') ) {
$template->param( course_reserves => $course_reserves ); $template->param( course_reserves => $course_reserves );
} }
my @libraries = $biblio->items($items_params)->get_column('homebranch'); my @libraries = $patron->libraries_where_can_edit_items;
my %can_edit_items_from = map { $template->param(can_edit_items_from => \@libraries);
$_ => $patron->can_edit_items_from($_)
} @libraries;
$template->param(can_edit_items_from => \%can_edit_items_from);
my @itemtypes = Koha::ItemTypes->search->as_list; my @itemtypes = Koha::ItemTypes->search->as_list;
my %item_type_image_locations = map { my %item_type_image_locations = map {

View file

@ -190,7 +190,7 @@
}); });
const item_types_notforloan = new Map(all_item_types.map( it => [it.itemtype, it.notforloan] )); 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 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_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])); 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, searchable: false,
orderable: false, orderable: false,
render: function (data, type, row, meta) { 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) ) { if ( items_selection[tab_id].includes(row.item_id) ) {
return '<input type="checkbox" value="%s" name="itemnumber" checked />'.format(row.item_id); return '<input type="checkbox" value="%s" name="itemnumber" checked />'.format(row.item_id);
} else { } else {
@ -752,7 +752,7 @@
{ {
data: function( row, type, val, meta ) { data: function( row, type, val, meta ) {
let nodes = ''; 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') %] [% IF Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %]
nodes += '<div class="btn-group">'; nodes += '<div class="btn-group">';
nodes += ' <a class="btn btn-default btn-xs" href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=%s&itemnumber=%s#edititem"><i class="fa-solid fa-pencil"></i> %s</a><a class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>'.format(row.biblio_id, row.item_id, _("Edit")); nodes += ' <a class="btn btn-default btn-xs" href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=%s&itemnumber=%s#edititem"><i class="fa-solid fa-pencil"></i> %s</a><a class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>'.format(row.biblio_id, row.item_id, _("Edit"));