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

(-)a/C4/Auth.pm (-4 / +8 lines)
Lines 2031-2047 sub get_all_subpermissions { Link Here
2031
2031
2032
=head2 haspermission
2032
=head2 haspermission
2033
2033
2034
  $flags = ($userid, $flagsrequired);
2034
  $flags = ( $userid, $flagsrequired[, { no_inherit => 1 } ] );
2035
2035
2036
C<$userid> the userid of the member
2036
C<$userid> the userid of the member
2037
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2037
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2038
C<no_inherit>, if true, means that this function will not return true if
2039
$flagsrequired is { module => 'sub_perm' } and the user only has { module => 1 }.
2040
This is useful for *_restricted permissions.
2038
2041
2039
Returns member's flags or 0 if a permission is not met.
2042
Returns member's flags or 0 if a permission is not met.
2040
2043
2041
=cut
2044
=cut
2042
2045
2043
sub haspermission {
2046
sub haspermission {
2044
    my ( $userid, $flagsrequired ) = @_;
2047
    my ( $userid, $flagsrequired, $options ) = @_;
2045
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2048
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2046
    $sth->execute($userid);
2049
    $sth->execute($userid);
2047
    my $row = $sth->fetchrow();
2050
    my $row = $sth->fetchrow();
Lines 2057-2063 sub haspermission { Link Here
2057
        $flags->{'superlibrarian'} = 1;
2060
        $flags->{'superlibrarian'} = 1;
2058
    }
2061
    }
2059
2062
2060
    return $flags if $flags->{superlibrarian};
2063
    return $flags if $flags->{superlibrarian} && !$options->{no_inherit};
2061
2064
2062
    foreach my $module ( keys %$flagsrequired ) {
2065
    foreach my $module ( keys %$flagsrequired ) {
2063
        my $subperm = $flagsrequired->{$module};
2066
        my $subperm = $flagsrequired->{$module};
Lines 2066-2072 sub haspermission { Link Here
2066
        } else {
2069
        } else {
2067
            return 0 unless (
2070
            return 0 unless (
2068
                ( defined $flags->{$module} and
2071
                ( defined $flags->{$module} and
2069
                    $flags->{$module} == 1 )
2072
                    $flags->{$module} == 1 and
2073
                    !$options->{no_inherit} )
2070
                or
2074
                or
2071
                ( ref( $flags->{$module} ) and
2075
                ( ref( $flags->{$module} ) and
2072
                    exists $flags->{$module}->{$subperm} and
2076
                    exists $flags->{$module}->{$subperm} and
(-)a/admin/smart-rules.pl (+7 lines)
Lines 34-39 use Koha::RefundLostItemFeeRule; Link Here
34
use Koha::RefundLostItemFeeRules;
34
use Koha::RefundLostItemFeeRules;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
37
use Koha::Patrons;
37
38
38
my $input = CGI->new;
39
my $input = CGI->new;
39
my $dbh = C4::Context->dbh;
40
my $dbh = C4::Context->dbh;
Lines 60-65 unless ( $branch ) { Link Here
60
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
61
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
61
    }
62
    }
62
}
63
}
64
65
my $uid = Koha::Patrons->find( $loggedinuser )->userid;
66
my $restricted_to_own_library = $uid && haspermission( $uid, { parameters => 'manage_circ_rules_restricted' }, { no_inherit => 1 } );
67
$template->param( restricted_to_own_library => $restricted_to_own_library );
68
$branch = C4::Context::mybranch() if $restricted_to_own_library;
69
63
$branch = '*' if $branch eq 'NO_LIBRARY_SET';
70
$branch = '*' if $branch eq 'NO_LIBRARY_SET';
64
71
65
my $op = $input->param('op') || q{};
72
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 31-37 Link Here
31
    [%- CASE 'overdues_report' -%]<span>Execute overdue items report</span>
31
    [%- CASE 'overdues_report' -%]<span>Execute overdue items report</span>
32
    [%- CASE 'override_renewals' -%]<span>Override blocked renewals</span>
32
    [%- CASE 'override_renewals' -%]<span>Override blocked renewals</span>
33
    [%- CASE 'self_checkout' -%]<span>Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID</span>
33
    [%- CASE 'self_checkout' -%]<span>Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID</span>
34
    [%- CASE 'manage_circ_rules' -%]<span>manage circulation rules</span>
34
    [%- CASE 'manage_circ_rules' -%]<span>Manage circulation rules</span>
35
    [%- 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>
35
    [%- CASE 'parameters_remaining_permissions' -%]<span>Remaining system parameters permissions</span>
36
    [%- CASE 'parameters_remaining_permissions' -%]<span>Remaining system parameters permissions</span>
36
    [%- CASE 'modify_holds_priority' -%]<span>Modify holds priority</span>
37
    [%- CASE 'modify_holds_priority' -%]<span>Modify holds priority</span>
37
    [%- CASE 'place_holds' -%]<span>Place holds for patrons</span>
38
    [%- CASE 'place_holds' -%]<span>Place holds for patrons</span>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-15 / +16 lines)
Lines 142-163 $(document).ready(function() { Link Here
142
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
142
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
143
    </div>
143
    </div>
144
    <div>
144
    <div>
145
        <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
145
        [% UNLESS restricted_to_own_library %]
146
        Select a library :
146
            <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
147
            <select name="branch" id="branch" style="width:20em;">
147
            Select a library :
148
                <option value="*">Standard rules for all libraries</option>
148
                <select name="branch" id="branch" style="width:20em;">
149
                [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
149
                    <option value="*">Standard rules for all libraries</option>
150
            </select>
150
                    [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
151
        </form>
152
        [% IF ( definedbranch ) %]
153
            <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
154
                <label for="tobranch"><strong>Clone these rules to:</strong></label>
155
                <input type="hidden" name="frombranch" value="[% current_branch %]" />
156
                <select name="tobranch" id="tobranch">
157
                    [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
158
                </select>
151
                </select>
159
                <input type="submit" value="Clone" />
160
            </form>
152
            </form>
153
            [% IF ( definedbranch ) %]
154
                <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
155
                    <label for="tobranch"><strong>Clone these rules to:</strong></label>
156
                    <input type="hidden" name="frombranch" value="[% current_branch %]" />
157
                    <select name="tobranch" id="tobranch">
158
                        [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
159
                    </select>
160
                    <input type="submit" value="Clone" />
161
                </form>
162
            [% END %]
161
        [% END %]
163
        [% END %]
162
164
163
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
165
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
164
- 

Return to bug 15520