@@ -, +, @@ own library 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. administration page (admin/smart-rules.pl). possible to view and edit the circ rules for all libraries. circ rules for their own library. --- C4/Auth.pm | 12 ++++++--- admin/smart-rules.pl | 7 +++++ .../bug_15520-add_manage_circ_rules_restricted.sql | 1 + .../intranet-tmpl/prog/en/includes/permissions.inc | 3 ++- .../prog/en/modules/admin/smart-rules.tt | 30 ++++++++++++---------- 5 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -2023,17 +2023,20 @@ sub get_all_subpermissions { =head2 haspermission - $flags = ($userid, $flagsrequired); + $flags = ( $userid, $flagsrequired[, { no_inherit => 1 } ] ); C<$userid> the userid of the member C<$flags> is a hashref of required flags like C<$borrower-<{authflags}> +C, if true, means that this function will not return true if +$flagsrequired is { module => 'sub_perm' } and the user only has { module => 1 }. +This is useful for *_restricted permissions. Returns member's flags or 0 if a permission is not met. =cut sub haspermission { - my ( $userid, $flagsrequired ) = @_; + my ( $userid, $flagsrequired, $options ) = @_; my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?"); $sth->execute($userid); my $row = $sth->fetchrow(); @@ -2044,7 +2047,7 @@ sub haspermission { $flags->{'superlibrarian'} = 1; } - return $flags if $flags->{superlibrarian}; + return $flags if $flags->{superlibrarian} && !$options->{no_inherit}; foreach my $module ( keys %$flagsrequired ) { my $subperm = $flagsrequired->{$module}; @@ -2053,7 +2056,8 @@ sub haspermission { } else { return 0 unless ( ( defined $flags->{$module} and - $flags->{$module} == 1 ) + $flags->{$module} == 1 and + !$options->{no_inherit} ) or ( ref( $flags->{$module} ) and exists $flags->{$module}->{$subperm} and --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -34,6 +34,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; @@ -60,6 +61,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{}; --- a/installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql +++ a/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'); --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -32,7 +32,8 @@ [%- CASE 'overdues_report' -%]Execute overdue items report [%- CASE 'override_renewals' -%]Override blocked renewals [%- 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' -%]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 'modify_holds_priority' -%]Modify holds priority [%- CASE 'place_holds' -%]Place holds for patrons --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -38,22 +38,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 %]
--