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

(-)a/C4/Letters.pm (-3 / +10 lines)
Lines 1319-1327 sub _send_message_by_email { Link Here
1319
1319
1320
    my $patron;
1320
    my $patron;
1321
    my $to_address = $message->{'to_address'};
1321
    my $to_address = $message->{'to_address'};
1322
    unless ($to_address) {
1322
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1323
    if($use_garantor eq 'yes' || !$to_address) {
1323
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1324
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1324
        unless ($patron) {
1325
        unless ($patron or $to_address) {
1325
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1326
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1326
            _set_message_status(
1327
            _set_message_status(
1327
                {
1328
                {
Lines 1332-1338 sub _send_message_by_email { Link Here
1332
            );
1333
            );
1333
            return;
1334
            return;
1334
        }
1335
        }
1335
        $to_address = $patron->notice_email_address;
1336
        if ($patron) {
1337
            $to_address = $patron->notice_email_address;
1338
        }
1336
        unless ($to_address) {  
1339
        unless ($to_address) {  
1337
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1340
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1338
            # warning too verbose for this more common case?
1341
            # warning too verbose for this more common case?
Lines 1467-1472 sub _send_message_by_email { Link Here
1467
      if !$message->{to_address}
1470
      if !$message->{to_address}
1468
      || $message->{to_address} ne $email->email->header('To');
1471
      || $message->{to_address} ne $email->email->header('To');
1469
1472
1473
    _update_message_from_address($message->{'message_id'},$email->email->header('From') )
1474
      if !$message->{from_address}
1475
      || $message->{from_address} ne $email->email->header('From');
1476
1470
    try {
1477
    try {
1471
        $email->send_or_die({ transport => $smtp_server->transport });
1478
        $email->send_or_die({ transport => $smtp_server->transport });
1472
1479
(-)a/Koha/Email.pm (-4 / +8 lines)
Lines 118-127 sub create { Link Here
118
        $args->{to} = $params->{to};
118
        $args->{to} = $params->{to};
119
    }
119
    }
120
120
121
    Koha::Exceptions::BadParameter->throw(
121
    my @emails = split(',', $args->{to});
122
        error     => "Invalid 'to' parameter: " . $args->{to},
122
    foreach my $email (@emails) {
123
        parameter => 'to'
123
       $email =~ s/ //g;
124
    ) unless Koha::Email->is_valid( $args->{to} );    # to is mandatory
124
       Koha::Exceptions::BadParameter->throw(
125
           error     => "Invalid 'to' parameter: ".$email,
126
           parameter => 'to'
127
       ) unless Koha::Email->is_valid($email);
128
    }
125
129
126
    my $addresses = {};
130
    my $addresses = {};
127
    $addresses->{reply_to} = $params->{reply_to};
131
    $addresses->{reply_to} = $params->{reply_to};
(-)a/Koha/Patron.pm (-2 / +23 lines)
Lines 1412-1425 Returns the empty string if no email address. Link Here
1412
1412
1413
sub notice_email_address{
1413
sub notice_email_address{
1414
    my ( $self ) = @_;
1414
    my ( $self ) = @_;
1415
    my $address;
1416
    my $guarantor_address;
1415
1417
1416
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1418
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1417
    # if syspref is set to 'first valid' (value == OFF), look up email address
1419
    # if syspref is set to 'first valid' (value == OFF), look up email address
1418
    if ( $which_address eq 'OFF' ) {
1420
    if ( $which_address eq 'OFF' ) {
1419
        return $self->first_valid_email_address;
1421
        $address = $self->first_valid_email_address;
1422
    } else {
1423
        $address = $self->$which_address || '';
1420
    }
1424
    }
1421
1425
1422
    return $self->$which_address || '';
1426
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1427
    if ($use_guarantor) {
1428
        my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships();
1429
        if (@guarantors) {
1430
            foreach my $guarantor (@guarantors) {
1431
                if ( $which_address eq 'OFF' ) {
1432
                    $guarantor_address = $guarantor->first_valid_email_address;
1433
                } else {
1434
                    $guarantor_address = $guarantor->$which_address || '';
1435
                }
1436
                if ($address){
1437
                    $address .= ', ';
1438
                }
1439
                $address .=  $guarantor_address if $guarantor_address;
1440
            }
1441
        }
1442
    }
1443
    return $address;
1423
}
1444
}
1424
1445
1425
=head3 first_valid_email_address
1446
=head3 first_valid_email_address
(-)a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "12532",
5
    description => "Add new system preference RedirectGuaranteeEmail",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('RedirectGuaranteeEmail', '0', 'Enable the ability to redirect guarantee email messages to guarantor.', NULL, 'YesNo') });
11
12
        say $out "Added system preference 'RedirectGuaranteeEmail'";
13
    },
14
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 597-602 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
597
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
597
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
598
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
598
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
599
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
599
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
600
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
600
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
601
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
601
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
602
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
602
('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
603
('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 343-348 Patrons: Link Here
343
               1: Allow
343
               1: Allow
344
               0: "Don't allow"
344
               0: "Don't allow"
345
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
345
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
346
     -
347
         - pref: RedirectGuaranteeEmail
348
           choices:
349
               yes: Enable
350
               no: Disable
351
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
346
     -
352
     -
347
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
353
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
348
           choices:
354
           choices:
(-)a/t/db_dependent/Letters.t (+1 lines)
Lines 842-847 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
842
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
842
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
843
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
843
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
844
844
845
    t::lib::Mocks::mock_preference('RedirectGuaranteeEmail', '0');
845
    my $patron = Koha::Patrons->find($borrowernumber);
846
    my $patron = Koha::Patrons->find($borrowernumber);
846
    $dbh->do(q|
847
    $dbh->do(q|
847
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
848
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
(-)a/t/db_dependent/Members.t (-2 / +49 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 53;
20
use Test::More tests => 57;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 119-124 C4::Context->clear_syspref_cache(); Link Here
119
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
119
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
120
is ($checkcardnum, "2", "Card number is too long");
120
is ($checkcardnum, "2", "Card number is too long");
121
121
122
# Test notice_email_address
123
# Add Guarantor for testing
124
my $GUARANTOR_EMAIL = "Robert\@email.com";
125
%data = (
126
    cardnumber => "2997924548",
127
    firstname =>  "Robert",
128
    surname => "Tables",
129
    categorycode => $patron_category->{categorycode},
130
    branchcode => $BRANCHCODE,
131
    dateofbirth => '',
132
    dateexpiry => '9999-12-31',
133
    userid => 'bobbytables',
134
    email => $GUARANTOR_EMAIL
135
);
136
137
$addmem=Koha::Patron->new(\%data)->store->borrowernumber;
138
ok($addmem, "Koha::Patron->store()");
139
140
my $patron_guarantor = Koha::Patrons->find( { cardnumber => (\%data)->{'cardnumber'} } )
141
  or BAIL_OUT("Cannot read member with card (\%data)->{'cardnumber'}");
142
my $member_guarantor = $patron_guarantor->unblessed;
143
144
my %data2 = (
145
    guarantor_id => $member_guarantor->{borrowernumber},
146
    guarantee_id => $member->{borrowernumber},
147
    relationship => "father"
148
);
149
Koha::Patron::Relationship->new(\%data2)->store;
150
151
$member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } );
152
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
153
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
154
C4::Context->clear_syspref_cache();
155
156
my $notice_email = $member->notice_email_address;
157
is ($notice_email, $EMAIL, "notice_email_address returns correct value when EmailFieldPrimary is off");
158
159
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
160
C4::Context->clear_syspref_cache();
161
162
$notice_email = $member->notice_email_address;
163
is ($notice_email, $EMAILPRO, "notice_email_address returns correct value when EmailFieldPrimary is emailpro");
164
165
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
166
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
167
C4::Context->clear_syspref_cache();
168
$notice_email = $member->notice_email_address;
169
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "notice_email_address returns correct value when RedirectGuaranteeEmail is enabled");
122
170
123
# Add a new borrower
171
# Add a new borrower
124
%data = (
172
%data = (
125
- 

Return to bug 12532