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

(-)a/Koha/Illrequest.pm (-46 / +15 lines)
Lines 30-36 use C4::Letters; Link Here
30
use C4::Members;
30
use C4::Members;
31
use Koha::Database;
31
use Koha::Database;
32
use Koha::DateUtils qw/ dt_from_string /;
32
use Koha::DateUtils qw/ dt_from_string /;
33
use Koha::Email;
34
use Koha::Exceptions::Ill;
33
use Koha::Exceptions::Ill;
35
use Koha::Illcomments;
34
use Koha::Illcomments;
36
use Koha::Illrequestattributes;
35
use Koha::Illrequestattributes;
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.")
1329
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1331
          if ( !$to );
1330
          if ( !$to );
1332
        # Create the from, replyto and sender headers
1331
        # Create the from, replyto and sender headers
1333
        my $from = $branch->branchillemail || $branch->branchemail;
1332
        my $from = $branch->branchemail;
1334
        my $replyto = $branch->branchreplyto || $from;
1333
        my $replyto = $branch->inbound_ill_address;
1335
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1334
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1336
            "Your library has no usable email address. Please set it.")
1335
            "Your library has no usable email address. Please set it.")
1337
          if ( !$from );
1336
          if ( !$from );
Lines 1351-1357 sub generic_confirm { Link Here
1351
            borrowernumber         => $self->borrowernumber,
1350
            borrowernumber         => $self->borrowernumber,
1352
            message_transport_type => 'email',
1351
            message_transport_type => 'email',
1353
            to_address             => $to,
1352
            to_address             => $to,
1354
            from_address           => $from
1353
            from_address           => $from,
1354
            reply_address          => $replyto
1355
        };
1355
        };
1356
1356
1357
        if ($letter) {
1357
        if ($letter) {
Lines 1387-1431 sub generic_confirm { Link Here
1387
    }
1387
    }
1388
}
1388
}
1389
1389
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
1390
=head3 send_patron_notice
1430
1391
1431
    my $result = $request->send_patron_notice($notice_code);
1392
    my $result = $request->send_patron_notice($notice_code);
Lines 1457-1462 sub send_patron_notice { Link Here
1457
    });
1418
    });
1458
    my @transports = keys %{ $borrower_preferences->{transports} };
1419
    my @transports = keys %{ $borrower_preferences->{transports} };
1459
1420
1421
    # Notice should come from the library where the request was placed,
1422
    # not the patrons home library
1423
    my $branch = Koha::Libraries->find($self->branchcode);
1424
    my $from_address = $branch->branchemail;
1425
    my $reply_address = $branch->inbound_ill_address;
1426
1460
    # Send the notice to the patron via the chosen transport methods
1427
    # Send the notice to the patron via the chosen transport methods
1461
    # and record the results
1428
    # and record the results
1462
    my @success = ();
1429
    my @success = ();
Lines 1471-1476 sub send_patron_notice { Link Here
1471
                letter                 => $letter,
1438
                letter                 => $letter,
1472
                borrowernumber         => $self->borrowernumber,
1439
                borrowernumber         => $self->borrowernumber,
1473
                message_transport_type => $transport,
1440
                message_transport_type => $transport,
1441
                from_address           => $from_address,
1442
                reply_address          => $reply_address
1474
            });
1443
            });
