|
Lines 7-13
use CGI qw ( -utf8 );
Link Here
|
| 7 |
use Test::MockObject; |
7 |
use Test::MockObject; |
| 8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
| 9 |
use List::MoreUtils qw/all any none/; |
9 |
use List::MoreUtils qw/all any none/; |
| 10 |
use Test::More tests => 18; |
10 |
use Test::More tests => 19; |
| 11 |
use Test::Warn; |
11 |
use Test::Warn; |
| 12 |
use t::lib::Mocks; |
12 |
use t::lib::Mocks; |
| 13 |
use t::lib::TestBuilder; |
13 |
use t::lib::TestBuilder; |
|
Lines 20-26
use Koha::Patrons;
Link Here
|
| 20 |
use Koha::Auth::TwoFactorAuth; |
20 |
use Koha::Auth::TwoFactorAuth; |
| 21 |
|
21 |
|
| 22 |
BEGIN { |
22 |
BEGIN { |
| 23 |
use_ok('C4::Auth', qw( checkauth haspermission track_login_daily checkpw get_template_and_user checkpw_hash )); |
23 |
use_ok( |
|
|
24 |
'C4::Auth', |
| 25 |
qw( checkauth haspermission track_login_daily checkpw get_template_and_user checkpw_hash get_cataloguing_page_permissions ) |
| 26 |
); |
| 24 |
} |
27 |
} |
| 25 |
|
28 |
|
| 26 |
my $schema = Koha::Database->schema; |
29 |
my $schema = Koha::Database->schema; |
|
Lines 1003-1005
subtest 'check_cookie_auth overwriting interface already set' => sub {
Link Here
|
| 1003 |
}; |
1006 |
}; |
| 1004 |
|
1007 |
|
| 1005 |
$schema->storage->txn_rollback; |
1008 |
$schema->storage->txn_rollback; |
| 1006 |
- |
1009 |
|
|
|
1010 |
subtest 'get_cataloguing_page_permissions() tests' => sub { |
| 1011 |
|
| 1012 |
plan tests => 6; |
| 1013 |
|
| 1014 |
$schema->storage->txn_begin; |
| 1015 |
|
| 1016 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 2**2 } } ); # catalogue |
| 1017 |
|
| 1018 |
ok( |
| 1019 |
!C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1020 |
'"catalogue" is not enough to see the cataloguing page' |
| 1021 |
); |
| 1022 |
|
| 1023 |
$builder->build( |
| 1024 |
{ |
| 1025 |
source => 'UserPermission', |
| 1026 |
value => { |
| 1027 |
borrowernumber => $patron->id, |
| 1028 |
module_bit => 24, # stockrotation |
| 1029 |
code => 'manage_rotas', |
| 1030 |
}, |
| 1031 |
} |
| 1032 |
); |
| 1033 |
|
| 1034 |
t::lib::Mocks::mock_preference( 'StockRotation', 1 ); |
| 1035 |
ok( |
| 1036 |
C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1037 |
'"stockrotation => manage_rotas" is enough' |
| 1038 |
); |
| 1039 |
|
| 1040 |
t::lib::Mocks::mock_preference( 'StockRotation', 0 ); |
| 1041 |
ok( |
| 1042 |
!C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1043 |
'"stockrotation => manage_rotas" is not enough when `StockRotation` is disabled' |
| 1044 |
); |
| 1045 |
|
| 1046 |
$builder->build( |
| 1047 |
{ |
| 1048 |
source => 'UserPermission', |
| 1049 |
value => { |
| 1050 |
borrowernumber => $patron->id, |
| 1051 |
module_bit => 13, # tools |
| 1052 |
code => 'manage_staged_marc', |
| 1053 |
}, |
| 1054 |
} |
| 1055 |
); |
| 1056 |
|
| 1057 |
ok( |
| 1058 |
C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1059 |
'Having one of the listed `tools` subperm is enough' |
| 1060 |
); |
| 1061 |
|
| 1062 |
$schema->resultset('UserPermission')->search( { borrowernumber => $patron->id } )->delete; |
| 1063 |
|
| 1064 |
ok( |
| 1065 |
!C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1066 |
'Permission removed, no access' |
| 1067 |
); |
| 1068 |
|
| 1069 |
$builder->build( |
| 1070 |
{ |
| 1071 |
source => 'UserPermission', |
| 1072 |
value => { |
| 1073 |
borrowernumber => $patron->id, |
| 1074 |
module_bit => 9, # editcatalogue |
| 1075 |
code => 'delete_all_items', |
| 1076 |
}, |
| 1077 |
} |
| 1078 |
); |
| 1079 |
|
| 1080 |
ok( |
| 1081 |
C4::Auth::haspermission( $patron->userid, get_cataloguing_page_permissions() ), |
| 1082 |
'Having any `editcatalogue` subperm is enough' |
| 1083 |
); |
| 1084 |
|
| 1085 |
$schema->storage->txn_rollback; |
| 1086 |
}; |