-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIS-7016 Add command and event for Resend Verification email (#494)
* APIS-7016 Add new command ResendRequesterEmailVerification handler etc * APIS-7016 Add new command ResendRequesterEmailVerification handler etc * APIS-7016 Add new command ResendRequesterEmailVerification handler etc * APIS-7016 Add new command ResendRequesterEmailVerification handler etc * APIS-7016 Add new command ResendRequesterEmailVerification handler etc * APIS-7016 Add new command ResendRequesterEmailVerification handler etc
- Loading branch information
1 parent
e4f66af
commit 0f48391
Showing
14 changed files
with
362 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ication/services/commands/submission/ResendRequesterEmailVerificationCommandHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.thirdpartyapplication.services.commands.submission | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import cats.Apply | ||
import cats.data.{NonEmptyList, Validated} | ||
import cats.syntax.validated._ | ||
|
||
import uk.gov.hmrc.apiplatform.modules.common.domain.models.{Actors, LaxEmailAddress} | ||
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.ApplicationCommands.ResendRequesterEmailVerification | ||
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.{CommandFailure, CommandFailures} | ||
import uk.gov.hmrc.apiplatform.modules.events.applications.domain.models.ApplicationEvents._ | ||
import uk.gov.hmrc.apiplatform.modules.events.applications.domain.models._ | ||
import uk.gov.hmrc.apiplatform.modules.submissions.domain.models._ | ||
import uk.gov.hmrc.apiplatform.modules.submissions.services.SubmissionsService | ||
import uk.gov.hmrc.thirdpartyapplication.models.db.StoredApplication | ||
import uk.gov.hmrc.thirdpartyapplication.services.commands.CommandHandler | ||
|
||
@Singleton | ||
class ResendRequesterEmailVerificationCommandHandler @Inject() ( | ||
submissionService: SubmissionsService | ||
)(implicit val ec: ExecutionContext | ||
) extends CommandHandler { | ||
|
||
import CommandHandler._ | ||
import CommandFailures._ | ||
|
||
private def validate(app: StoredApplication): Future[Validated[Failures, (LaxEmailAddress, String, Submission)]] = { | ||
|
||
def checkSubmission(maybeSubmission: Option[Submission]): Validated[Failures, Submission] = { | ||
lazy val fails: CommandFailure = GenericFailure(s"No submission found for application ${app.id.value}") | ||
maybeSubmission.fold(fails.invalidNel[Submission])(_.validNel[CommandFailure]) | ||
} | ||
|
||
submissionService.fetchLatest(app.id).map { maybeSubmission => | ||
Apply[Validated[Failures, *]].map6( | ||
isStandardNewJourneyApp(app), | ||
isPendingRequesterVerification(app), | ||
ensureRequesterEmailDefined(app), | ||
ensureRequesterNameDefined(app), | ||
ensureVerificationCodeDefined(app), | ||
checkSubmission(maybeSubmission) | ||
) { case (_, _, requesterEmail, requesterName, _, submission) => (requesterEmail, requesterName, submission) } | ||
} | ||
} | ||
|
||
private def asEvents( | ||
app: StoredApplication, | ||
cmd: ResendRequesterEmailVerification, | ||
submission: Submission, | ||
requesterEmail: LaxEmailAddress, | ||
requesterName: String | ||
): (RequesterEmailVerificationResent) = { | ||
( | ||
RequesterEmailVerificationResent( | ||
id = EventId.random, | ||
applicationId = app.id, | ||
eventDateTime = cmd.timestamp, | ||
actor = Actors.GatekeeperUser(cmd.gatekeeperUser), | ||
submissionId = submission.id, | ||
submissionIndex = submission.latestInstance.index, | ||
requestingAdminName = requesterName, | ||
requestingAdminEmail = requesterEmail | ||
) | ||
) | ||
} | ||
|
||
def process(app: StoredApplication, cmd: ResendRequesterEmailVerification): AppCmdResultT = { | ||
for { | ||
validated <- E.fromValidatedF(validate(app)) | ||
(requesterEmail, requesterName, submission) = validated | ||
emailResent = asEvents(app, cmd, submission, requesterEmail, requesterName) | ||
} yield (app, NonEmptyList.one(emailResent)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../hmrc/thirdpartyapplication/services/notifications/VerifyRequesterEmailNotification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.thirdpartyapplication.services.notifications | ||
|
||
import scala.concurrent.Future | ||
|
||
import uk.gov.hmrc.http.HeaderCarrier | ||
|
||
import uk.gov.hmrc.apiplatform.modules.events.applications.domain.models.ApplicationEvents.RequesterEmailVerificationResent | ||
import uk.gov.hmrc.thirdpartyapplication.connector.EmailConnector | ||
import uk.gov.hmrc.thirdpartyapplication.models.HasSucceeded | ||
import uk.gov.hmrc.thirdpartyapplication.models.db.StoredApplication | ||
|
||
object VerifyRequesterEmailNotification { | ||
|
||
def sendAdviceEmail(emailConnector: EmailConnector, app: StoredApplication, event: RequesterEmailVerificationResent)(implicit hc: HeaderCarrier): Future[HasSucceeded] = { | ||
val verificationCode: String = app.state.verificationCode.getOrElse("") // Note verificationCode has already been validated | ||
emailConnector.sendApplicationApprovedAdminConfirmation( | ||
app.name, | ||
verificationCode, | ||
Set(event.requestingAdminEmail) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.