Bug 20473: Whitespace
[koha.git] / Koha / Auth / Permissions.pm
1 package Koha::Auth::Permissions;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use C4::Auth qw//;
21
22 =head1 NAME
23
24 Koha::Auth::Permissions - Class for setting up CAN_user_* permissions
25
26 =head1 SYNOPSIS
27
28 =head2 METHODS
29
30 =head3 get_authz_from_flags
31
32 =cut
33
34 sub get_authz_from_flags {
35     my ($class,$args) = @_;
36     my $flags = $args->{flags};
37     my $authz;
38     my $all_perms = C4::Auth::get_all_subpermissions();
39     if ($flags && $all_perms){
40         foreach my $module ( keys %$all_perms ) {
41             if (
42                 ( $flags->{superlibrarian} == 1 ) ||
43                 ( defined($flags->{$module}) && $flags->{$module} == 1 )
44             ) {
45                 foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
46                     $authz->{ "CAN_user_${module}_${subperm}" } = 1;
47                 }
48             }
49             elsif ( ref( $flags->{$module} ) ){
50                 foreach my $subperm ( keys %{ $flags->{$module} } ) {
51                     $authz->{ "CAN_user_${module}_${subperm}" } = 1;
52                 }
53             }
54         }
55         foreach my $module ( keys %$flags ) {
56             if (
57                 ( $flags->{superlibrarian} == 1 ) ||
58                 ( $flags->{$module} == 1 ) ||
59                 ( ref( $flags->{$module} ) )
60             ) {
61                 $authz->{ "CAN_user_$module" } = 1;
62             }
63         }
64     }
65     return $authz;
66 }
67
68
69 1;