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 Sep 13, 2023
1 parent c545cf3 commit 45cfcd1
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 @@ -2809,13 +2809,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 @@ -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;
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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'];
}

/**
Expand Down

0 comments on commit 45cfcd1

Please sign in to comment.