Skip to content

Commit

Permalink
handle email that are already verified
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Feb 9, 2024
1 parent d8bec8c commit 5e40175
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/Model/CoPetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -2820,13 +2820,16 @@ public function sendConfirmation($id, $actorCoPersonId) {
// Org Identities).

$toEmail = null;
$hasOrgEmail = false;
$hasPersonEmail = false;
$coPersonEmail = false;

if(!empty($pt['EnrolleeOrgIdentity']['EmailAddress'])
// If there's an OrgIdentitySourceRecord we can't write to any
// 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;
Expand All @@ -2840,6 +2843,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;
Expand Down Expand Up @@ -2884,8 +2888,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'])
Expand Down Expand Up @@ -2931,7 +2944,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,
Expand All @@ -2942,7 +2955,7 @@ public function sendConfirmation($id, $actorCoPersonId) {
$bcc,
$subs,
$format,
$skip_invite);
($skip_invite || $is_verified) );

// Add the invite ID to the petition record

Expand All @@ -2955,14 +2968,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'];
}

/**
Expand Down

0 comments on commit 5e40175

Please sign in to comment.