From 471d166b4b6a7214d8df6ca8882a8f1a98709634 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 1 Aug 2018 16:12:42 +0200 Subject: [PATCH] SL::Menu: Negierung (!) beim access_string erlauben und Tests hierzu --- SL/Menu.pm | 5 ++--- menus/user/00-erp.yaml | 4 +++- t/menu/parse_access_string.t | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/SL/Menu.pm b/SL/Menu.pm index 0e92cc5b3..42b08de48 100644 --- a/SL/Menu.pm +++ b/SL/Menu.pm @@ -180,7 +180,7 @@ sub parse_access_string { my $access = $node->{access}; - while ($access =~ m/^([a-z_\/]+|\||\&|\(|\)|\s+)/) { + while ($access =~ m/^([a-z_\/]+|\!|\||\&|\(|\)|\s+)/) { my $token = $1; substr($access, 0, length($1)) = ""; @@ -199,7 +199,7 @@ sub parse_access_string { } $cur_ary = $stack[-1]; - } elsif (($token eq "|") || ($token eq "&")) { + } elsif (($token eq "|") || ($token eq "&") || ($token eq "!")) { push @{$cur_ary}, $token; } else { @@ -273,4 +273,3 @@ sub set_access { } 1; - diff --git a/menus/user/00-erp.yaml b/menus/user/00-erp.yaml index 3264c3f4a..d3c006cbb 100644 --- a/menus/user/00-erp.yaml +++ b/menus/user/00-erp.yaml @@ -11,7 +11,9 @@ # ( ) & | are supported. if binary operator is missing the last # operator in same scope is repeated, or "|" if none used in scope # yet. client config entries can be used as rights by prefixing them -# with "client/". If missing, access will be granted. +# with "client/". +# ! is supported to negate the subsequent expression. +# If missing, access will be granted. # # Example: # client/feature_default_enabled | ( feature & system ) diff --git a/t/menu/parse_access_string.t b/t/menu/parse_access_string.t index f1cbd4289..fd6e790ae 100644 --- a/t/menu/parse_access_string.t +++ b/t/menu/parse_access_string.t @@ -57,6 +57,24 @@ ok(!$menu->parse_access_string(\%node), 'parenthesis 2'); $node{access} = 'sales_quotation_edit & client/feature_experimental'; ok($menu->parse_access_string(\%node), 'client'); +$node{access} = '!no_such_right'; +ok($menu->parse_access_string(\%node), 'simple negation 1'); + +$node{access} = '!sales_order_edit'; +ok(!$menu->parse_access_string(\%node), 'simple negation 2'); + +$node{access} = '!!sales_order_edit'; +ok($menu->parse_access_string(\%node), 'double negation'); + +$node{access} = '(no_such_right & sales_order_edit | !(no_such_right & sales_order_edit))'; +ok($menu->parse_access_string(\%node), 'parenthesis with negation 1'); + +$node{access} = '(no_such_right & sales_order_edit | (!no_such_right | !sales_order_edit))'; +ok($menu->parse_access_string(\%node), 'parenthesis with negation 2'); + +$node{access} = 'sales_quotation_edit & !client/feature_experimental'; +ok(!$menu->parse_access_string(\%node), 'client negation'); + done_testing; 1; -- 2.20.1