View | Details | Raw Unified | Return to bug 15520
Collapse All | Expand All

(-)a/C4/Auth.pm (-4 / +8 lines)
Lines 2026-2042 sub get_all_subpermissions { Link Here
2026
2026
2027
=head2 haspermission
2027
=head2 haspermission
2028
2028
2029
  $flags = ($userid, $flagsrequired);
2029
  $flags = ( $userid, $flagsrequired[, { no_inherit => 1 } ] );
2030
2030
2031
C<$userid> the userid of the member
2031
C<$userid> the userid of the member
2032
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2032
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2033
C<no_inherit>, if true, means that this function will not return true if
2034
$flagsrequired is { module => 'sub_perm' } and the user only has { module => 1 }.
2035
This is useful for *_restricted permissions.
2033
2036
2034
Returns member's flags or 0 if a permission is not met.
2037
Returns member's flags or 0 if a permission is not met.
2035
2038
2036
=cut
2039
=cut
2037
2040
2038
sub haspermission {
2041
sub haspermission {
2039
    my ( $userid, $flagsrequired ) = @_;
2042
    my ( $userid, $flagsrequired, $options ) = @_;
2040
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2043
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2041
    $sth->execute($userid);
2044
    $sth->execute($userid);
2042
    my $row = $sth->fetchrow();
2045
    my $row = $sth->fetchrow();
Lines 2047-2053 sub haspermission { Link Here
2047
        $flags->{'superlibrarian'} = 1;
2050
        $flags->{'superlibrarian'} = 1;
2048
    }
2051
    }
2049
2052
2050
    return $flags if $flags->{superlibrarian};
2053
    return $flags if $flags->{superlibrarian} && !$options->{no_inherit};
2051
2054
2052
    foreach my $module ( keys %$flagsrequired ) {
2055
    foreach my $module ( keys %$flagsrequired ) {
2053
        my $subperm = $flagsrequired->{$module};
2056
        my $subperm = $flagsrequired->{$module};
Lines 2056-2062 sub haspermission { Link Here
2056
        } else {
2059
        } else {
2057
            return 0 unless (
2060
            return 0 unless (
2058
                ( defined $flags->{$module} and
2061
                ( defined $flags->{$module} and
2059
                    $flags->{$module} == 1 )
2062
                    $flags->{$module} == 1 and
2063
                    !$options->{no_inherit} )
2060
                or
2064
                or
2061
                ( ref( $flags->{$module} ) and
2065
                ( ref( $flags->{$module} ) and
2062
                    exists $flags->{$module}->{$subperm} and
2066
                    exists $flags->{$module}->{$subperm} and
(-)a/admin/smart-rules.pl (+7 lines)
Lines 33-38 use Koha::RefundLostItemFeeRule; Link Here
33
use Koha::RefundLostItemFeeRules;
33
use Koha::RefundLostItemFeeRules;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
36
use Koha::Patrons;
36
37
37
my $input = CGI->new;
38
my $input = CGI->new;
38
my $dbh = C4::Context->dbh;
39
my $dbh = C4::Context->dbh;
Lines 59-64 unless ( $branch ) { Link Here
59
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
60
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
60
    }
61
    }
61
}
62
}
63
64
my $uid = Koha::Patrons->find( $loggedinuser )->userid;
65
my $restricted_to_own_library = $uid && haspermission( $uid, { parameters => 'manage_circ_rules_restricted' }, { no_inherit => 1 } );
66
$template->param( restricted_to_own_library => $restricted_to_own_library );
67
$branch = C4::Context::mybranch() if $restricted_to_own_library;
68
62
$branch = '*' if $branch eq 'NO_LIBRARY_SET';
69
$branch = '*' if $branch eq 'NO_LIBRARY_SET';
63
70
64
my $op = $input->param('op') || q{};
71
my $op = $input->param('op') || q{};
(-)a/installer/data/mysql/atomicupdate/bug_15520-add_manage_circ_rules_restricted.sql (+1 lines)
Line 0 Link Here
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 (-1 / +2 lines)
Lines 32-38 Link Here
32
    [%- CASE 'overdues_report' -%]<span>Execute overdue items report</span>
32
    [%- CASE 'overdues_report' -%]<span>Execute overdue items report</span>
33
    [%- CASE 'override_renewals' -%]<span>Override blocked renewals</span>
33
    [%- CASE 'override_renewals' -%]<span>Override blocked renewals</span>
34
    [%- CASE 'self_checkout' -%]<span>Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID</span>
34
    [%- CASE 'self_checkout' -%]<span>Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID</span>
35
    [%- CASE 'manage_circ_rules' -%]<span>manage circulation rules</span>
35
    [%- CASE 'manage_circ_rules' -%]<span>Manage circulation rules</span>
36
    [%- CASE 'manage_circ_rules_restricted' -%]<span>Limit circulation rules editing to the user's own library (please note that manage_circ_rules is still required)</span>
36
    [%- CASE 'parameters_remaining_permissions' -%]<span>Remaining system parameters permissions</span>
37
    [%- CASE 'parameters_remaining_permissions' -%]<span>Remaining system parameters permissions</span>
37
    [%- CASE 'edit_borrowers' -%]<span>Add, modify and view patron information</span>
38
    [%- CASE 'edit_borrowers' -%]<span>Add, modify and view patron information</span>
38
    [%- CASE 'view_borrower_infos_from_any_libraries' -%]<span>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.</span>
39
    [%- CASE 'view_borrower_infos_from_any_libraries' -%]<span>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.</span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-15 / +16 lines)
Lines 38-59 Link Here
38
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
38
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
39
    </div>
39
    </div>
40
    <div>
40
    <div>
41
        <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
41
        [% UNLESS restricted_to_own_library %]
42
        Select a library :
42
            <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
43
            <select name="branch" id="branch" style="width:20em;">
43
            Select a library :
44
                <option value="*">Standard rules for all libraries</option>
44
                <select name="branch" id="branch" style="width:20em;">
45
                [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
45
                    <option value="*">Standard rules for all libraries</option>
46
            </select>
46
                    [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
47
        </form>
48
        [% IF ( definedbranch ) %]
49
            <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
50
                <label for="tobranch"><strong>Clone these rules to:</strong></label>
51
                <input type="hidden" name="frombranch" value="[% current_branch %]" />
52
                <select name="tobranch" id="tobranch">
53
                    [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
54
                </select>
47
                </select>
55
                <input type="submit" id="clone_rules" value="Clone" />
56
            </form>
48
            </form>
49
            [% IF ( definedbranch ) %]
50
                <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
51
                    <label for="tobranch"><strong>Clone these rules to:</strong></label>
52
                    <input type="hidden" name="frombranch" value="[% current_branch %]" />
53
                    <select name="tobranch" id="tobranch">
54
                        [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
55
                    </select>
56
                    <input type="submit" id="clone_rules" value="Clone" />
57
                </form>
58
            [% END %]
57
        [% END %]
59
        [% END %]
58
60
59
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
61
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
60
- 

Return to bug 15520