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

(-)a/Koha/Illrequest.pm (-45 / +15 lines)
Lines 1330-1337 sub generic_confirm { Link Here
1330
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1330
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1331
          if ( !$to );
1331
          if ( !$to );
1332
        # Create the from, replyto and sender headers
1332
        # Create the from, replyto and sender headers
1333
        my $from = $branch->branchillemail || $branch->branchemail;
1333
        my $from = $branch->branchemail;
1334
        my $replyto = $branch->branchreplyto || $from;
1334
        my $replyto = $branch->inbound_ill_address;
1335
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1335
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1336
            "Your library has no usable email address. Please set it.")
1336
            "Your library has no usable email address. Please set it.")
1337
          if ( !$from );
1337
          if ( !$from );
Lines 1351-1357 sub generic_confirm { Link Here
1351
            borrowernumber         => $self->borrowernumber,
1351
            borrowernumber         => $self->borrowernumber,
1352
            message_transport_type => 'email',
1352
            message_transport_type => 'email',
1353
            to_address             => $to,
1353
            to_address             => $to,
1354
            from_address           => $from
1354
            from_address           => $from,
1355
            reply_address          => $replyto
1355
        };
1356
        };
1356
1357
1357
        if ($letter) {
1358
        if ($letter) {
Lines 1387-1431 sub generic_confirm { Link Here
1387
    }
1388
    }
1388
}
1389
}
1389
1390
1390
=head3 get_staff_to_address
1391
1392
    my $email = $request->get_staff_to_address();
1393
1394
Get the email address to which staff notices should be sent
1395
1396
=cut
1397
1398
sub get_staff_to_address {
1399
    my ( $self ) = @_;
1400
1401
    # The various places we can get an ILL staff email address from
1402
    # (In order of preference)
1403
    #
1404
    # Dedicated branch address
1405
    my $library = Koha::Libraries->find( $self->branchcode );
1406
    my $branch_ill_to = $library->branchillemail;
1407
    # General purpose ILL address from syspref
1408
    my $syspref = C4::Context->preference("ILLDefaultStaffEmail");
1409
    # Branch general email address
1410
    my $branch_to = $library->branchemail;
1411
    # Last resort
1412
    my $koha_admin = C4::Context->preference('KohaAdminEmailAddress');
1413
1414
    my $to;
1415
    if ($branch_ill_to) {
1416
        $to = $branch_ill_to;
1417
    } elsif ($syspref) {
1418
        $to = $syspref;
1419
    } elsif ($branch_to) {
1420
        $to = $branch_to;
1421
    } elsif ($koha_admin) {
1422
        $to = $koha_admin;
1423
    }
1424
1425
    # $to will not be defined if we didn't find a usable address
1426
    return $to;
1427
}
1428
1429
=head3 send_patron_notice
1391
=head3 send_patron_notice
1430
1392
1431
    my $result = $request->send_patron_notice($notice_code);
1393
    my $result = $request->send_patron_notice($notice_code);
Lines 1457-1462 sub send_patron_notice { Link Here
1457
    });
1419
    });
1458
    my @transports = keys %{ $borrower_preferences->{transports} };
1420
    my @transports = keys %{ $borrower_preferences->{transports} };
1459
1421
1422
    # Notice should come from the library where the request was placed, 
1423
    # not the patrons home library
1424
    my $branch = Koha::Libraries->find($self->branchcode);
1425
    my $from_address = $branch->branchemail;
1426
    my $reply_address = $branch->inbound_ill_address;
1427
1460
    # Send the notice to the patron via the chosen transport methods
1428
    # Send the notice to the patron via the chosen transport methods
1461
    # and record the results
1429
    # and record the results
1462
    my @success = ();
1430
    my @success = ();
Lines 1471-1476 sub send_patron_notice { Link Here
1471
                letter                 => $letter,
1439
                letter                 => $letter,
1472
                borrowernumber         => $self->borrowernumber,
1440
                borrowernumber         => $self->borrowernumber,
1473
                message_transport_type => $transport,
1441
                message_transport_type => $transport,
1442
                from_address           => $from_address,
1443
                reply_address          => $reply_address
1474
            });
1444
            });
