diff --git a/C4/Auth.pm b/C4/Auth.pm index 44af94f33d..a8c21740f0 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2262,6 +2262,7 @@ sub get_cataloguing_page_permissions { $flagsrequired = { 'a_flag => 1, 'b_flag' => 1 }; # a_flag AND b_flag must be satisfied $flagsrequired = { 'a_flag' => 'sub_a' }; # sub_a of a_flag must be satisfied $flagsrequired = { 'a_flag' => [ 'sub_a, 'sub_b' ] }; # sub_a OR sub_b of a_flag must be satisfied + $flagsrequired = { 'a_flag' => { 'sub_a' => 1, 'sub_b' => 1 } }; # sub_a AND sub_b of a_flag must be satisfied $flags = ($userid, $flagsrequired); diff --git a/t/db_dependent/Auth/haspermission.t b/t/db_dependent/Auth/haspermission.t index b487358461..6cbb044561 100755 --- a/t/db_dependent/Auth/haspermission.t +++ b/t/db_dependent/Auth/haspermission.t @@ -20,7 +20,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; use Koha::Database; @@ -238,3 +238,46 @@ subtest 'arrayref top level OR tests' => sub { }; $schema->storage->txn_rollback; + +subtest 'AND on subpermissions' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); + + $builder->build( + { + source => 'UserPermission', + value => { + borrowernumber => $patron->id, + module_bit => 9, # editcatalogue + code => 'edit_catalogue', + }, + } + ); + + my $r = haspermission( $patron->userid, { editcatalogue => { edit_catalogue => 1, advanced_editor => 1 } } ); + is( $r, 0, "The user only has 'edit_catalogue' permissions, 0 returned" ); + + $builder->build( + { + source => 'UserPermission', + value => { + borrowernumber => $patron->id, + module_bit => 9, # editcatalogue + code => 'advanced_editor', + }, + } + ); + + $r = haspermission( $patron->userid, { editcatalogue => { edit_catalogue => 1, advanced_editor => 1 } } ); + + ok( + $r->{editcatalogue}->{edit_catalogue} && $r->{editcatalogue}->{advanced_editor}, + "The patron has 'edit_catalogue' and 'advanced_editor', both returned" + ); + + $schema->storage->txn_rollback; +};