From ec22f77b76a79d1200efeb772cf3b0c495001a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Thu, 3 Sep 2026 09:02:02 +0000 Subject: [PATCH] Bug 10190: (QA follow-up): fix: permissions Important note: the following assumes manage_circ_triggers is intended as a sibling to manage_circ_rules, and that of the two, only manage_circ_triggers ought to grant access to client-side circulation trigger configuration actions. When manage_circ_triggers was introduced, it was not applied client-side, resulting in the router and menu permission checks incorrectly expecting manage_circ_rules. Amend that. Additionally, while the API endpoint blocked a user with only manage_circ_triggers from editing non-triggers circulation rules, it did not block a user with only manage_circ_rules from editing trigger circulation rules. Add a guard clause. Test plan (based on comment 872): A) Go to a patron's 'More' > 'Set permissions' tab. Check 'catalogue' (needed for basic staff login), and under circulation-rules sub-permissions, check only 'Manage overdue notice triggers' - leave 'Manage circulation rules' unchecked. B) Log in as that patron, go to 'Administration' - 'Circulation triggers' link present (admin-home.tt now correctly checks CAN_user_parameters_manage_circ_triggers), 'Circulation and fine rules' is not present. C) Visit http://localhost:8081/cgi-bin/koha/admin/circulation_triggers directly - you are granted access. D) Confirm that you can create and edit circulation triggers. E) Go to a patron's 'More' > 'Set permissions' tab. Check 'catalogue' (needed for basic staff login), and under circulation-rules sub-permissions, check only 'Manage circulation rules' - leave 'Manage overdue notice triggers' unchecked. F) Log in as that patron, go to 'Administration' - no 'Circulation triggers' link present (as we require manage_circ_triggers), however 'Circulation and fine rules' is present. G) Visit http://localhost:8081/cgi-bin/koha/admin/circulation_triggers directly - you see "Error: You do not have permission to access this page" and are prompted to log in as a different user (as we require manage_circ_triggers). H) Go to http://localhost:8081/cgi-bin/koha/admin/smart-rules.pl, and confirm that you can edit circulation rules for your library (no regression). Assisted-by: Claude Opus 5 (Anthropic) Sponsored-by: Glasgow Colleges Library Group Signed-off-by: Nick Clemens Signed-off-by: Pedro Amorim --- Koha/REST/V1/CirculationRules.pm | 15 +++++++++++++++ .../prog/en/modules/admin/admin-home.tt | 4 ++-- .../js/vue/modules/admin/circulation_triggers.ts | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/CirculationRules.pm b/Koha/REST/V1/CirculationRules.pm index eeff57ebb0..c7740e6aa6 100644 --- a/Koha/REST/V1/CirculationRules.pm +++ b/Koha/REST/V1/CirculationRules.pm @@ -271,6 +271,21 @@ sub set_rules { } } + unless ( haspermission( $logged_in_user->userid, { parameters => 'manage_circ_triggers' } ) + || haspermission( $logged_in_user->userid, { circulate => 'circulate_remaining_permissions' } ) ) + { + my @trigger_rules = grep { /^overdue_/ } keys %{$body}; + if (@trigger_rules) { + return $c->render( + status => 403, + openapi => { + error => + 'the manage_circ_triggers or circulate_remaining_permissions permission is required to manage circulation triggers' + } + ); + } + } + if ( $patron_category eq '*' ) { $patron_category = undef; } else { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 96937fadfe..9a1b718c5c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -85,7 +85,7 @@ [% END %] - [% IF ( CAN_user_parameters_manage_patron_categories || CAN_user_parameters_manage_circ_rules || CAN_user_parameters_manage_patron_attributes || CAN_user_parameters_manage_transfers || CAN_user_parameters_manage_item_circ_alerts || CAN_user_parameters_manage_cities || CAN_user_parameters_manage_curbside_pickups ) %] + [% IF ( CAN_user_parameters_manage_patron_categories || CAN_user_parameters_manage_circ_rules || CAN_user_parameters_manage_circ_triggers || CAN_user_parameters_manage_patron_attributes || CAN_user_parameters_manage_transfers || CAN_user_parameters_manage_item_circ_alerts || CAN_user_parameters_manage_cities || CAN_user_parameters_manage_curbside_pickups ) %]

Patrons and circulation

[% IF ( CAN_user_parameters_manage_patron_categories ) %] @@ -96,7 +96,7 @@
Circulation and fine rules
Define circulation and fine rules for combinations of libraries, patron categories, and item types
[% END %] - [% IF ( CAN_user_parameters_manage_circ_rules ) %] + [% IF ( CAN_user_parameters_manage_circ_triggers ) %]
Circulation triggers
Define triggers for circulation notices
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/circulation_triggers.ts b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/circulation_triggers.ts index 9eee3955c8..1d5aa38c12 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/circulation_triggers.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/circulation_triggers.ts @@ -57,7 +57,7 @@ router.beforeEach((to, from, next) => { .then(() => { if ( !circRulesStore.isUserPermitted( - "CAN_user_parameters_manage_circ_rules" + "CAN_user_parameters_manage_circ_triggers" ) ) { navigationStore.$patch({