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

(-)a/C4/SIP/Sip/MsgType.pm (-2 / +25 lines)
Lines 552-558 sub handle_checkout { Link Here
552
        }
552
        }
553
553
554
        # We never return the obsolete 'U' value for 'desensitize'
554
        # We never return the obsolete 'U' value for 'desensitize'
555
        $resp .= sipbool( $status->desensitize );
555
        $resp .= sipbool( desensitize( { status => $status, patron => $patron, server => $server } ) );
556
        $resp .= timestamp;
556
        $resp .= timestamp;
557
557
558
        # Now for the variable fields
558
        # Now for the variable fields
Lines 1458-1464 sub handle_renew { Link Here
1458
        } else {
1458
        } else {
1459
            $resp .= 'U';
1459
            $resp .= 'U';
1460
        }
1460
        }
1461
        $resp .= sipbool( $status->desensitize );
1461
        $resp .= sipbool( desensitize( { status => $status, patron => $patron, server => $server } ) );
1462
        $resp .= timestamp;
1462
        $resp .= timestamp;
1463
        $resp .= add_field( FID_PATRON_ID, $patron->id, $server );
1463
        $resp .= add_field( FID_PATRON_ID, $patron->id, $server );
1464
        $resp .= add_field( FID_ITEM_ID, $item->id, $server );
1464
        $resp .= add_field( FID_ITEM_ID, $item->id, $server );
Lines 1701-1706 sub api_auth { Link Here
1701
    return $status;
1701
    return $status;
1702
}
1702
}
1703
1703
1704
sub desensitize {
1705
    my ($params) = @_;
1706
1707
    my $status      = $params->{status};
1708
    my $desensitize = $status->desensitize();
1709
1710
    # If desenstize is already false, no need to do anything
1711
    return unless $desensitize;
1712
1713
    my $patron = $params->{patron};
1714
    my $server = $params->{server};
1715
1716
    my $patron_categories = $server->{account}->{never_demagnitize};
1717
1718
    # If no patron categories are set for never desensitize, no need to do anything
1719
    return $desensitize unless $patron_categories;
1720
1721
    my $patron_category = $patron->ptype();
1722
    my @patron_categories = split( /,/, $patron_categories );
1723
1724
    return !grep( /^$patron_category$/, @patron_categories );
1725
}
1726
1704
1;
1727
1;
1705
__END__
1728
__END__
1706
1729
(-)a/t/db_dependent/SIP/Message.t (-2 / +150 lines)
Lines 21-27 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
use Test::More tests => 10;
24
use Test::More tests => 12;
25
use Test::MockObject;
25
use Test::MockObject;
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::Warn;
27
use Test::Warn;
Lines 76-81 subtest 'Checkout V2' => sub { Link Here
76
    $schema->storage->txn_rollback;
76
    $schema->storage->txn_rollback;
77
};
77
};
78
78
79
subtest 'Test checkout desensitize' => sub {
80
    my $schema = Koha::Database->new->schema;
81
    $schema->storage->txn_begin;
82
    plan tests => 3;
83
    $C4::SIP::Sip::protocol_version = 2;
84
    test_checkout_desensitize();
85
    $schema->storage->txn_rollback;
86
};
87
88
subtest 'Test renew desensitize' => sub {
89
    my $schema = Koha::Database->new->schema;
90
    $schema->storage->txn_begin;
91
    plan tests => 3;
92
    $C4::SIP::Sip::protocol_version = 2;
93
    test_renew_desensitize();
94
    $schema->storage->txn_rollback;
95
};
96
79
subtest 'Checkin V2' => sub {
97
subtest 'Checkin V2' => sub {
80
    my $schema = Koha::Database->new->schema;
98
    my $schema = Koha::Database->new->schema;
81
    $schema->storage->txn_begin;
99
    $schema->storage->txn_begin;
Lines 793-798 sub test_hold_patron_bcode { Link Here
793
    is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" );
811
    is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" );
794
}
812
}
795
813
814
sub test_checkout_desensitize {
815
    my $builder = t::lib::TestBuilder->new();
816
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
817
    my ( $response, $findpatron );
818
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
819
820
    # create some data
821
    my $patron1 = $builder->build({
822
        source => 'Borrower',
823
        value  => {
824
            password => hash_password( PATRON_PW ),
825
        },
826
    });
827
    my $card1 = $patron1->{cardnumber};
828
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
829
    my $patron_category = $sip_patron1->ptype();
830
    $findpatron = $sip_patron1;
831
    my $item_object = $builder->build_sample_item({
832
        damaged => 0,
833
        withdrawn => 0,
834
        itemlost => 0,
835
        restricted => 0,
836
        homebranch => $branchcode,
837
        holdingbranch => $branchcode,
838
    });
839
840
    my $mockILS = $mocks->{ils};
841
    my $server = { ils => $mockILS, account => {} };
842
    $mockILS->mock( 'institution', sub { $branchcode; } );
843
    $mockILS->mock( 'supports', sub { return; } );
844
    $mockILS->mock( 'checkout', sub {
845
        shift;
846
        return C4::SIP::ILS->checkout(@_);
847
    });
848
    my $today = dt_from_string;
849
    t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 });
