|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 4; |
21 |
use Test::More tests => 5; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
|
23 |
|
| 24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
|
Lines 27-32
use t::lib::Mocks;
Link Here
|
| 27 |
use Koha::Items; |
27 |
use Koha::Items; |
| 28 |
use Koha::Old::Items; |
28 |
use Koha::Old::Items; |
| 29 |
use Koha::Database; |
29 |
use Koha::Database; |
|
|
30 |
use Koha::Library::Groups; |
| 30 |
|
31 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
| 32 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 162-169
subtest 'restore() tests' => sub {
Link Here
|
| 162 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
163 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 163 |
my $unauth_userid = $patron->userid; |
164 |
my $unauth_userid = $patron->userid; |
| 164 |
|
165 |
|
| 165 |
my $item = $builder->build_sample_item( { barcode => 'TEST_RESTORE_ITEM' } ); |
166 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 166 |
my $item_id = $item->itemnumber; |
167 |
$librarian->branchcode( $library->branchcode )->store; |
|
|
168 |
|
| 169 |
my $item = $builder->build_sample_item( { barcode => 'TEST_RESTORE_ITEM', homebranch => $library->branchcode } ); |
| 170 |
my $item_id = $item->itemnumber; |
| 167 |
my $item_data = $item->unblessed; |
171 |
my $item_data = $item->unblessed; |
| 168 |
my $deleted_item = Koha::Old::Item->new($item_data)->store; |
172 |
my $deleted_item = Koha::Old::Item->new($item_data)->store; |
| 169 |
$item->delete; |
173 |
$item->delete; |
|
Lines 183-189
subtest 'restore() tests' => sub {
Link Here
|
| 183 |
|
187 |
|
| 184 |
$t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404); |
188 |
$t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404); |
| 185 |
|
189 |
|
| 186 |
my $item_without_biblio = $builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO' } ); |
190 |
my $item_without_biblio = |
|
|
191 |
$builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO', homebranch => $library->branchcode } ); |
| 187 |
my $orphan_item_id = $item_without_biblio->itemnumber; |
192 |
my $orphan_item_id = $item_without_biblio->itemnumber; |
| 188 |
my $orphan_biblio_id = $item_without_biblio->biblionumber; |
193 |
my $orphan_biblio_id = $item_without_biblio->biblionumber; |
| 189 |
my $orphan_item_data = $item_without_biblio->unblessed; |
194 |
my $orphan_item_data = $item_without_biblio->unblessed; |
|
Lines 196-198
subtest 'restore() tests' => sub {
Link Here
|
| 196 |
|
201 |
|
| 197 |
$schema->storage->txn_rollback; |
202 |
$schema->storage->txn_rollback; |
| 198 |
}; |
203 |
}; |
| 199 |
- |
204 |
|
|
|
205 |
subtest 'restore() with library group permissions tests' => sub { |
| 206 |
|
| 207 |
plan tests => 7; |
| 208 |
|
| 209 |
$schema->storage->txn_begin; |
| 210 |
|
| 211 |
my $librarian = $builder->build_object( |
| 212 |
{ |
| 213 |
class => 'Koha::Patrons', |
| 214 |
value => { flags => 0 } |
| 215 |
} |
| 216 |
); |
| 217 |
my $password = 'thePassword123'; |
| 218 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 219 |
my $userid = $librarian->userid; |
| 220 |
|
| 221 |
$builder->build( |
| 222 |
{ |
| 223 |
source => 'UserPermission', |
| 224 |
value => { |
| 225 |
borrowernumber => $librarian->borrowernumber, |
| 226 |
module_bit => 13, |
| 227 |
code => 'records_restore', |
| 228 |
} |
| 229 |
} |
| 230 |
); |
| 231 |
|
| 232 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 233 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 234 |
|
| 235 |
$librarian->branchcode( $library1->branchcode )->store; |
| 236 |
|
| 237 |
my $library_group = Koha::Library::Group->new( { title => 'Test Group', ft_limit_item_editing => 1 } )->store; |
| 238 |
Koha::Library::Group->new( |
| 239 |
{ |
| 240 |
parent_id => $library_group->id, |
| 241 |
branchcode => $library1->branchcode, |
| 242 |
} |
| 243 |
)->store; |
| 244 |
|
| 245 |
my $item_allowed = $builder->build_sample_item( { homebranch => $library1->branchcode } ); |
| 246 |
my $item_restricted = $builder->build_sample_item( { homebranch => $library2->branchcode } ); |
| 247 |
|
| 248 |
my $item_allowed_id = $item_allowed->itemnumber; |
| 249 |
my $item_restricted_id = $item_restricted->itemnumber; |
| 250 |
|
| 251 |
my $item_allowed_data = $item_allowed->unblessed; |
| 252 |
my $item_restricted_data = $item_restricted->unblessed; |
| 253 |
|
| 254 |
my $deleted_item_allowed = Koha::Old::Item->new($item_allowed_data)->store; |
| 255 |
my $deleted_item_restricted = Koha::Old::Item->new($item_restricted_data)->store; |
| 256 |
|
| 257 |
$item_allowed->delete; |
| 258 |
$item_restricted->delete; |
| 259 |
|
| 260 |
$t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_allowed_id")->status_is(200); |
| 261 |
|
| 262 |
my $restored_item = Koha::Items->find($item_allowed_id); |
| 263 |
ok( $restored_item, 'Item from allowed library restored' ); |
| 264 |
|
| 265 |
$t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_restricted_id")->status_is(403) |
| 266 |
->json_is( '/error' => 'You do not have permission to restore items from this library.' ); |
| 267 |
|
| 268 |
my $not_restored = Koha::Items->find($item_restricted_id); |
| 269 |
is( $not_restored, undef, 'Item from restricted library not restored' ); |
| 270 |
|
| 271 |
$schema->storage->txn_rollback; |
| 272 |
}; |