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

(-)a/C4/Letters.pm (-2 / +6 lines)
Lines 1267-1280 sub _send_message_by_email { Link Here
1267
1267
1268
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1268
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1269
    my $to_address = $message->{'to_address'};
1269
    my $to_address = $message->{'to_address'};
1270
    unless ($to_address) {
1270
1271
        unless ($patron) {
1271
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1272
    if($use_garantor || !$to_address) {
1273
        unless ($patron and $to_address) {
1272
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1274
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1273
            _set_message_status( { message_id => $message->{'message_id'},
1275
            _set_message_status( { message_id => $message->{'message_id'},
1274
                                   status     => 'failed' } );
1276
                                   status     => 'failed' } );
1275
            return;
1277
            return;
1276
        }
1278
        }
1279
        if ($patron) {
1277
        $to_address = $patron->notice_email_address;
1280
        $to_address = $patron->notice_email_address;
1281
        }
1278
        unless ($to_address) {  
1282
        unless ($to_address) {  
1279
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1283
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1280
            # warning too verbose for this more common case?
1284
            # warning too verbose for this more common case?
(-)a/Koha/Patron.pm (-2 / +16 lines)
Lines 1027-1040 Returns the empty string if no email address. Link Here
1027
1027
1028
sub notice_email_address{
1028
sub notice_email_address{
1029
    my ( $self ) = @_;
1029
    my ( $self ) = @_;
1030
    my $address;
1030
1031
1031
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1032
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1032
    # if syspref is set to 'first valid' (value == OFF), look up email address
1033
    # if syspref is set to 'first valid' (value == OFF), look up email address
1033
    if ( $which_address eq 'OFF' ) {
1034
    if ( $which_address eq 'OFF' ) {
1034
        return $self->first_valid_email_address;
1035
        $address = $self->first_valid_email_address;
1036
    } else {
1037
        $address = $self->$which_address || '';
1035
    }
1038
    }
1036
1039
1037
    return $self->$which_address || '';
1040
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1041
    if ($use_guarantor) {
1042
        my $guarantor = $self->guarantor;
1043
        if ($guarantor) {
1044
            my $guarantor_address = $guarantor->notice_email_address;
1045
            if ($address){
1046
            $address .= ', ';
1047
            }
1048
            $address .=  $guarantor_address if $guarantor_address;
1049
        }
1050
    }
1051
    return $address;
1038
}
1052
}
1039
1053
1040
=head3 first_valid_email_address
1054
=head3 first_valid_email_address
(-)a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type)
2
VALUES ('RedirectGuaranteeEmail','0',NULL,'Enable the ability to redirect guarantee email messages to guarantor.','YesNo');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 486-491 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
486
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
486
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
487
('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'),
487
('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'),
488
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
488
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
489
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
489
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
490
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
490
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
491
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
491
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
492
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 220-225 Patrons: Link Here
220
         - pref: FailedLoginAttempts
220
         - pref: FailedLoginAttempts
221
           class: integer
221
           class: integer
222
         - failed login attempts.
222
         - failed login attempts.
223
     -
224
         - pref: RedirectGuaranteeEmail
225
           choices:
226
               yes: Enable
227
               no: Disable
228
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
223
     -
229
     -
224
         - pref: ProtectSuperlibrarianPrivileges
230
         - pref: ProtectSuperlibrarianPrivileges
225
           choices:
231
           choices:
(-)a/t/db_dependent/Members.t (-2 / +38 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 47;
20
use Test::More tests => 50;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 121-126 C4::Context->clear_syspref_cache(); Link Here
121
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
121
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
122
is ($checkcardnum, "2", "Card number is too long");
122
is ($checkcardnum, "2", "Card number is too long");
123
123
124
# Test notice_email_address
125
# Add Guarantor for testing
126
my $GUARANTOR_EMAIL = "Robert\@email.com";
127
%data = (
128
    cardnumber => "2997924548",
129
    firstname =>  "Robert",
130
    surname => "Tables",
131
    categorycode => $patron_category->{categorycode},
132
    branchcode => $BRANCHCODE,
133
    dateofbirth => '',
134
    dateexpiry => '9999-12-31',
135
    userid => 'bobbytables',
136
    email => $GUARANTOR_EMAIL
137
);
138
139
$member->{guarantorid} = Koha::Patron->new(\%data)->store->borrowernumber;
140
$patron->set($member)->store;
141
142
$member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } );
143
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
144
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
145
C4::Context->clear_syspref_cache();
146
147
my $notice_email = $member->notice_email_address;
148
is ($notice_email, $EMAIL, "notice_email_address returns correct value when AutoEmailPrimaryAddress is off");
149
150
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
151
C4::Context->clear_syspref_cache();
152
153
$notice_email = $member->notice_email_address;
154
is ($notice_email, $EMAILPRO, "notice_email_address returns correct value when AutoEmailPrimaryAddress is emailpro");
155
156
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
157
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
158
C4::Context->clear_syspref_cache();
159
$notice_email = $member->notice_email_address;
160
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "notice_email_address returns correct value when RedirectGuaranteeEmail is enabled");
124
161
125
# Add a new borrower
162
# Add a new borrower
126
%data = (
163
%data = (
127
- 

Return to bug 12532