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

(-)a/Koha/Illrequest.pm (-46 / +15 lines)
Lines 29-35 use C4::Letters; Link Here
29
use C4::Members;
29
use C4::Members;
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::DateUtils qw/ dt_from_string /;
31
use Koha::DateUtils qw/ dt_from_string /;
32
use Koha::Email;
33
use Koha::Exceptions::Ill;
32
use Koha::Exceptions::Ill;
34
use Koha::Illcomments;
33
use Koha::Illcomments;
35
use Koha::Illrequestattributes;
34
use Koha::Illrequestattributes;
Lines 1329-1336 sub generic_confirm { Link Here
1329
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1328
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1330
          if ( !$to );
1329
          if ( !$to );
1331
        # Create the from, replyto and sender headers
1330
        # Create the from, replyto and sender headers
1332
        my $from = $branch->branchillemail || $branch->branchemail;
1331
        my $from = $branch->branchemail;
1333
        my $replyto = $branch->branchreplyto || $from;
1332
        my $replyto = $branch->inbound_ill_address;
1334
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1333
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1335
            "Your library has no usable email address. Please set it.")
1334
            "Your library has no usable email address. Please set it.")
1336
          if ( !$from );
1335
          if ( !$from );
Lines 1350-1356 sub generic_confirm { Link Here
1350
            borrowernumber         => $self->borrowernumber,
1349
            borrowernumber         => $self->borrowernumber,
1351
            message_transport_type => 'email',
1350
            message_transport_type => 'email',
1352
            to_address             => $to,
1351
            to_address             => $to,
1353
            from_address           => $from
1352
            from_address           => $from,
1353
            reply_address          => $replyto
1354
        };
1354
        };
1355
1355
1356
        if ($letter) {
1356
        if ($letter) {
Lines 1386-1430 sub generic_confirm { Link Here
1386
    }
1386
    }
1387
}
1387
}
1388
1388
1389
=head3 get_staff_to_address
1390
1391
    my $email = $request->get_staff_to_address();
1392
1393
Get the email address to which staff notices should be sent
1394
1395
=cut
1396
1397
sub get_staff_to_address {
1398
    my ( $self ) = @_;
1399
1400
    # The various places we can get an ILL staff email address from
1401
    # (In order of preference)
1402
    #
1403
    # Dedicated branch address
1404
    my $library = Koha::Libraries->find( $self->branchcode );
1405
    my $branch_ill_to = $library->branchillemail;
1406
    # General purpose ILL address from syspref
1407
    my $syspref = C4::Context->preference("ILLDefaultStaffEmail");
1408
    # Branch general email address
1409
    my $branch_to = $library->branchemail;
1410
    # Last resort
1411
    my $koha_admin = C4::Context->preference('KohaAdminEmailAddress');
1412
1413
    my $to;
1414
    if ($branch_ill_to) {
1415
        $to = $branch_ill_to;
1416
    } elsif ($syspref) {
1417
        $to = $syspref;
1418
    } elsif ($branch_to) {
1419
        $to = $branch_to;
1420
    } elsif ($koha_admin) {
1421
        $to = $koha_admin;
1422
    }
1423
1424
    # $to will not be defined if we didn't find a usable address
1425
    return $to;
1426
}
1427
1428
=head3 send_patron_notice
1389
=head3 send_patron_notice
1429
1390
1430
    my $result = $request->send_patron_notice($notice_code);
1391
    my $result = $request->send_patron_notice($notice_code);
Lines 1456-1461 sub send_patron_notice { Link Here
1456
    });
1417
    });
1457
    my @transports = keys %{ $borrower_preferences->{transports} };
1418
    my @transports = keys %{ $borrower_preferences->{transports} };
1458
1419
1420
    # Notice should come from the library where the request was placed,
1421
    # not the patrons home library
1422
    my $branch = Koha::Libraries->find($self->branchcode);
1423
    my $from_address = $branch->branchemail;
1424
    my $reply_address = $branch->inbound_ill_address;
1425
1459
    # Send the notice to the patron via the chosen transport methods
1426
    # Send the notice to the patron via the chosen transport methods
1460
    # and record the results
1427
    # and record the results
1461
    my @success = ();
1428
    my @success = ();
Lines 1470-1475 sub send_patron_notice { Link Here
1470
                letter                 => $letter,
1437
                letter                 => $letter,
1471
                borrowernumber         => $self->borrowernumber,
1438
                borrowernumber         => $self->borrowernumber,
1472
                message_transport_type => $transport,
1439
                message_transport_type => $transport,
1440
                from_address           => $from_address,
1441
                reply_address          => $reply_address
1473
            });
1442
            });
1474
            if ($result) {
1443
            if ($result) {
1475
                push @success, $transport;
1444
                push @success, $transport;
Lines 1515-1521 sub send_staff_notice { Link Here
1515
1484
1516
    # Get the staff notices that have been assigned for sending in
1485
    # Get the staff notices that have been assigned for sending in
1517
    # the syspref
1486
    # the syspref
1518
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices');
1487
    my $staff_to_send = C4::Context->preference('ILLSendStaffNotices') // q{};
1519
1488
1520
    # If it hasn't been enabled in the syspref, we don't want to send it
1489
    # If it hasn't been enabled in the syspref, we don't want to send it
1521
    if ($staff_to_send !~ /\b$notice_code\b/) {
1490
    if ($staff_to_send !~ /\b$notice_code\b/) {
Lines 1530-1536 sub send_staff_notice { Link Here
1530
    });
1499
    });
1531
1500
1532
    # Try and get an address to which to send staff notices
1501
    # Try and get an address to which to send staff notices
1533
    my $to_address = scalar $self->get_staff_to_address;
1502
    my $branch = Koha::Libraries->find($self->branchcode);
1503
    my $to_address = $branch->inbound_ill_address;
1534
1504
1535
    my $params = {
1505
    my $params = {
1536
        letter                 => $letter,
1506
        letter                 => $letter,
Lines 1540-1546 sub send_staff_notice { Link Here
1540
1510
1541
    if ($to_address) {
1511
    if ($to_address) {
1542
        $params->{to_address} = $to_address;
1512
        $params->{to_address} = $to_address;
1543
        $params->{from_address} = $to_address;
1544
    } else {
1513
    } else {
1545
        return {
1514
        return {
1546
            error => 'notice_no_create'
1515
            error => 'notice_no_create'
(-)a/Koha/Library.pm (+18 lines)
Lines 134-139 sub inbound_email_address { Link Here
134
      || undef;
134
      || undef;
135
}
135
}
136
136
137
=head3 inbound_ill_address
138
139
  my $to_email = Koha::Library->inbound_ill_address;
140
141
Returns an effective email address which should be accessible to librarians at the branch
142
for inter library loans communication.
143
144
=cut
145
146
sub inbound_ill_address {
147
    my ($self) = @_;
148
149
    return
150
         $self->branchillemail
151
      || C4::Context->preference('ILLDefaultStaffEmail')
152
      || $self->inbound_email_address;
153
}
154
137
=head3 library_groups
155
=head3 library_groups
138
156
139
Return the Library groups of this library
157
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