From a951e6d131536d26f3e00677d9f526001146841c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 28 Apr 2022 16:12:47 +0100 Subject: [PATCH] Bug 30646: Add welcome email support to SAML2 This patch adds the ability to enable the welcome email notice for new users added via the Shibboleth autocreate option. Test plan 1) Configure Shibboleth for authentication 2) Enable the welcome email by adding '1' to your shibboleth config block 3) Confirm you have autocreate enabled for your Shibboleth config 4) Attempt to login with an entirely new user to Koha using the shibboleth connection (with a user who has a valid email address mapped to Koha borrower fields) 5) Confirm the email is sent by looking at the notices for the new user. Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Auth_with_shibboleth.pm | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/C4/Auth_with_shibboleth.pm b/C4/Auth_with_shibboleth.pm index 5a46737c59..8801530857 100644 --- a/C4/Auth_with_shibboleth.pm +++ b/C4/Auth_with_shibboleth.pm @@ -23,6 +23,7 @@ use C4::Context; use Koha::AuthUtils qw( get_script_name ); use Koha::Database; use Koha::Patrons; +use C4::Letters qw( GetPreparedLetter EnqueueLetter ); use C4::Members::Messaging; use Carp qw( carp ); use List::MoreUtils qw( any ); @@ -134,8 +135,42 @@ sub _autocreate { } my $patron = Koha::Patron->new( \%borrower )->store; - C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $patron->borrowernumber, categorycode => $patron->categorycode } ); - + C4::Members::Messaging::SetMessagingPreferencesFromDefaults( + { + borrowernumber => $patron->borrowernumber, + categorycode => $patron->categorycode + } + ); + + # Send welcome email if enabled + if ( $config->{welcome} ) { + my $emailaddr = $patron->notice_email_address; + + # if we manage to find a valid email address, send notice + if ($emailaddr) { + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'WELCOME', + branchcode => $patron->branchcode, + , + lang => $patron->lang || 'default', + tables => { + 'branches' => $patron->branchcode, + 'borrowers' => $patron->borrowernumber, + }, + want_librarian => 1, + ) or return; + + my $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->id, + to_address => $emailaddr, + message_transport_type => 'email' + } + ); + } + } return ( 1, $patron->cardnumber, $patron->userid ); } -- 2.39.5