850
    t::lib::Mocks::mock_preference( 'CheckPrevCheckout',  'hardyes' );
851
852
    my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) .
853
    siprequestdate( $today->clone->add( days => 1) ) .
854
    FID_INST_ID . $branchcode . '|'.
855
    FID_PATRON_ID . $sip_patron1->id . '|' .
856
    FID_ITEM_ID . $item_object->barcode . '|' .
857
    FID_TERMINAL_PWD . 'ignored' . '|';
858
859
    undef $response;
860
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
861
    $server->{account}->{never_demagnitize} = "A,$patron_category,Z";
862
    $msg->handle_checkout( $server );
863
    my $respcode = substr( $response, 5, 1 );
864
    is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" );
865
866
    undef $response;
867
    $server->{account}->{never_demagnitize} = "A,B,C";
868
    $msg->handle_checkout( $server );
869
    $respcode = substr( $response, 5, 1 );
870
    is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" );
871
872
    undef $response;
873
    $server->{account}->{never_demagnitize} = "";
874
    $msg->handle_checkout( $server );
875
    $respcode = substr( $response, 5, 1 );
876
    is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" );
877
}
878
879
sub test_renew_desensitize {
880
    my $builder = t::lib::TestBuilder->new();
881
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
882
    my ( $response, $findpatron );
883
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
884
885
    # create some data
886
    my $patron1 = $builder->build({
887
        source => 'Borrower',
888
        value  => {
889
            password => hash_password( PATRON_PW ),
890
        },
891
    });
892
    my $card1 = $patron1->{cardnumber};
893
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
894
    my $patron_category = $sip_patron1->ptype();
895
    $findpatron = $sip_patron1;
896
    my $item_object = $builder->build_sample_item({
897
        damaged => 0,
898
        withdrawn => 0,
899
        itemlost => 0,
900
        restricted => 0,
901
        homebranch => $branchcode,
902
        holdingbranch => $branchcode,
903
    });
904
905
    my $mockILS = $mocks->{ils};
906
    my $server = { ils => $mockILS, account => {} };
907
    $mockILS->mock( 'institution', sub { $branchcode; } );
908
    $mockILS->mock( 'supports', sub { return; } );
909
    $mockILS->mock( 'checkout', sub {
910
        shift;
911
        return C4::SIP::ILS->checkout(@_);
912
    });
913
    my $today = dt_from_string;
914
    t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 });
915
916
    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store;
917
918
    my $siprequest = RENEW . 'YN' . siprequestdate($today) .
919
    siprequestdate( $today->clone->add( days => 1) ) .
920
    FID_INST_ID . $branchcode . '|'.
921
    FID_PATRON_ID . $sip_patron1->id . '|' .
922
    FID_ITEM_ID . $item_object->barcode . '|' .
923
    FID_TERMINAL_PWD . 'ignored' . '|';
924
925
    undef $response;
926
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
927
    $server->{account}->{never_demagnitize} = "A,$patron_category,Z";
928
    $msg->handle_checkout( $server );
929
    my $respcode = substr( $response, 5, 1 );
930
    is( $respcode, 'N', "Desensitize flag was not set for patron category in never_demagnitize" );
931
932
    undef $response;
933
    $server->{account}->{never_demagnitize} = "A,B,C";
934
    $msg->handle_checkout( $server );
935
    $respcode = substr( $response, 5, 1 );
936
    is( $respcode, 'Y', "Desensitize flag was set for patron category not in never_demagnitize" );
937
938
    undef $response;
939
    $server->{account}->{never_demagnitize} = "";
940
    $msg->handle_checkout( $server );
941
    $respcode = substr( $response, 5, 1 );
942
    is( $respcode, 'Y', "Desensitize flag was set for empty never_demagnitize" );
943
}
944
796
# Helper routines
945
# Helper routines
797
946
798
sub create_mocks {
947
sub create_mocks {
799
- 

Return to bug 26370