From 45cfcd16ed8682a0e0b85fe7c5cb648f3616bd0b Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 29 Aug 2023 17:44:42 +0300 Subject: [PATCH] handle email that are already verified --- app/Model/CoPetition.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Model/CoPetition.php b/app/Model/CoPetition.php index 00d85d35c..bb3934acd 100644 --- a/app/Model/CoPetition.php +++ b/app/Model/CoPetition.php @@ -2809,6 +2809,8 @@ public function sendConfirmation($id, $actorCoPersonId) { // Org Identities). $toEmail = null; + $hasOrgEmail = false; + $hasPersonEmail = false; $coPersonEmail = false; if(!empty($pt['EnrolleeOrgIdentity']['EmailAddress']) @@ -2816,6 +2818,7 @@ public function sendConfirmation($id, $actorCoPersonId) { // associated EmailAddress, so skip this OrgIdentity && empty($pt['EnrolleeOrgIdentity']['OrgIdentitySourceRecord'])) { foreach($pt['EnrolleeOrgIdentity']['EmailAddress'] as $ea) { + $hasOrgEmail = true; if(!$ea['verified']) { // Use this address $toEmail = $ea; @@ -2829,6 +2832,7 @@ public function sendConfirmation($id, $actorCoPersonId) { if(!empty($pt['EnrolleeCoPerson']['EmailAddress'])) { foreach($pt['EnrolleeCoPerson']['EmailAddress'] as $ea) { + $hasPersonEmail = true; if(!$ea['verified']) { // Use this address $toEmail = $ea; @@ -2873,8 +2877,17 @@ public function sendConfirmation($id, $actorCoPersonId) { } } + // The email has already been verified + $is_verified = false; + if($email_verification_mode === VerificationModeEnum::SkipIfVerified + && ($hasOrgEmail && $hasPersonEmail) + && empty($toEmail)) { + // We already have a verified email so skip the invitation. + $is_verified = true; + } + // Should we proceed with Email Confirmation or not? - if(!$toEmail) { + if(!$toEmail && !$is_verified) { throw new RuntimeException(_txt('er.pt.mail', array(!empty($pt['EnrolleeCoPerson']['PrimaryName']) ? generateCn($pt['EnrolleeCoPerson']['PrimaryName']) @@ -2920,7 +2933,7 @@ public function sendConfirmation($id, $actorCoPersonId) { $coInviteId = $this->CoInvite->send($pt['CoPetition']['enrollee_co_person_id'], $pt['CoPetition']['enrollee_org_identity_id'], $actorCoPersonId, - $toEmail['mail'], + $is_verified ? "" : $toEmail['mail'], $ef['CoEnrollmentFlow']['notify_from'], $ef['Co']['name'], $subject, @@ -2931,7 +2944,7 @@ public function sendConfirmation($id, $actorCoPersonId) { $bcc, $subs, $format, - $skip_invite); + ($skip_invite || $is_verified) ); // Add the invite ID to the petition record @@ -2944,14 +2957,14 @@ public function sendConfirmation($id, $actorCoPersonId) { $this->CoPetitionHistoryRecord->record($id, $actorCoPersonId, PetitionActionEnum::InviteSent, - _txt('rs.inv.sent', array($toEmail['mail']))); + _txt('rs.inv.sent', array($is_verified ? "" : $toEmail['mail']))); } catch(Exception $e) { $dbc->rollback(); throw new RuntimeException(_txt('er.db.save-a', array('CoPetitionHistoryRecord'))); } - return $toEmail['mail']; + return $is_verified ? "" : $toEmail['mail']; } /**