View | Details | Raw Unified | Return to bug 23473
Collapse All | Expand All

(-)a/Koha/Patrons/Import.pm (-1 / +1 lines)
Lines 303-309 sub import_patrons { Link Here
303
                    );
303
                    );
304
                }
304
                }
305
            }
305
            }
306
            if ($overwrite_passwords && defined $borrower{password} && $borrower{password} ne ''){
306
            if ($patron->category->category_type ne 'S' && $overwrite_passwords && defined $borrower{password} && $borrower{password} ne ''){
307
                try {
307
                try {
308
                    $patron->set_password({ password => $borrower{password} });
308
                    $patron->set_password({ password => $borrower{password} });
309
                }
309
                }
(-)a/t/db_dependent/Koha/Patrons/Import.t (-3 / +17 lines)
Lines 435-441 subtest 'test_import_with_cardnumber_0' => sub { Link Here
435
};
435
};
436
436
437
subtest 'test_import_with_password_overwrite' => sub {
437
subtest 'test_import_with_password_overwrite' => sub {
438
    plan tests => 6;
438
    plan tests => 8;
439
439
440
    #Remove possible existing user to avoid clashes
440
    #Remove possible existing user to avoid clashes
441
    my $ernest = Koha::Patrons->find({ userid => 'ErnestP' });
441
    my $ernest = Koha::Patrons->find({ userid => 'ErnestP' });
Lines 443-454 subtest 'test_import_with_password_overwrite' => sub { Link Here
443
443
444
    #Setup our info
444
    #Setup our info
445
    my $branchcode = $builder->build({ source => "Branch"})->{branchcode};
445
    my $branchcode = $builder->build({ source => "Branch"})->{branchcode};
446
    my $categorycode = $builder->build({ source => "Category"})->{categorycode};
446
    my $categorycode = $builder->build({ source => "Category", value => { category_type => 'A'  } })->{categorycode};
447
    my $staff_categorycode = $builder->build({ source => "Category", value => { category_type => 'S'  } })->{categorycode};
447
    my $csv_headers  = 'surname,userid,branchcode,categorycode,password';
448
    my $csv_headers  = 'surname,userid,branchcode,categorycode,password';
448
    my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest1";
449
    my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest1";
449
    my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1";
450
    my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1";
450
    my $csv_blank_password = "Worel,ErnestP,$branchcode,$categorycode,";
451
    my $csv_blank_password = "Worel,ErnestP,$branchcode,$categorycode,";
451
    my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled
452
    my $defaults = { cardnumber => "" }; #currently all the defaults come as "" if not filled
453
    my $csv_staff_password_change = "Worrell,ErnestP,$branchcode,$staff_categorycode,Vern1";
452
454
453
    #Make the test files for importing
455
    #Make the test files for importing
454
    my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_password);
456
    my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_password);
Lines 462-467 subtest 'test_import_with_password_overwrite' => sub { Link Here
462
    open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!";
464
    open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!";
463
    my $params_3 = { file => $handle_3, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1};
465
    my $params_3 = { file => $handle_3, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1};
464
466
467
    my $filename_4 = make_csv($temp_dir, $csv_headers, $csv_staff_password_change);
468
    open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!";
469
    my $params_4 = { file => $handle_4, matchpoint => 'userid', overwrite_passwords => 1, overwrite_cardnumber => 1};
470
465
471
466
    my $result = $patrons_import->import_patrons($params_1, $defaults);
472
    my $result = $patrons_import->import_patrons($params_1, $defaults);
467
    like($result->{feedback}->[1]->{value}, qr/^Worrell \/ \d+/, 'First borrower imported as expected');
473
    like($result->{feedback}->[1]->{value}, qr/^Worrell \/ \d+/, 'First borrower imported as expected');
Lines 484-489 subtest 'test_import_with_password_overwrite' => sub { Link Here
484
    is($ernest->surname,'Worel',"Patron is overwritten, surname changed");
490
    is($ernest->surname,'Worel',"Patron is overwritten, surname changed");
485
    is($ernest->password,$orig_pass,"Patron was overwritten but password is not overwritten if blank");
491
    is($ernest->password,$orig_pass,"Patron was overwritten but password is not overwritten if blank");
486
492
493
    $ernest->category($staff_categorycode);
494
    $ernest->store;
495
496
    $result = $patrons_import->import_patrons($params_4, $defaults);
497
    warn Data::Dumper::Dumper( $result );
498
    $ernest = Koha::Patrons->find({ userid => 'ErnestP' });
499
    is($ernest->surname,'Worrell',"Patron is overwritten, surname changed");
500
    is($ernest->password,$orig_pass,"Patron is imported, password is not changed for staff");
501
487
};
502
};
488
503
489
504
490
- 

Return to bug 23473