Skip to content

Commit

Permalink
GFORMS-3085 - Clear verified code if email changed (#2355)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmanson authored Dec 20, 2024
1 parent 1a57956 commit 25bceb5
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions app/uk/gov/hmrc/gform/gform/processor/FormProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ import uk.gov.hmrc.gform.api.{ BankAccountInsightsConnector, CompanyInformationC
import uk.gov.hmrc.gform.bars.BankAccountReputationConnector
import uk.gov.hmrc.gform.controllers.AuthCacheWithForm
import uk.gov.hmrc.gform.eval.FileIdsWithMapping
import uk.gov.hmrc.gform.eval.smartstring.{ RealSmartStringEvaluatorFactory, SmartStringEvaluationSyntax, SmartStringEvaluatorFactory }
import uk.gov.hmrc.gform.eval.smartstring.SmartStringEvaluator
import uk.gov.hmrc.gform.objectStore.{ EnvelopeWithMapping, ObjectStoreAlgebra }
import uk.gov.hmrc.gform.eval.smartstring.{ RealSmartStringEvaluatorFactory, SmartStringEvaluationSyntax, SmartStringEvaluator, SmartStringEvaluatorFactory }
import uk.gov.hmrc.gform.gform.handlers.FormControllerRequestHandler
import uk.gov.hmrc.gform.gform.{ DataRetrieveService, FastForwardService, FileSystemConnector, routes }
import uk.gov.hmrc.gform.gformbackend.GformConnector
import uk.gov.hmrc.gform.graph.Recalculation
import uk.gov.hmrc.gform.models._
import uk.gov.hmrc.gform.models.gform.{ FormValidationOutcome, NoSpecificAction }
import uk.gov.hmrc.gform.models.ids.{ ModelComponentId, ModelPageId }
import uk.gov.hmrc.gform.models.optics.DataOrigin.Mongo
import uk.gov.hmrc.gform.models.optics.DataOrigin.{ Browser, Mongo }
import uk.gov.hmrc.gform.models.optics.{ DataOrigin, FormModelVisibilityOptics }
import uk.gov.hmrc.gform.objectStore.{ EnvelopeWithMapping, ObjectStoreAlgebra }
import uk.gov.hmrc.gform.sharedmodel._
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormModelOptics, TaskIdTaskStatusMapping, ThirdPartyData, VisitIndex }
import uk.gov.hmrc.gform.sharedmodel.form._
import uk.gov.hmrc.gform.sharedmodel.formtemplate.SectionTitle4Ga.sectionTitle4GaFactory
import uk.gov.hmrc.gform.sharedmodel.formtemplate._
import uk.gov.hmrc.gform.tasklist.TaskListUtils
Expand Down Expand Up @@ -406,7 +405,11 @@ class FormProcessor(
} else TaskIdTaskStatusMapping.empty.pure[Future]

res <- {
val oldData: VariadicFormData[SourceOrigin.Current] = processData.formModelOptics.pageOpticsData
val oldData: VariadicFormData[SourceOrigin.Current] = maybeRemoveVerifiedCode(
validatorsResult,
formModelVisibilityOptics,
processData.formModelOptics.pageOpticsData
)

val formDataU = oldData.toFormData ++ formData
val updatedThirdPartyData: ThirdPartyData = cache.form.thirdPartyData
Expand Down Expand Up @@ -494,4 +497,26 @@ class FormProcessor(
smartStringEvaluatorFactory(DataOrigin.swapDataOrigin(formModelVisibilityOptics))(messages, LangADT.En)
sectionTitle4GaFactory(processData.formModel(sectionNumber), sectionNumber)(sse)
}

private def maybeRemoveVerifiedCode(
validatorsResult: Option[ValidatorsResult],
formModelVisibilityOptics: FormModelVisibilityOptics[Browser],
oldData: VariadicFormData[SourceOrigin.Current]
): VariadicFormData[SourceOrigin.Current] = {
val maybeVerifiedBy: Option[FormComponentId] = validatorsResult.flatMap { result =>
result.emailVerification.keySet
.flatMap { emailFieldId =>
formModelVisibilityOptics.formModel.allFormComponents
.collectFirst {
case IsEmailVerifier(emailId, emailVerifiedBy)
if emailId.baseComponentId === emailFieldId.baseComponentId =>
emailVerifiedBy.formComponentId
}
}
.toList
.headOption
}

maybeVerifiedBy.map(fcId => oldData - fcId.modelComponentId).getOrElse(oldData)
}
}

0 comments on commit 25bceb5

Please sign in to comment.