Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip_verified_email_extension #537

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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