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

(-)a/C4/Letters.pm (-4 / +4 lines)
Lines 1288-1305 sub _send_message_by_email { Link Here
1288
    my ($username, $password, $method) = @_;
1288
    my ($username, $password, $method) = @_;
1289
1289
1290
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1290
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1291
    my $useGurantor = $member && $member->{'guarantorid'} && C4::Context->preference("EnableRedirectGuaranteeEmail");
1291
    my $to_address = $message->{'to_address'};
1292
    my $to_address = $message->{'to_address'};
1292
    unless ($to_address) {
1293
    if ($useGurantor || !$to_address) {
1293
        unless ($member) {
1294
        unless ($member) {
1294
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1295
            warn "FAIL: INVALID borrowernumber ($message->{borrowernumber})";
1295
            _set_message_status( { message_id => $message->{'message_id'},
1296
            _set_message_status( { message_id => $message->{'message_id'},
1296
                                   status     => 'failed' } );
1297
                                   status     => 'failed' } );
1297
            return;
1298
            return;
1298
        }
1299
        }
1299
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1300
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1300
        unless ($to_address) {  
1301
        unless ($to_address) {  
1301
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1302
            warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1302
            # warning too verbose for this more common case?
1303
            _set_message_status( { message_id => $message->{'message_id'},
1303
            _set_message_status( { message_id => $message->{'message_id'},
1304
                                   status     => 'failed' } );
1304
                                   status     => 'failed' } );
1305
            return;
1305
            return;
(-)a/C4/Members.pm (-14 / +13 lines)
Lines 1001-1022 Returns the empty string if no email address. Link Here
1001
1001
1002
sub GetNoticeEmailAddress {
1002
sub GetNoticeEmailAddress {
1003
    my $borrowernumber = shift;
1003
    my $borrowernumber = shift;
1004
    my $member = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
1005
1006
    #  Determine who we send the email to.
1007
    my $guarantorid = $member->{'guarantorid'};
1008
    my $useGuarantor = $guarantorid && C4::Context->preference("EnableRedirectGuaranteeEmail");
1009
1010
    my $guarantor =  C4::Members::GetMember( 'borrowernumber' => $guarantorid ) if $useGuarantor;
1004
1011
1005
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1006
    # if syspref is set to 'first valid' (value == OFF), look up email address
1012
    # if syspref is set to 'first valid' (value == OFF), look up email address
1007
    if ( $which_address eq 'OFF' ) {
1013
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1008
        return GetFirstValidEmailAddress($borrowernumber);
1014
    my $to_address = $which_address eq 'OFF' ? GetFirstValidEmailAddress($member->{'borrowernumber'}) : $member->{ $which_address };
1009
    }
1015
    my $guarantor_to_address = $which_address eq 'OFF' ? GetFirstValidEmailAddress($guarantor->{'borrowernumber'}) : $guarantor->{ $which_address } if $guarantor;
1010
    # specified email address field
1016
    $to_address .="," . $guarantor_to_address if $guarantor_to_address;
1011
    my $dbh = C4::Context->dbh;
1017
1012
    my $sth = $dbh->prepare( qq{
1018
   return $to_address || '';
1013
        SELECT $which_address AS primaryemail
1014
        FROM borrowers
1015
        WHERE borrowernumber=?
1016
    } );
1017
    $sth->execute($borrowernumber);
1018
    my $data = $sth->fetchrow_hashref;
1019
    return $data->{'primaryemail'} || '';
1020
}
1019
}
1021
1020
1022
=head2 GetBorrowersToExpunge
1021
=head2 GetBorrowersToExpunge
(-)a/installer/data/mysql/atomicupdate/bug_12532-EnableRedirectGuaranteeEmail_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 145-150 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
145
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
145
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
146
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
146
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
147
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
147
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
148
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
148
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
149
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
149
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
150
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
150
('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'),
151
('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 191-196 Patrons: Link Here
191
               no: "Don't"
191
               no: "Don't"
192
         - track last patron activity.
192
         - track last patron activity.
193
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
193
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
194
     -
195
         - pref: RedirectGuaranteeEmail
196
           choices:
197
               yes: Enable
198
               no: "Don't enable"
199
         - redirection of guarantee email messages to the guarantor. All email messages send via the message_queue table will be affected.
194
    "Norwegian patron database":
200
    "Norwegian patron database":
195
     -
201
     -
196
         - pref: NorwegianPatronDBEnable
202
         - pref: NorwegianPatronDBEnable
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-1 lines)
Lines 77-83 $(document).ready(function() { Link Here
77
            $("#entryform").submit();
77
            $("#entryform").submit();
78
        }
78
        }
79
    });
79
    });
80
81
});
80
});
82
81
83
        var MSG_SEPARATOR = _("Separator must be / in field %s");
82
        var MSG_SEPARATOR = _("Separator must be / in field %s");
