Revision 78b23538
Von Bernd Bleßmann vor mehr als 6 Jahren hinzugefügt
SL/Auth.pm | ||
---|---|---|
1077 | 1077 |
|
1078 | 1078 |
my $value = 0; |
1079 | 1079 |
my $action = '|'; |
1080 |
my $negate = 0; |
|
1080 | 1081 |
|
1081 | 1082 |
foreach my $el (@{$ary}) { |
1082 | 1083 |
if (ref $el eq "ARRAY") { |
1084 |
my $val = evaluate_rights_ary($el); |
|
1085 |
$val = !$val if $negate; |
|
1086 |
$negate = 0; |
|
1083 | 1087 |
if ($action eq '|') { |
1084 |
$value |= evaluate_rights_ary($el);
|
|
1088 |
$value |= $val;
|
|
1085 | 1089 |
} else { |
1086 |
$value &= evaluate_rights_ary($el);
|
|
1090 |
$value &= $val;
|
|
1087 | 1091 |
} |
1088 | 1092 |
|
1089 | 1093 |
} elsif (($el eq '&') || ($el eq '|')) { |
1090 | 1094 |
$action = $el; |
1091 | 1095 |
|
1096 |
} elsif ($el eq '!') { |
|
1097 |
$negate = !$negate; |
|
1098 |
|
|
1092 | 1099 |
} elsif ($action eq '|') { |
1093 |
$value |= $el; |
|
1100 |
my $val = $el; |
|
1101 |
$val = !$val if $negate; |
|
1102 |
$negate = 0; |
|
1103 |
$value |= $val; |
|
1094 | 1104 |
|
1095 | 1105 |
} else { |
1096 |
$value &= $el; |
|
1106 |
my $val = $el; |
|
1107 |
$val = !$val if $negate; |
|
1108 |
$negate = 0; |
|
1109 |
$value &= $val; |
|
1097 | 1110 |
|
1098 | 1111 |
} |
1099 | 1112 |
} |
t/auth/evaluate_rights_ary.t | ||
---|---|---|
1 |
use strict; |
|
2 |
|
|
3 |
use Test::More; |
|
4 |
|
|
5 |
use lib 't'; |
|
6 |
use Support::TestSetup; |
|
7 |
|
|
8 |
Support::TestSetup::login(); |
|
9 |
|
|
10 |
use_ok 'SL::Auth'; |
|
11 |
|
|
12 |
ok( SL::Auth::evaluate_rights_ary(['1']), 'simple: right'); |
|
13 |
ok(!SL::Auth::evaluate_rights_ary(['0']), 'simple: no right'); |
|
14 |
ok( SL::Auth::evaluate_rights_ary(['1', '|', 0]), 'simple: or'); |
|
15 |
ok( SL::Auth::evaluate_rights_ary(['0', '|', '1']), 'simple: or 2'); |
|
16 |
ok(!SL::Auth::evaluate_rights_ary(['1', '&', '0']), 'simple: and'); |
|
17 |
ok(!SL::Auth::evaluate_rights_ary(['0', '&', '1']), 'simple: and 2'); |
|
18 |
ok( SL::Auth::evaluate_rights_ary(['1', '&', '1']), 'simple: and 3'); |
|
19 |
ok(!SL::Auth::evaluate_rights_ary(['!', '1']), 'simple: not'); |
|
20 |
ok( SL::Auth::evaluate_rights_ary(['!', '0']), 'simple: not 2'); |
|
21 |
ok(!SL::Auth::evaluate_rights_ary(['!', '!', '0']), 'simple: double not'); |
|
22 |
ok( SL::Auth::evaluate_rights_ary(['!', ['0']]), 'not 1'); |
|
23 |
ok(!SL::Auth::evaluate_rights_ary(['!', ['1']]), 'not 2'); |
|
24 |
ok( SL::Auth::evaluate_rights_ary(['!', '!', ['1']]), 'double not'); |
|
25 |
ok( SL::Auth::evaluate_rights_ary([ '!', ['!', ['1', '&', '1'], '&', '!', '!', ['1', '|', '!', '1']] ]), 'something more coplex'); |
|
26 |
|
|
27 |
done_testing; |
|
28 |
|
|
29 |
1; |
Auch abrufbar als: Unified diff
SL::Auth: evaluate_rights_ary: Negierung (!) ermöglichen