1475
            if ($result) {
1444
            if ($result) {
1476
                push @success, $transport;
1445
                push @success, $transport;
Lines 1516-1522 sub send_staff_notice { Link Here
1516
1485
1517
    # Get the staff notices that have been assigned for sending in
1486
    # Get the staff notices that have been assigned for sending in
1518
    # the syspref
1487
    # the syspref
1519
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices');
1488
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices') // q{};
1520
1489
1521
    # If it hasn't been enabled in the syspref, we don't want to send it
1490
    # 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/) {
1491
    if ($staff_to_send !~ /\b$notice_code\b/) {
Lines 1531-1537 sub send_staff_notice { Link Here
1531
    });
1500
    });
1532
1501
1533
    # Try and get an address to which to send staff notices
1502
    # Try and get an address to which to send staff notices
1534
    my $to_address = scalar $self->get_staff_to_address;
1503
    my $branch = Koha::Libraries->find($self->branchcode);
1504
    my $to_address = $branch->inbound_ill_address;
1535
1505
1536
    my $params = {
1506
    my $params = {
1537
        letter                 => $letter,
1507
        letter                 => $letter,
Lines 1541-1547 sub send_staff_notice { Link Here
1541
1511
1542
    if ($to_address) {
1512
    if ($to_address) {
1543
        $params->{to_address} = $to_address;
1513
        $params->{to_address} = $to_address;
1544
        $params->{from_address} = $to_address;
1545
    } else {
1514
    } else {
1546
        return {
1515
        return {
1547
            error => 'notice_no_create'
1516
            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 715-721 subtest 'Backend core methods' => sub { Link Here
715
715
716
subtest 'Helpers' => sub {
716
subtest 'Helpers' => sub {
717
717
718
    plan tests => 21;
718
    plan tests => 20;
719
719
720
    $schema->storage->txn_begin;
720
    $schema->storage->txn_begin;
721
721
Lines 817-878 subtest 'Helpers' => sub { Link Here
817
        "Correct error when missing type"
817
        "Correct error when missing type"
818
    );
818
    );
819
819
820
    #get_staff_to_address
821
    # Mock a KohaAdminEmailAddress syspref
822
    t::lib::Mocks::mock_preference(
823
        'KohaAdminEmailAddress',
824
        'kohaadmin@nowhere.com'
825
    );
826
    # No branch addresses defined and no ILLDefaultStaffEmail, so should
827
    # fall back to Koha admin address
828
    my $email_kohaadmin = $illrq_obj->get_staff_to_address;
829
    ok(
830
        $email_kohaadmin eq 'kohaadmin@nowhere.com',
831
        'get_staff_to_address falls back to Koha admin in the absence of other alternatives'
832
    );
833
    # General branch address defined, should fall back to that
834
    $builder->delete({ source => 'Branch', records => $illbrn });
835
    $illbrn = $builder->build({
836
        source => 'Branch',
837
        value => {
838
            branchcode => 'HDE',
839
            branchemail => 'branch@nowhere.com',
840
            branchillemail => "",
841
            branchreplyto => ""
842
        }
843
    });
844
    my $email_gen_branch = $illrq_obj->get_staff_to_address;
845
    ok(
846
        $email_gen_branch eq 'branch@nowhere.com',
847
        'get_staff_to_address falls back to general branch address when defined'
848
    );
849
    # ILL staff syspref address defined, should fall back to that
850
    t::lib::Mocks::mock_preference(
851
        'ILLDefaultStaffEmail',
852
        'illstaff@nowhere.com'
853
    );
854
    my $email_syspref = $illrq_obj->get_staff_to_address;
855
    ok(
856
        $email_syspref eq 'illstaff@nowhere.com',
857
        'get_staff_to_address falls back to ILLDefaultStaffEmail when defined'
858
    );
859
    # Branch ILL address defined, should use that
860
    $builder->delete({ source => 'Branch', records => $illbrn });
861
    $illbrn = $builder->build({
862
        source => 'Branch',
863
        value => {
864
            branchcode => 'HDE',
865
            branchemail => 'branch@nowhere.com',
866
            branchillemail => 'branchill@nowhere.com',
867
            branchreplyto => ""
868
        }
869
    });
870
    my $email_branch = $illrq_obj->get_staff_to_address;
871
    ok(
872
        $email_branch eq 'branchill@nowhere.com',
873
        'get_staff_to_address uses branch ILL address when defined'
874
    );
875
876
    #send_staff_notice
820
    #send_staff_notice
877
    # Specify that no staff notices should be send
821
    # Specify that no staff notices should be send
878
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', '');
822
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', '');
Lines 883-903 subtest 'Helpers' => sub { Link Here
883
        { error => 'notice_not_enabled' },
827
        { error => 'notice_not_enabled' },
884
        "Does not send notices that are not enabled"
828
        "Does not send notices that are not enabled"
885
    );
829
    );
830
    my $queue = $schema->resultset('MessageQueue')->search({
831
            letter_code => 'ILL_REQUEST_CANCEL'
832
        });
833
    is($queue->count, 0, "Notice is not queued");
834
886
    # Specify that the cancel notice can be sent
835
    # Specify that the cancel notice can be sent
887
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL');
836
    t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL');
888
    my $return_staff_cancel = $illrq_obj->send_staff_notice(
837
    my $return_staff_cancel = $illrq_obj->send_staff_notice(
889
        'ILL_REQUEST_CANCEL'
838
        'ILL_REQUEST_CANCEL'
890
    );
839
    );
891
    my $cancel = $schema->resultset('MessageQueue')->search({
892
            letter_code => 'ILL_REQUEST_CANCEL',
893
            message_transport_type => 'email',
894
            to_address => 'branchill@nowhere.com'
895
        })->next()->letter_code;
896
    is_deeply(
840
    is_deeply(
897
        $return_staff_cancel,
841
        $return_staff_cancel,
898
        { success => 'notice_queued' },
842
        { success => 'notice_queued' },
899
        "Correct return when staff notice created"
843
        "Correct return when staff notice created"
900
    );
844
    );
845
    $queue = $schema->resultset('MessageQueue')->search({
846
            letter_code => 'ILL_REQUEST_CANCEL'
847
        });
848
    is($queue->count, 1, "Notice queued as expected");
901
849
902
    my $return_staff_fail = $illrq_obj->send_staff_notice();
850
    my $return_staff_fail = $illrq_obj->send_staff_notice();
903
    is_deeply(
851
    is_deeply(
Lines 905-910 subtest 'Helpers' => sub { Link Here
905
        { error => 'notice_no_type' },
853
        { error => 'notice_no_type' },
906
        "Correct error when missing type"
854
        "Correct error when missing type"
907
    );
855
    );
856
    $queue = $schema->resultset('MessageQueue')->search({
857
            letter_code => 'ILL_REQUEST_CANCEL'
858
        });
859
    is($queue->count, 1, "Notice is not queued");
908
860
909
    #get_notice
861
    #get_notice
910
    my $not = $illrq_obj->get_notice({
862
    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