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

(-)a/C4/Letters.pm (-1 / +3 lines)
Lines 1267-1273 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
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1272
    if($use_garantor || !$to_address) {
1271
        unless ($patron) {
1273
        unless ($patron) {
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'},
(-)a/Koha/Patron.pm (-2 / +16 lines)
Lines 1003-1016 Returns the empty string if no email address. Link Here
1003
1003
1004
sub notice_email_address{
1004
sub notice_email_address{
1005
    my ( $self ) = @_;
1005
    my ( $self ) = @_;
1006
    my $address;
1006
1007
1007
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1008
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1008
    # if syspref is set to 'first valid' (value == OFF), look up email address
1009
    # if syspref is set to 'first valid' (value == OFF), look up email address
1009
    if ( $which_address eq 'OFF' ) {
1010
    if ( $which_address eq 'OFF' ) {
1010
        return $self->first_valid_email_address;
1011
        $address = $self->first_valid_email_address;
1012
    } else {
1013
        $address = $self->$which_address || '';
1011
    }
1014
    }
1012
1015
1013
    return $self->$which_address || '';
1016
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1017
    if ($use_guarantor) {
1018
        my $guarantor = $self->guarantor;
1019
        if ($guarantor) {
1020
            my $guarantor_address = $guarantor->notice_email_address;
1021
            if ($address){
1022
            $address .= ', ';
1023
            }
1024
            $address .=  $guarantor_address if $guarantor_address;
1025
        }
1026
    }
1027
    return $address;
1014
}
1028
}
1015
1029
1016
=head3 first_valid_email_address
1030
=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 474-479 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
474
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
474
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
475
('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'),
475
('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'),
476
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
476
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
477
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
477
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
478
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
478
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
479
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
479
('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'),
480
('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