Lines 20-26
Link Here
|
20 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
20 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
21 |
|
21 |
|
22 |
use Modern::Perl; |
22 |
use Modern::Perl; |
23 |
use Test::More tests => 13; |
23 |
use Test::More tests => 3; |
24 |
|
24 |
|
25 |
use Koha::Database; |
25 |
use Koha::Database; |
26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
Lines 31-108
$schema->storage->txn_begin;
Link Here
|
31 |
|
31 |
|
32 |
# Adding two borrowers and granular permissions for the second borrower |
32 |
# Adding two borrowers and granular permissions for the second borrower |
33 |
my $builder = t::lib::TestBuilder->new(); |
33 |
my $builder = t::lib::TestBuilder->new(); |
34 |
my $borr1 = $builder->build({ |
34 |
my $borr1 = $builder->build( |
35 |
source => 'Borrower', |
35 |
{ |
36 |
value => { |
36 |
source => 'Borrower', |
37 |
surname => 'Superlib', |
37 |
value => { |
38 |
flags => 1, |
38 |
surname => 'Superlib', |
39 |
}, |
39 |
flags => 1, |
40 |
}); |
40 |
}, |
41 |
my $borr2 = $builder->build({ |
41 |
} |
42 |
source => 'Borrower', |
42 |
); |
43 |
value => { |
43 |
my $borr2 = $builder->build( |
44 |
surname => 'Bor2', |
44 |
{ |
45 |
flags => 2 + 4 + 2**11, # circulate, catalogue, acquisition |
45 |
source => 'Borrower', |
46 |
}, |
46 |
value => { |
47 |
}); |
47 |
surname => 'Bor2', |
48 |
$builder->build({ |
48 |
flags => 2 + 4 + 2**11, # circulate, catalogue, acquisition |
49 |
source => 'UserPermission', |
49 |
}, |
50 |
value => { |
50 |
} |
51 |
borrowernumber => $borr2->{borrowernumber}, |
51 |
); |
52 |
module_bit => 13, # tools |
52 |
$builder->build( |
53 |
code => 'upload_local_cover_images', |
53 |
{ |
54 |
}, |
54 |
source => 'UserPermission', |
55 |
}); |
55 |
value => { |
56 |
$builder->build({ |
56 |
borrowernumber => $borr2->{borrowernumber}, |
57 |
source => 'UserPermission', |
57 |
module_bit => 13, # tools |
58 |
value => { |
58 |
code => 'upload_local_cover_images', |
59 |
borrowernumber => $borr2->{borrowernumber}, |
59 |
}, |
60 |
module_bit => 13, # tools |
60 |
} |
61 |
code => 'batch_upload_patron_images', |
61 |
); |
62 |
}, |
62 |
$builder->build( |
63 |
}); |
63 |
{ |
64 |
|
64 |
source => 'UserPermission', |
65 |
# Check top level permission for superlibrarian |
65 |
value => { |
66 |
my $r = haspermission( $borr1->{userid}, |
66 |
borrowernumber => $borr2->{borrowernumber}, |
67 |
{ circulate => 1, editcatalogue => 1 } ); |
67 |
module_bit => 13, # tools |
68 |
is( ref($r), 'HASH', 'Superlibrarian/circulate' ); |
68 |
code => 'batch_upload_patron_images', |
69 |
|
69 |
}, |
70 |
# Check specific top level permission(s) for borr2 |
70 |
} |
71 |
$r = haspermission( $borr2->{userid}, |
71 |
); |
72 |
{ circulate => 1, catalogue => 1 } ); |
72 |
|
73 |
is( ref($r), 'HASH', 'Borrower2/circulate' ); |
73 |
subtest 'scalar top level tests' => sub { |
74 |
$r = haspermission( $borr2->{userid}, { updatecharges => 1 } ); |
74 |
|
75 |
is( $r, 0, 'Borrower2/updatecharges should fail' ); |
75 |
plan tests => 3; |
76 |
|
76 |
|
77 |
# Check granular permission with 1: means all subpermissions |
77 |
# Check top level permission for superlibrarian |
78 |
$r = haspermission( $borr1->{userid}, { tools => 1 } ); |
78 |
my $r = haspermission( $borr1->{userid}, 'circulate' ); |
79 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular all' ); |
79 |
is( ref($r), 'HASH', 'Superlibrarian/circulate' ); |
80 |
$r = haspermission( $borr2->{userid}, { tools => 1 } ); |
80 |
|
81 |
is( $r, 0, 'Borrower2/tools granular all should fail' ); |
81 |
# Check specific top level permission(s) for borr2 |
82 |
|
82 |
$r = haspermission( $borr2->{userid}, 'circulate' ); |
83 |
# Check granular permission with *: means at least one subpermission |
83 |
is( ref($r), 'HASH', 'Borrower2/circulate' ); |
84 |
$r = haspermission( $borr1->{userid}, { tools => '*' } ); |
84 |
$r = haspermission( $borr2->{userid}, 'updatecharges' ); |
85 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular *' ); |
85 |
is( $r, 0, 'Borrower2/updatecharges should fail' ); |
86 |
$r = haspermission( $borr2->{userid}, { acquisition => '*' } ); |
86 |
}; |
87 |
is( ref($r), 'HASH', 'Borrower2/acq granular *' ); |
87 |
|
88 |
$r = haspermission( $borr2->{userid}, { tools => '*' } ); |
88 |
subtest 'hashref top level AND tests' => sub { |
89 |
is( ref($r), 'HASH', 'Borrower2/tools granular *' ); |
89 |
|
90 |
$r = haspermission( $borr2->{userid}, { serials => '*' } ); |
90 |
plan tests => 15; |
91 |
is( $r, 0, 'Borrower2/serials granular * should fail' ); |
91 |
|
92 |
|
92 |
# Check top level permission for superlibrarian |
93 |
# Check granular permission with one or more specific subperms |
93 |
my $r = |
94 |
$r = haspermission( $borr1->{userid}, { tools => 'edit_news' } ); |
94 |
haspermission( $borr1->{userid}, { circulate => 1 } ); |
95 |
is( ref($r), 'HASH', 'Superlibrarian/tools edit_news' ); |
95 |
is( ref($r), 'HASH', 'Superlibrarian/circulate' ); |
96 |
$r = haspermission( $borr2->{userid}, { acquisition => 'budget_manage' } ); |
96 |
|
97 |
is( ref($r), 'HASH', 'Borrower2/acq budget_manage' ); |
97 |
# Check specific top level permission(s) for borr2 |
98 |
$r = haspermission( $borr2->{userid}, |
98 |
$r = haspermission( $borr2->{userid}, { circulate => 1, catalogue => 1 } ); |
99 |
{ acquisition => 'budget_manage', tools => 'edit_news' } ); |
99 |
is( ref($r), 'HASH', 'Borrower2/circulate' ); |
100 |
is( $r, 0, 'Borrower2/two granular should fail' ); |
100 |
$r = haspermission( $borr2->{userid}, { updatecharges => 1 } ); |
101 |
$r = haspermission( $borr2->{userid}, { |
101 |
is( $r, 0, 'Borrower2/updatecharges should fail' ); |
102 |
tools => 'upload_local_cover_images', |
102 |
|
103 |
tools => 'batch_upload_patron_images', |
103 |
# Check granular permission with 1: means all subpermissions |
104 |
}); |
104 |
$r = haspermission( $borr1->{userid}, { tools => 1 } ); |
105 |
is( ref($r), 'HASH', 'Borrower2/tools granular two upload subperms' ); |
105 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular all' ); |
106 |
|
106 |
$r = haspermission( $borr2->{userid}, { tools => 1 } ); |
107 |
# End |
107 |
is( $r, 0, 'Borrower2/tools granular all should fail' ); |
|
|
108 |
|
109 |
# Check granular permission with *: means at least one subpermission |
110 |
$r = haspermission( $borr1->{userid}, { tools => '*' } ); |
111 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular *' ); |
112 |
$r = haspermission( $borr2->{userid}, { acquisition => '*' } ); |
113 |
is( ref($r), 'HASH', 'Borrower2/acq granular *' ); |
114 |
$r = haspermission( $borr2->{userid}, { tools => '*' } ); |
115 |
is( ref($r), 'HASH', 'Borrower2/tools granular *' ); |
116 |
$r = haspermission( $borr2->{userid}, { serials => '*' } ); |
117 |
is( $r, 0, 'Borrower2/serials granular * should fail' ); |
118 |
|
119 |
# Check granular permission with one or more specific subperms |
120 |
$r = haspermission( $borr1->{userid}, { tools => 'edit_news' } ); |
121 |
is( ref($r), 'HASH', 'Superlibrarian/tools edit_news' ); |
122 |
$r = haspermission( $borr2->{userid}, { acquisition => 'budget_manage' } ); |
123 |
is( ref($r), 'HASH', 'Borrower2/acq budget_manage' ); |
124 |
$r = haspermission( $borr2->{userid}, |
125 |
{ acquisition => 'budget_manage', tools => 'edit_news' } ); |
126 |
is( $r, 0, 'Borrower2 (/acquisition|budget_manage AND /tools|edit_news) should fail' ); |
127 |
$r = haspermission( |
128 |
$borr2->{userid}, |
129 |
{ |
130 |
tools => { |
131 |
'upload_local_cover_images' => 1, |
132 |
'batch_upload_patron_images' => 1 |
133 |
}, |
134 |
} |
135 |
); |
136 |
is( ref($r), 'HASH', 'Borrower2 (/tools|upload_local_cover_image AND /tools|batch_upload_patron_images) granular' ); |
137 |
$r = haspermission( |
138 |
$borr2->{userid}, |
139 |
{ |
140 |
tools => { |
141 |
'upload_local_cover_images' => 1, |
142 |
'edit_news' => 1 |
143 |
}, |
144 |
} |
145 |
); |
146 |
is( $r, 0, 'Borrower2 (/tools|upload_local_cover_image AND /tools|edit_news) granular' ); |
147 |
$r = haspermission( |
148 |
$borr2->{userid}, |
149 |
{ |
150 |
tools => [ 'upload_local_cover_images', 'edit_news'], |
151 |
} |
152 |
); |
153 |
is( ref($r), 'HASH', 'Borrower2 (/tools|upload_local_cover_image OR /tools|edit_news) granular' ); |
154 |
}; |
155 |
|
156 |
subtest 'arrayref top level OR tests' => sub { |
157 |
|
158 |
plan tests => 13; |
159 |
|
160 |
# Check top level permission for superlibrarian |
161 |
my $r = |
162 |
haspermission( $borr1->{userid}, [ 'circulate', 'editcatalogue' ] ); |
163 |
is( ref($r), 'HASH', 'Superlibrarian/circulate' ); |
164 |
|
165 |
# Check specific top level permission(s) for borr2 |
166 |
$r = haspermission( $borr2->{userid}, [ 'circulate', 'updatecharges' ] ); |
167 |
is( ref($r), 'HASH', 'Borrower2/circulate OR Borrower2/updatecharges' ); |
168 |
$r = haspermission( $borr2->{userid}, ['updatecharges', 'serials' ] ); |
169 |
is( $r, 0, 'Borrower2/updatecharges OR Borrower2/serials should fail' ); |
170 |
|
171 |
# Check granular permission with 1: means all subpermissions |
172 |
$r = haspermission( $borr1->{userid}, [ 'tools' ] ); |
173 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular all' ); |
174 |
$r = haspermission( $borr2->{userid}, [ 'tools' ] ); |
175 |
is( $r, 0, 'Borrower2/tools granular all should fail' ); |
176 |
|
177 |
# Check granular permission with *: means at least one subpermission |
178 |
$r = haspermission( $borr1->{userid}, [ { tools => '*' } ] ); |
179 |
is( ref($r), 'HASH', 'Superlibrarian/tools granular *' ); |
180 |
$r = haspermission( $borr2->{userid}, [ { acquisition => '*' } ] ); |
181 |
is( ref($r), 'HASH', 'Borrower2/acq granular *' ); |
182 |
$r = haspermission( $borr2->{userid}, [ { tools => '*' } ] ); |
183 |
is( ref($r), 'HASH', 'Borrower2/tools granular *' ); |
184 |
$r = haspermission( $borr2->{userid}, [ { serials => '*' } ] ); |
185 |
is( $r, 0, 'Borrower2/serials granular * should fail' ); |
186 |
|
187 |
# Check granular permission with one or more specific subperms |
188 |
$r = haspermission( $borr1->{userid}, [ { tools => 'edit_news' } ] ); |
189 |
is( ref($r), 'HASH', 'Superlibrarian/tools edit_news' ); |
190 |
$r = |
191 |
haspermission( $borr2->{userid}, [ { acquisition => 'budget_manage' } ] ); |
192 |
is( ref($r), 'HASH', 'Borrower2/acq budget_manage' ); |
193 |
$r = haspermission( $borr2->{userid}, |
194 |
[ { acquisition => 'budget_manage'}, { tools => 'edit_news' } ] ); |
195 |
is( ref($r), 'HASH', 'Borrower2/two granular OR should pass' ); |
196 |
$r = haspermission( |
197 |
$borr2->{userid}, |
198 |
[ |
199 |
{ tools => ['upload_local_cover_images'] }, |
200 |
{ tools => ['edit_news'] } |
201 |
] |
202 |
); |
203 |
is( ref($r), 'HASH', 'Borrower2/tools granular OR subperms' ); |
204 |
}; |
205 |
|
108 |
$schema->storage->txn_rollback; |
206 |
$schema->storage->txn_rollback; |
109 |
- |
|
|