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-<{authflags}> |
2029 |
C<$flags> is a hashref of required flags like C<$borrower-<{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 |