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 1470-1475 sub _send_message_by_email { Link Here
1470
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1473
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1471
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1474
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1472
1475
1476
    _update_message_from_address($message->{'message_id'},$email->email->header('From') )
1477
      if !$message->{from_address}
1478
      || $message->{from_address} ne $email->email->header('From');
1479
1473
    try {
1480
    try {
1474
        $email->send_or_die({ transport => $smtp_transport });
1481
        $email->send_or_die({ transport => $smtp_transport });
1475
1482
(-)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 1428-1441 Returns the empty string if no email address. Link Here
1428
1428
1429
sub notice_email_address{
1429
sub notice_email_address{
1430
    my ( $self ) = @_;
1430
    my ( $self ) = @_;
1431
    my $address;
1432
    my $guarantor_address;
1431
1433
1432
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1434
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1433
    # if syspref is set to 'first valid' (value == OFF), look up email address
1435
    # if syspref is set to 'first valid' (value == OFF), look up email address
1434
    if ( $which_address eq 'OFF' ) {
1436
    if ( $which_address eq 'OFF' ) {
1435
        return $self->first_valid_email_address;
1437
        $address = $self->first_valid_email_address;
1438
    } else {
1439
        $address = $self->$which_address || '';
1436
    }
1440
    }
1437
1441
1438
    return $self->$which_address || '';
1442
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1443
    if ($use_guarantor) {
1444
        my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships();
1445
        if (@guarantors) {
1446
            foreach my $guarantor (@guarantors) {
1447
                if ( $which_address eq 'OFF' ) {
1448
                    $guarantor_address = $guarantor->first_valid_email_address;
1449
                } else {
1450
                    $guarantor_address = $guarantor->$which_address || '';
1451
                }
1452
                if ($address){
1453
                    $address .= ', ';
1454
                }
1455
                $address .=  $guarantor_address if $guarantor_address;
1456
            }
1457
        }
1458
    }
1459
    return $address;
1439
}
1460
}
1440
1461
1441
=head3 first_valid_email_address
1462
=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 602-607 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
602
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
602
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
603
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
603
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
604
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
604
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
605
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
605
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
606
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
606
('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'),
607
('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'),
607
('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'),
608
('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 357-362 Patrons: Link Here
357
               1: Allow
357
               1: Allow
358
               0: "Don't allow"
358
               0: "Don't allow"
359
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
359
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
360
     -
361
         - pref: RedirectGuaranteeEmail
362
           choices:
363
               yes: Enable
364
               no: Disable
365
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
360
     -
366
     -
361
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
367
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
362
           choices:
368
           choices:
(-)a/t/db_dependent/Letters.t (+1 lines)
Lines 869-874 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
871
871
872
    t::lib::Mocks::mock_preference('RedirectGuaranteeEmail', '0');
872
    my $patron = Koha::Patrons->find($borrowernumber);
873
    my $patron = Koha::Patrons->find($borrowernumber);
873
    $dbh->do(q|
874
    $dbh->do(q|
874
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
875
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
(-)a/t/db_dependent/Members.t (-14 / +47 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 50;
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 101-121 ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME && Link Here
101
     , "Member Changed")
101
     , "Member Changed")
102
  or diag("Mismatching member details: ".Dumper($member, $changedmember));
102
  or diag("Mismatching member details: ".Dumper($member, $changedmember));
103
103
104
# Add a new borrower
104
# Test notice_email_address
105
# Add Guarantor for testing
106
my $GUARANTOR_EMAIL = "Robert\@email.com";
105
%data = (
107
%data = (
106
    cardnumber   => "123456789",
108
    cardnumber => "2997924548",
107
    firstname    => "Tomasito",
109
    firstname =>  "Robert",
108
    surname      => "None",
110
    surname => "Tables",
109
    categorycode => $patron_category->{categorycode},
111
    categorycode => $patron_category->{categorycode},
110
    branchcode   => $library2->{branchcode},
112
    branchcode => $BRANCHCODE,
111
    dateofbirth  => '',
113
    dateofbirth => '',
112
    debarred     => '',
114
    dateexpiry => '9999-12-31',
113
    dateexpiry   => '',
115
    userid => 'bobbytables',
114
    dateenrolled => '',
116
    email => $GUARANTOR_EMAIL
115
);
117
);
116
my $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
118
117
$patron = Koha::Patrons->find( $borrowernumber );
119
$addmem=Koha::Patron->new(\%data)->store->borrowernumber;
118
my $borrower = $patron->unblessed;
120
ok($addmem, "Koha::Patron->store()");
121
122
my $patron_guarantor = Koha::Patrons->find( { cardnumber => (\%data)->{'cardnumber'} } )
123
  or BAIL_OUT("Cannot read member with card (\%data)->{'cardnumber'}");
124
my $member_guarantor = $patron_guarantor->unblessed;
125
126
my %data2 = (
127
    guarantor_id => $member_guarantor->{borrowernumber},
128
    guarantee_id => $member->{borrowernumber},
129
    relationship => "father"
130
);
131
Koha::Patron::Relationship->new(\%data2)->store;
132
133
$member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } );
134
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
135
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
136
C4::Context->clear_syspref_cache();
137
138
my $notice_email = $member->notice_email_address;
139
is ($notice_email, $EMAIL, "notice_email_address returns correct value when EmailFieldPrimary is off");
140
141
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
142
C4::Context->clear_syspref_cache();
143
144
$notice_email = $member->notice_email_address;
145
is ($notice_email, $EMAILPRO, "notice_email_address returns correct value when EmailFieldPrimary is emailpro");
146
147
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
148
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
149
C4::Context->clear_syspref_cache();
150
$notice_email = $member->notice_email_address;
151
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "notice_email_address returns correct value when RedirectGuaranteeEmail is enabled");
152
119
is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given');
153
is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given');
120
is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given');
154
is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given');
121
isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given');
155
isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given');
122
- 

Return to bug 12532