From 9403a9510405d3bc069ab879533f5f7e811ebd16 Mon Sep 17 00:00:00 2001 From: "Alex Carver [Acerock7]" Date: Fri, 12 Jun 2026 18:57:17 +0000 Subject: [PATCH] Bug 41253: Item Modification by Age should have its own permission Adds a new permission to control access to the Item Modification by Age tool in the Cataloging Module. Previously access to this tool was controlled by the items_batchmod permission. This can be an issue for consortiums where staff members should be able to batch change items that belong to their library, but who shouldn't be able to define item aging rules. Staff with automatic item aging tool access can use authorized values to change items that belong to other libraries. This patch introduces a dedicated permission (items_modification_by_age) to restrict access to the tool to users with this permission. - new permission definition via atomicupdate - removal of dependency on items_batchmod for tool access - updated permission UI display - updated cataloguing-home button visibility - updated flagsrequired check in tool script Signed-off-by: Andrew Fuerste Henry Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim --- ...dd_items_modification_by_age_permission.pl | 51 +++++++++++++++++++ .../data/mysql/mandatory/userpermissions.sql | 1 + .../prog/en/includes/permissions.inc | 3 ++ .../en/modules/cataloguing/cataloging-home.tt | 4 +- tools/automatic_item_modification_by_age.pl | 2 +- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_41253_add_items_modification_by_age_permission.pl diff --git a/installer/data/mysql/atomicupdate/bug_41253_add_items_modification_by_age_permission.pl b/installer/data/mysql/atomicupdate/bug_41253_add_items_modification_by_age_permission.pl new file mode 100755 index 0000000000..b78b67062d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41253_add_items_modification_by_age_permission.pl @@ -0,0 +1,51 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "41253", + description => "Add items_modification_by_age permission", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + INSERT IGNORE INTO permissions (module_bit, code, description) + VALUES (13, 'items_modification_by_age', 'Define rules for automatic item aging') + } + ); + + say $out "Added new permission 'items_modification_by_age'"; + + my $sth = $dbh->prepare( + q{ + SELECT borrowernumber + FROM user_permissions + WHERE code = 'items_batchmod' + } + ); + + $sth->execute(); + + my @borrowernumbers; + while ( my ($borrowernumber) = $sth->fetchrow_array ) { + push @borrowernumbers, $borrowernumber; + } + + if (@borrowernumbers) { + + my $insert_sth = $dbh->prepare( + q{ + INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) + VALUES (?, 13, 'items_modification_by_age') + } + ); + + foreach my $borrowernumber (@borrowernumbers) { + $insert_sth->execute($borrowernumber); + } + + say_success( $out, "Granted items_modification_by_age to users with items_batchmod" ); + } + }, +}; diff --git a/installer/data/mysql/mandatory/userpermissions.sql b/installer/data/mysql/mandatory/userpermissions.sql index dbd907f6dd..3d32c18f64 100644 --- a/installer/data/mysql/mandatory/userpermissions.sql +++ b/installer/data/mysql/mandatory/userpermissions.sql @@ -126,6 +126,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'items_batchmod', 'Perform batch modification of items'), (13, 'items_batchmod_restricted', 'Limit batch item modification to subfields defined in the SubfieldsToAllowForRestrictedBatchmod preference (please note that items_batchmod is still required)'), (13, 'items_batchdel', 'Perform batch deletion of items'), + (13, 'items_modification_by_age', 'Define rules for automatic item aging'), (13, 'manage_csv_profiles', 'Manage CSV export profiles'), (13, 'moderate_tags', 'Moderate patron tags'), (13, 'rotating_collections', 'Manage rotating collections'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index b12e828a91..119f6dcd5c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -436,6 +436,9 @@ Limit batch item modification to subfields defined in the SubfieldsToAllowForRestrictedBatchmod preference (please note that items_batchmod is still required) ([% name | html %]) + [%- CASE 'items_modification_by_age' -%] + Define rules for automatic item aging + ([% name | html %]) [%- CASE 'label_creator' -%] Create printable labels and barcodes from catalog and patron data ([% name | html %]) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt index da7cc85691..cbb5288820 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt @@ -165,10 +165,10 @@ [% END %] - [% IF ( CAN_user_tools_items_batchmod || ( CAN_user_stockrotation_manage_rotas && Koha.Preference('StockRotation') ) ) %] + [% IF ( CAN_user_tools_items_modification_by_age || ( CAN_user_stockrotation_manage_rotas && Koha.Preference('StockRotation') ) ) %]

Automation

    - [% IF ( CAN_user_tools_items_batchmod ) %] + [% IF ( CAN_user_tools_items_modification_by_age ) %]
  • Item modifications by age
  • diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl index c307b237d2..f68b43498f 100755 --- a/tools/automatic_item_modification_by_age.pl +++ b/tools/automatic_item_modification_by_age.pl @@ -53,7 +53,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( template_name => "tools/automatic_item_modification_by_age.tt", query => $cgi, type => "intranet", - flagsrequired => { tools => 'items_batchmod' }, + flagsrequired => { tools => 'items_modification_by_age' }, } );