1475
            if ($result) {
1445
            if ($result) {
1476
                push @success, $transport;
1446
                push @success, $transport;
Lines 1516-1522 sub send_staff_notice { Link Here
1516
1486
1517
    # Get the staff notices that have been assigned for sending in
1487
    # Get the staff notices that have been assigned for sending in
1518
    # the syspref
1488
    # the syspref
1519
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices');
1489
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices') // q{};
1520
1490
1521
    # If it hasn't been enabled in the syspref, we don't want to send it
1491
    # If it hasn't been enabled in the syspref, we don't want to send it
1522
    if ($staff_to_send !~ /\b$notice_code\b/) {
1492
    if ($staff_to_send !~ /\b$notice_code\b/) {
Lines 1531-1537 sub send_staff_notice { Link Here
1531
    });
1501
    });
1532
1502
1533
    # Try and get an address to which to send staff notices
1503
    # Try and get an address to which to send staff notices
1534
    my $to_address = scalar $self->get_staff_to_address;
1504
    my $branch = Koha::Libraries->find($self->branchcode);
1505
    my $to_address = $branch->inbound_ill_address;
1535
1506
1536
    my $params = {
1507
    my $params = {
1537
        letter                 => $letter,
1508
        letter                 => $letter,
Lines 1541-1547 sub send_staff_notice { Link Here
1541
1512
1542
    if ($to_address) {
1513
    if ($to_address) {
1543
        $params->{to_address} = $to_address;
1514
        $params->{to_address} = $to_address;
1544
        $params->{from_address} = $to_address;
1545
    } else {
1515
    } else {
1546
        return {
1516
        return {
1547
            error => 'notice_no_create'
1517
            error => 'notice_no_create'
(-)a/Koha/Library.pm (+18 lines)
Lines 84-89 sub inbound_email_address { Link Here
84
      || undef;
84
      || undef;
85
}
85
}
86
86
87
=head3 inbound_ill_address
88
89
  my $to_email = Koha::Library->inbound_ill_address;
90
91
Returns an effective email address which should be accessible to librarians at the branch
92
for inter library loans communication.
93
94
=cut
95
96
sub inbound_ill_address {
97
    my ($self) = @_;
98
99
    return
100
         $self->branchillemail
101
      || C4::Context->preference('ILLDefaultStaffEmail')
102
      || $self->inbound_email_address;
103
}
104
87
=head3 library_groups
105
=head3 library_groups
88
106
89
Return the Library groups of this library
107
Return the Library groups of this library
(-)a/t/db_dependent/Illrequests.t (-62 / +14 lines)
Lines 713-719 subtest 'Backend core methods' => sub { Link Here
713
713
714
subtest 'Helpers' => sub {
714
subtest 'Helpers' => sub {
715
715
716
    plan tests => 21;
716
    plan tests => 20;
717
717
718
    $schema->storage->txn_begin;
718
    $schema->storage->txn_begin;
719
719
Lines 815-876 subtest 'Helpers' => sub { Link Here
815
        "Correct error when missing type"
815
        "Correct error when missing type"
816
    );
816
    );
817
817
818
    #get_staff_to_address
819
    # Mock a KohaAdminEmailAddress syspref
820
    t::lib::Mocks::mock_preference(
821
        'KohaAdminEmailAddress',
822
        'kohaadmin@nowhere.com'
823
    );
824
    # No branch addresses defined and no ILLDefaultStaffEmail, so should
825
    # fall back to Koha admin address
826
    my $email_kohaadmin = $illrq_obj->get_staff_to_address;
827
    ok(
828
        $email_kohaadmin eq 'kohaadmin@nowhere.com',
829
        'get_staff_to_address falls back to Koha admin in the absence of other alternatives'
830
    );
831
    # General branch address defined, should fall back to that
832
    $builder->delete({ source => 'Branch', records => $illbrn });
833
    $illbrn = $builder->build({
834
        source => 'Branch',
835
        value => {
836
            branchcode => 'HDE',
837
            branchemail => 'branch@nowhere.com',
838
            branchillemail => "",
839
            branchreplyto => ""
840
        }
841
    });
842
    my $email_gen_branch = $illrq_obj->get_staff_to_address;
843
    ok(
844
        $email_gen_branch eq 'branch@nowhere.com',
845
        'get_staff_to_address falls back to general branch address when defined'
846
    );
847
    # ILL staff syspref address defined, should fall back to that
848
    t::lib::Mocks::mock_preference(
849
        'ILLDefaultStaffEmail',
850
        'illstaff@nowhere.com'
851
    );
852
    my $email_syspref = $illrq_obj->get_staff_to_address;
853
    ok(
854
        $email_syspref eq 'illstaff@nowhere.com',
855
        'get_staff_to_address falls back to ILLDefaultStaffEmail when defined'
856
    );
857
    # Branch ILL address defined, should use that
858
    $builder->delete({ source => 'Branch', records => $illbrn });
859
    $illbrn = $builder->build({
860
        source => 'Branch',
861
        value => {
862
            branchcode => 'HDE',
863
            branchemail => 'branch@nowhere.com',
864
            branchillemail => 'branchill@nowhere.com',
865
            branchreplyto => ""
866
        }
867
    });
868
    my $email_branch = $illrq_obj->get_staff_to_address;
869
    ok(
870
        $email_branch eq 'branchill@nowhere.com',
871
        'get_staff_to_address uses branch ILL address when defined'
872
    );
873
874
    #send_staff_notice
818
    #send_staff_notice
875
    # Specify that no staff notices should be send
819
    # Specify that no staff notices should be send
876
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', '');
820
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', '');
Lines 881-901 subtest 'Helpers' => sub { Link Here
881
        { error => 'notice_not_enabled' },
825
        { error => 'notice_not_enabled' },
882
        "Does not send notices that are not enabled"
826
        "Does not send notices that are not enabled"
883
    );
827
    );
828
    my $queue = $schema->resultset('MessageQueue')->search({
829
            letter_code => 'ILL_REQUEST_CANCEL'
830
        });
831
    is($queue->count, 0, "Notice is not queued");
832
884
    # Specify that the cancel notice can be sent
833
    # Specify that the cancel notice can be sent
885
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL');
834
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL');
886
    my $return_staff_cancel = $illrq_obj->send_staff_notice(
835
    my $return_staff_cancel = $illrq_obj->send_staff_notice(
887
        'ILL_REQUEST_CANCEL'
836
        'ILL_REQUEST_CANCEL'
888
    );
837
    );
889
    my $cancel = $schema->resultset('MessageQueue')->search({
890
            letter_code => 'ILL_REQUEST_CANCEL',
891
            message_transport_type => 'email',
892
            to_address => 'branchill@nowhere.com'
893
        })->next()->letter_code;
894
    is_deeply(
838
    is_deeply(
895
        $return_staff_cancel,
839
        $return_staff_cancel,
896
        { success => 'notice_queued' },
840
        { success => 'notice_queued' },
897
        "Correct return when staff notice created"
841
        "Correct return when staff notice created"
898
    );
842
    );
843
    $queue = $schema->resultset('MessageQueue')->search({
844
            letter_code => 'ILL_REQUEST_CANCEL'
845
        });
846
    is($queue->count, 1, "Notice queued as expected");
899
847
900
    my $return_staff_fail = $illrq_obj->send_staff_notice();
848
    my $return_staff_fail = $illrq_obj->send_staff_notice();
901
    is_deeply(
849
    is_deeply(
Lines 903-908 subtest 'Helpers' => sub { Link Here
903
        { error => 'notice_no_type' },
851
        { error => 'notice_no_type' },
904
        "Correct error when missing type"
852
        "Correct error when missing type"
905
    );
853
    );
854
    $queue = $schema->resultset('MessageQueue')->search({
855
            letter_code => 'ILL_REQUEST_CANCEL'
856
        });
857
    is($queue->count, 1, "Notice is not queued");
906
858
907
    #get_notice
859
    #get_notice
908
    my $not = $illrq_obj->get_notice({
860
    my $not = $illrq_obj->get_notice({
(-)a/t/db_dependent/Koha/Libraries.t (-2 / +52 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Context;
25
use C4::Context;
Lines 159-164 subtest '->inbound_email_address' => sub { Link Here
159
    $schema->storage->txn_rollback;
159
    $schema->storage->txn_rollback;
160
};
160
};
161
161
162
subtest '->inbound_ill_address' => sub {
163
164
    plan tests => 7;
165
166
    $schema->storage->txn_begin;
167
168
    my $library_1 = $builder->build_object(
169
        {
170
            class => 'Koha::Libraries',
171
            value => {
172
                branchemail   => 'from@mylibrary.com',
173
                branchreplyto => 'reply@mylibrary.com',
174
                branchillemail => 'ill@mylibrary.com'
175
            }
176
        }
177
    );
178
179
    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'admin@mylibrary.com' );
180
    t::lib::Mocks::mock_preference( 'ReplytoDefault', 'reply@mylibrary.com' );
181
    t::lib::Mocks::mock_preference( 'ILLDefaultStaffEmail', 'illdefault@mylibrary.com' );
182
183
    is( $library_1->inbound_ill_address, $library_1->branchillemail,
184
       'If defined, use library branchillemail address');
185
186
    $library_1->branchillemail(undef)->store();
187
    is( $library_1->inbound_ill_address, 'illdefault@mylibrary.com',
188
       'Fallback to ILLDefaultStaffEmail preference when branchillemail is undefined');
189
190
    t::lib::Mocks::mock_preference( 'ILLDefaultStaffEmail', undef );
191
    is( $library_1->inbound_ill_address, $library_1->branchreplyto,
192
       'Fallback to library replyto address when ILLDefaultStaffEmail is undefined');
193
194
    $library_1->branchreplyto(undef)->store();
195
    is( $library_1->inbound_ill_address, $library_1->branchemail,
196
       'Fallback to branches email address when branchreplyto is undefined');
197
198
    $library_1->branchemail(undef)->store();
199
    is( $library_1->inbound_ill_address, 'reply@mylibrary.com',
200
       'Fallback to ReplytoDefault email address when branchreplyto and branchemail are undefined');
201
202
    t::lib::Mocks::mock_preference( 'ReplytoDefault', '' );
203
    is( $library_1->inbound_ill_address, 'admin@mylibrary.com',
204
       'Fallback to KohaAdminEmailAddress email address when branchreplyto, branchemail and ReplytoDefault are undefined');
205
206
    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', '' );
207
    is( $library_1->inbound_ill_address, undef,
208
       'Return undef when  email address when branchreplyto, branchemail, ReplytoDefault and KohaAdminEmailAddress are undefined');
209
210
    $schema->storage->txn_rollback;
211
};
212
162
subtest 'cash_registers' => sub {
213
subtest 'cash_registers' => sub {
163
    plan tests => 3;
214
    plan tests => 3;
164
215
165
- 

Return to bug 22818