From 1371e0b1dbb59c0123bfc1d4ff6b067853105aa8 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Thu, 31 Aug 2017 17:02:42 -0600 Subject: [PATCH] Bug 15520: Add permission to restrict circ rules editing to own library Test plan: 1) Ensure that you have four users: a) A superlibrarian b) A user with all `parameters` permissions (the toplevel `parameters` box is checked). c) A user with the `manage_circ_rules` permission (and, of course, `catalogue`). d) A user with the `manage_circ_rules`, `manage_circ_rules_restricted` and `catalogue` permissions. 2) As all four users, load the "Circulation and fine rules" administration page (admin/smart-rules.pl). 3) The page should be unchanged for the first three users. It should be possible to view and edit the circ rules for all libraries. 4) The last (restricted) user should only be able to view and edit the circ rules for their own library. Amended by JD: In a second version of this patch manage_circ_rules_restricted has been replaced by manage_circ_rules_from_any_libraries and 'no_inherit' related code has been removed --- admin/smart-rules.pl | 7 +++++ .../bug_15520-add_manage_circ_rules_restricted.sql | 1 + installer/data/mysql/userpermissions.sql | 1 + .../intranet-tmpl/prog/en/includes/permissions.inc | 4 ++- .../prog/en/modules/admin/smart-rules.tt | 30 ++++++++++++---------- 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index fe0c9c29f1..e425d8230b 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -33,6 +33,7 @@ use Koha::RefundLostItemFeeRule; use Koha::RefundLostItemFeeRules; use Koha::Libraries; use Koha::Patron::Categories; +use Koha::Patrons; my $input = CGI->new; my $dbh = C4::Context->dbh; @@ -59,6 +60,12 @@ unless ( $branch ) { $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*'; } } + +my $uid = Koha::Patrons->find( $loggedinuser )->userid; +my $restricted_to_own_library = $uid && haspermission( $uid, { parameters => 'manage_circ_rules_restricted' }, { no_inherit => 1 } ); +$template->param( restricted_to_own_library => $restricted_to_own_library ); +$branch = C4::Context::mybranch() if $restricted_to_own_library; + $branch = '*' if $branch eq 'NO_LIBRARY_SET'; my $op = $input->param('op') || q{}; diff --git a/installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql b/installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql new file mode 100644 index 0000000000..830f4fb0aa --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO `permissions` (module_bit, code, description) VALUES(3, 'manage_circ_rules_restricted', 'Only manage circ rules for own library'); diff --git a/installer/data/mysql/userpermissions.sql b/installer/data/mysql/userpermissions.sql index 93d030b410..df025a92d4 100644 --- a/installer/data/mysql/userpermissions.sql +++ b/installer/data/mysql/userpermissions.sql @@ -6,6 +6,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'manage_restrictions', 'Manage restrictions for accounts'), ( 3, 'parameters_remaining_permissions', 'Remaining system parameters permissions'), ( 3, 'manage_circ_rules', 'Manage circulation rules'), + ( 3, 'manage_circ_rules_restricted', 'Only manage circ rules for own library'), ( 4, 'edit_borrowers', 'Add, modify and view patron information'), ( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'), ( 6, 'place_holds', 'Place holds for patrons'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index c5330865fb..3fa7105e8a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -31,7 +31,9 @@ [%- CASE 'manage_restrictions' -%]Manage restrictions for accounts [%- CASE 'overdues_report' -%]Execute overdue items report [%- CASE 'override_renewals' -%]Override blocked renewals - [%- CASE 'manage_circ_rules' -%]manage circulation rules + [%- CASE 'self_checkout' -%]Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID + [%- CASE 'manage_circ_rules' -%]Manage circulation rules + [%- CASE 'manage_circ_rules_restricted' -%]Limit circulation rules editing to the user's own library (please note that manage_circ_rules is still required) [%- CASE 'parameters_remaining_permissions' -%]Remaining system parameters permissions [%- CASE 'edit_borrowers' -%]Add, modify and view patron information [%- CASE 'view_borrower_infos_from_any_libraries' -%]View patron infos from any libraries. If not set the logged in user could only access patron infos from its own library or group of libraries. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 86226cb7d3..f3cbf1ae35 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -39,22 +39,24 @@

To modify a rule, create a new one with the same patron category and item type.

-
- Select a library : - -
- [% IF ( definedbranch ) %] -
- - - + + [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %] -
+ [% IF ( definedbranch ) %] +
+ + + + +
+ [% END %] [% END %]
-- 2.11.0