(-)a/t/db_dependent/Letters.t (+55 lines)
Lines 148-153 is( $resent, 0, 'The message should not have been resent again' ); Link Here
148
$resent = C4::Letters::ResendMessage();
148
$resent = C4::Letters::ResendMessage();
149
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
149
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
150
150
151
#Test guarantee-guarantor email redirection
152
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |;
153
my $guarantor = {
154
    email        => $GUARANTOR_EMAIL,
155
    categorycode => 'PT',
156
    branchcode   => 'CPL',
157
    surname      => "Guarantor"
158
};
159
$guarantor->{'borrowernumber'} = AddMember(%$guarantor);
160
my $guarantee = {
161
    guarantorid  => $guarantor->{'borrowernumber'},
162
    email        => $GUARANTEE_EMAIL,
163
    categorycode => 'PT',
164
    branchcode   => 'CPL',
165
    surname      => "Guarantee"
166
};
167
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
168
169
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com';
170
my $guarantee_message = {
171
    borrowernumber         => $guarantee->{'borrowernumber'},
172
    message_transport_type => 'email',
173
    to_address             => $GUARANTEE_TO_ADDRESS,
174
    from_address           => 'from@example.com',
175
    letter                 => $my_message->{'letter'}
176
};
177
178
sub SendToGuarantor {
179
    my ($useGuarantor, $message) = @_;
180
    C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
181
    C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor );
182
    C4::Context->clear_syspref_cache();
183
    my $id = C4::Letters::EnqueueLetter($message);
184
    C4::Letters::SendQueuedMessages();
185
    my $result = $dbh->selectrow_hashref( 'SELECT to_address, status FROM message_queue WHERE message_id = ?', undef, ($id) );
186
    return $result;
187
}
188
my $result = SendToGuarantor(0,$guarantee_message);
189
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent.");
190
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address.");
191
192
$result = SendToGuarantor(1,$guarantee_message);
193
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail on, message is sent.");
194
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With EnableRedirectGuaranteeEmail on, Message is sent to the guarantor's email address.");
195
196
$guarantor->{'email'} = undef;
197
ModMember(%$guarantor);
198
$result = SendToGuarantor(1,$guarantee_message);
199
is($result->{'status'}, "failed", "With EnableRedirectGuaranteeEmail on, message fails if guarantor has no address.");
200
201
$guarantee->{'guarantorid'} = undef;
202
ModMember(%$guarantee);
203
$result = SendToGuarantor(1,$guarantee_message);
204
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail on, Message is sent to specicied to_address if he has no guarantor.");
205
151
# GetLetters
206
# GetLetters
152
my $letters = C4::Letters::GetLetters();
207
my $letters = C4::Letters::GetLetters();
153
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
208
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
(-)a/t/db_dependent/Members.t (-1 / +44 lines)
Lines 139-144 is ($checkcardnum, "2", "Card number is too long"); Link Here
139
139
140
140
141
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
141
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
142
143
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 0 );
144
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
142
C4::Context->clear_syspref_cache();
145
C4::Context->clear_syspref_cache();
143
146
144
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
147
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
Lines 150-155 C4::Context->clear_syspref_cache(); Link Here
150
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
153
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
151
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
154
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
152
155
156
#Test guarantee-guarantor email redirection
157
my $GUARANTEE_EMAIL = 'guanrantee@email.test';
158
my $guarantee = {
159
    guarantorid  => $member->{'borrowernumber'},
160
    emailpro     => $GUARANTEE_EMAIL,
161
    categorycode => $CATEGORYCODE,
162
    branchcode   => $BRANCHCODE,
163
    surname      => "surname"
164
};
165
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
166
167
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
168
is ($notice_email, $GUARANTEE_EMAIL, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is disabled");
169
170
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 1 );
171
C4::Context->clear_syspref_cache();
172
173
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
174
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is activated");
175
176
177
ok(!$member->{is_expired}, "GetMemberDetails() indicates that patron is not expired");
178
ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01-1');
179
$member = GetMemberDetails($member->{'borrowernumber'});
180
ok($member->{is_expired}, "GetMemberDetails() indicates that patron is expired");
181
182
# Create a reserve for the patron
183
$builder->build({
184
    source => 'Reserve',
185
    value  => {
186
        borrowernumber => $member->{ borrowernumber }
187
    }
188
});
189
is( Koha::Holds->search({ borrowernumber => $member->{borrowernumber} })->count,
190
    1, 'Hold created correctly' );
191
DelMember($member->{borrowernumber});
192
my $borrower = GetMember( cardnumber => $CARDNUMBER );
193
is( $borrower, undef, 'DelMember should remove the patron' );
194
is( Koha::Holds->search({ borrowernumber => $member->{borrowernumber} })->count,
195
    0, 'Hold deleted correctly' );
196
153
# Check_Userid tests
197
# Check_Userid tests
154
%data = (
198
%data = (
155
    cardnumber   => "123456789",
199
    cardnumber   => "123456789",
156
- 

Return to bug 12532