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

(-)a/C4/Auth.pm (-4 / +8 lines)
Lines 2023-2039 sub get_all_subpermissions { Link Here
2023
2023
2024
=head2 haspermission
2024
=head2 haspermission
2025
2025
2026
  $flags = ($userid, $flagsrequired);
2026
  $flags = ( $userid, $flagsrequired[, { no_inherit => 1 } ] );
2027
2027
2028
C<$userid> the userid of the member
2028
C<$userid> the userid of the member
2029
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2029
C<$flags> is a hashref of required flags like C<$borrower-&lt;{authflags}> 
2030
C<no_inherit>, if true, means that this function will not return true if
2031
$flagsrequired is { module => 'sub_perm' } and the user only has { module => 1 }.
2032
This is useful for *_restricted permissions.
2030
2033
2031
Returns member's flags or 0 if a permission is not met.
2034
Returns member's flags or 0 if a permission is not met.
2032
2035
2033
=cut
2036
=cut
2034
2037
2035
sub haspermission {
2038
sub haspermission {
2036
    my ( $userid, $flagsrequired ) = @_;
2039
    my ( $userid, $flagsrequired, $options ) = @_;
2037
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2040
    my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?");
2038
    $sth->execute($userid);
2041
    $sth->execute($userid);
2039
    my $row = $sth->fetchrow();
2042
    my $row = $sth->fetchrow();
Lines 2044-2050 sub haspermission { Link Here
2044
        $flags->{'superlibrarian'} = 1;
2047
        $flags->{'superlibrarian'} = 1;
2045
    }
2048
    }
2046
2049
2047
    return $flags if $flags->{superlibrarian};
2050
    return $flags if $flags->{superlibrarian} && !$options->{no_inherit};
2048
2051
2049
    foreach my $module ( keys %$flagsrequired ) {
2052
    foreach my $module ( keys %$flagsrequired ) {
2050
        my $subperm = $flagsrequired->{$module};
2053
        my $subperm = $flagsrequired->{$module};
Lines 2053-2059 sub haspermission { Link Here
2053
        } else {
2056
        } else {
2054
            return 0 unless (
2057
            return 0 unless (
2055
                ( defined $flags->{$module} and
2058
                ( defined $flags->{$module} and
2056
                    $flags->{$module} == 1 )
2059
                    $flags->{$module} == 1 and
2060
                    !$options->{no_inherit} )
2057
                or
2061
                or
2058
                ( ref( $flags->{$module} ) and
2062
                ( ref( $flags->{$module} ) and
2059
                    exists $flags->{$module}->{$subperm} and
2063
                    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 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 'modify_holds_priority' -%]<span>Modify holds priority</span>
38
    [%- CASE 'modify_holds_priority' -%]<span>Modify holds priority</span>
38
    [%- CASE 'place_holds' -%]<span>Place holds for patrons</span>
39
    [%- 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 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