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

(-)a/C4/Letters.pm (-1 / +3 lines)
Lines 1258-1264 sub _send_message_by_email { Link Here
1258
1258
1259
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1259
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1260
    my $to_address = $message->{'to_address'};
1260
    my $to_address = $message->{'to_address'};
1261
    unless ($to_address) {
1261
1262
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1263
    if($use_garantor || !$to_address) {
1262
        unless ($patron) {
1264
        unless ($patron) {
1263
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1265
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1264
            _set_message_status( { message_id => $message->{'message_id'},
1266
            _set_message_status( { message_id => $message->{'message_id'},
(-)a/Koha/Patron.pm (-2 / +16 lines)
Lines 982-995 Returns the empty string if no email address. Link Here
982
982
983
sub notice_email_address{
983
sub notice_email_address{
984
    my ( $self ) = @_;
984
    my ( $self ) = @_;
985
    my $address;
985
986
986
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
987
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
987
    # if syspref is set to 'first valid' (value == OFF), look up email address
988
    # if syspref is set to 'first valid' (value == OFF), look up email address
988
    if ( $which_address eq 'OFF' ) {
989
    if ( $which_address eq 'OFF' ) {
989
        return $self->first_valid_email_address;
990
        $address = $self->first_valid_email_address;
991
    } else {
992
        $address = $self->$which_address || '';
990
    }
993
    }
991
994
992
    return $self->$which_address || '';
995
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
996
    if ($use_guarantor) {
997
        my $guarantor = $self->guarantor;
998
        if ($guarantor) {
999
            my $guarantor_address = $guarantor->notice_email_address;
1000
            if ($address){
1001
            $address .= ', ';
1002
            }
1003
            $address .=  $guarantor_address if $guarantor_address;
1004
        }
1005
    }
1006
    return $address;
993
}
1007
}
994
1008
995
=head3 first_valid_email_address
1009
=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 459-464 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
459
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
459
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
460
('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'),
460
('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'),
461
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
461
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
462
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
462
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
463
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
463
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
464
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
464
('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'),
465
('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 208-213 Patrons: Link Here
208
           class: integer
208
           class: integer
209
         - failed login attempts.
209
         - failed login attempts.
210
     -
210
     -
211
         - pref: RedirectGuaranteeEmail
212
           choices:
213
               yes: Enable
214
               no: Disable
215
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
216
     -
211
         - pref: ProtectSuperlibrarianPrivileges
217
         - pref: ProtectSuperlibrarianPrivileges
212
           choices:
218
           choices:
213
               yes: Allow only superlibrarians
219
               yes: Allow only superlibrarians
(-)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 138-143 C4::Context->clear_syspref_cache(); Link Here
138
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
138
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
139
is ($checkcardnum, "2", "Card number is too long");
139
is ($checkcardnum, "2", "Card number is too long");
140
140
141
# Test notice_email_address
142
# Add Guarantor for testing
143
my $GUARANTOR_EMAIL = "Robert\@email.com";
144
%data = (
145
    cardnumber => "2997924548",
146
    firstname =>  "Robert",
147
    surname => "Tables",
148
    categorycode => $patron_category->{categorycode},
149
    branchcode => $BRANCHCODE,
150
    dateofbirth => '',
151
    dateexpiry => '9999-12-31',
152
    userid => 'bobbytables',
153
    email => $GUARANTOR_EMAIL
154
);
155
156
$member->{guarantorid} = Koha::Patron->new(\%data)->store->borrowernumber;
157
$patron->set($member)->store;
158
159
$member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } );
160
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
161
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
162
C4::Context->clear_syspref_cache();
163
164
my $notice_email = $member->notice_email_address;
165
is ($notice_email, $EMAIL, "notice_email_address returns correct value when AutoEmailPrimaryAddress is off");
166
167
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
168
C4::Context->clear_syspref_cache();
169
170
$notice_email = $member->notice_email_address;
171
is ($notice_email, $EMAILPRO, "notice_email_address returns correct value when AutoEmailPrimaryAddress is emailpro");
172
173
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
174
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
175
C4::Context->clear_syspref_cache();
176
$notice_email = $member->notice_email_address;
177
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "notice_email_address returns correct value when RedirectGuaranteeEmail is enabled");
141
178
142
# Add a new borrower
179
# Add a new borrower
143
%data = (
180
%data = (
144
- 

Return to bug 12532