-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from hmrc/DAC6-3209
DAC6-3209 | Implement CYA Validation
- Loading branch information
Showing
12 changed files
with
975 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 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 controllers | ||
|
||
import controllers.actions._ | ||
import javax.inject.Inject | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import views.html.SomeInformationMissingView | ||
|
||
class SomeInformationMissingController @Inject() ( | ||
override val messagesApi: MessagesApi, | ||
identify: IdentifierAction, | ||
getData: DataRetrievalAction, | ||
requireData: DataRequiredAction, | ||
val controllerComponents: MessagesControllerComponents, | ||
view: SomeInformationMissingView | ||
) extends FrontendBaseController | ||
with I18nSupport { | ||
|
||
def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) { | ||
implicit request => | ||
Ok(view()) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2024 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 utils | ||
|
||
import models.UserAnswers | ||
import pages._ | ||
import pages.addFinancialInstitution._ | ||
import play.api.libs.json.Reads | ||
|
||
sealed trait AddFIValidator { | ||
self: CheckYourAnswersValidator => | ||
|
||
private def firstContactPhoneMissingAnswers: Seq[Page] = (userAnswers.get(FirstContactHavePhonePage) match { | ||
case Some(true) => checkPage(FirstContactPhoneNumberPage) | ||
case Some(false) => None | ||
case _ => Some(FirstContactPhoneNumberPage) | ||
}).toSeq | ||
|
||
private def secContactPhoneMissingAnswers: Seq[Page] = (userAnswers.get(SecondContactCanWePhonePage) match { | ||
case Some(true) => checkPage(SecondContactPhoneNumberPage) | ||
case Some(false) => None | ||
case _ => Some(SecondContactPhoneNumberPage) | ||
}).toSeq | ||
|
||
private def checkFirstContactMissingAnswers: Seq[Page] = Seq( | ||
checkPage(FirstContactNamePage), | ||
checkPage(FirstContactEmailPage) | ||
).flatten ++ firstContactPhoneMissingAnswers | ||
|
||
private def checkSecContactDetailsMissingAnswers: Seq[Page] = | ||
userAnswers.get(SecondContactExistsPage) match { | ||
case Some(true) => | ||
Seq( | ||
checkPage(SecondContactNamePage), | ||
checkPage(SecondContactEmailPage) | ||
).flatten ++ secContactPhoneMissingAnswers | ||
case Some(false) => Seq.empty | ||
case _ => Seq(SecondContactExistsPage) | ||
} | ||
|
||
private[utils] def checkContactDetailsMissingAnswers = checkFirstContactMissingAnswers ++ checkSecContactDetailsMissingAnswers | ||
|
||
private[utils] def checkAddressMissingAnswers: Seq[Page] = (userAnswers.get(WhereIsFIBasedPage) match { | ||
case Some(true) => | ||
checkPage(PostcodePage) | ||
.orElse( | ||
any( | ||
checkPage(SelectAddressPage), | ||
checkPage(UkAddressPage) | ||
).map( | ||
_ => PostcodePage | ||
) | ||
) | ||
case Some(false) => checkPage(NonUkAddressPage) | ||
case _ => Some(WhereIsFIBasedPage) | ||
}).toSeq | ||
|
||
private def fiUTRMissingAnswers: Seq[Page] = (userAnswers.get(HaveUniqueTaxpayerReferencePage) match { | ||
case Some(true) => checkPage(WhatIsUniqueTaxpayerReferencePage) | ||
case Some(false) => None | ||
case _ => Some(HaveUniqueTaxpayerReferencePage) | ||
}).toSeq | ||
|
||
private def fiGIINMissingAnswers: Seq[Page] = (userAnswers.get(HaveGIINPage) match { | ||
case Some(true) => checkPage(WhatIsGIINPage) | ||
case Some(false) => None | ||
case _ => Some(HaveGIINPage) | ||
}).toSeq | ||
|
||
private[utils] def checkNameUTRGIINMissingAnswers: Seq[Page] = Seq( | ||
checkPage(NameOfFinancialInstitutionPage) | ||
).flatten ++ fiUTRMissingAnswers ++ fiGIINMissingAnswers | ||
|
||
} | ||
|
||
class CheckYourAnswersValidator(val userAnswers: UserAnswers) extends AddFIValidator { | ||
|
||
private[utils] def checkPage[A](page: QuestionPage[A])(implicit rds: Reads[A]): Option[Page] = | ||
userAnswers.get(page) match { | ||
case None => Some(page) | ||
case _ => None | ||
} | ||
|
||
private[utils] def any(checkPages: Option[Page]*): Option[Page] = checkPages.find(_.isEmpty).getOrElse(checkPages.last) | ||
|
||
def validate: Seq[Page] = checkNameUTRGIINMissingAnswers ++ checkAddressMissingAnswers ++ checkContactDetailsMissingAnswers | ||
|
||
} | ||
|
||
object CheckYourAnswersValidator { | ||
def apply(userAnswers: UserAnswers): CheckYourAnswersValidator = new CheckYourAnswersValidator(userAnswers) | ||
} |
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,29 @@ | ||
@* | ||
* Copyright 2024 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. | ||
*@ | ||
|
||
@this( | ||
layout: templates.Layout, | ||
govukButton: GovukButton | ||
) | ||
|
||
@()(implicit request: Request[_], messages: Messages) | ||
|
||
@layout(pageTitle = titleNoForm(messages("someInformationMissing.title"))) { | ||
|
||
<h1 class="govuk-heading-xl">@messages("someInformationMissing.heading")</h1> | ||
|
||
<p class="govuk-body">@messages("someInformationMissing.p1")</p> | ||
} |
Oops, something went wrong.