Skip to content

Commit

Permalink
TGP-2721: Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan-James-Donovan committed Nov 5, 2024
2 parents b3e8bba + 23ec1c9 commit ac2e562
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 1,027 deletions.
58 changes: 0 additions & 58 deletions app/controllers/DownloadDataIndexController.scala

This file was deleted.

47 changes: 0 additions & 47 deletions app/controllers/FileInProgressController.scala

This file was deleted.

83 changes: 0 additions & 83 deletions app/controllers/FileReadyController.scala

This file was deleted.

11 changes: 9 additions & 2 deletions app/forms/EmailFormProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ package forms
import javax.inject.Inject
import forms.mappings.Mappings
import forms.mappings.helpers.FormatAnswers.removeWhitespace
import forms.mappings.helpers.StopOnFirstFail
import models.StringFieldRegex
import play.api.data.Form
import utils.Constants

class EmailFormProvider @Inject() extends Mappings {

def apply(): Form[String] =
Form(
"value" -> text("email.error.required")
.transform(removeWhitespace, identity[String])
.verifying(maxLength(254, "email.error.length"))
.verifying(regexp(StringFieldRegex.emailRegex, "email.error.invalidFormat"))
.verifying(
StopOnFirstFail[String](
maxLength(Constants.maximumEmailLength, "email.error.length"),
regexp(StringFieldRegex.emailRegex, "email.error.invalidFormat"),
email("email.error.invalidFormat")
)
)
)
}
12 changes: 12 additions & 0 deletions app/forms/mappings/Constraints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package forms.mappings

import java.time.LocalDate

import org.apache.commons.validator.routines.EmailValidator
import play.api.data.validation.{Constraint, Invalid, Valid}

trait Constraints {
Expand Down Expand Up @@ -102,4 +103,15 @@ trait Constraints {
case _ =>
Invalid(errorKey)
}

protected def email(errorKey: String): Constraint[String] = {
val emailValidator = EmailValidator.getInstance(true)

Constraint {
case str if emailValidator.isValid(str) =>
Valid
case _ =>
Invalid(errorKey)
}
}
}
29 changes: 29 additions & 0 deletions app/forms/mappings/helpers/StopOnFirstFail.scala
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.
*/

package forms.mappings.helpers

import play.api.data.validation.{Constraint, Valid}

object StopOnFirstFail {

def apply[T](constraints: Constraint[T]*): Constraint[T] = Constraint { field =>
constraints.toList dropWhile (_(field) == Valid) match {
case Nil => Valid
case constraint :: _ => constraint(field)
}
}
}
16 changes: 10 additions & 6 deletions app/handlers/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@

package handlers

import javax.inject.{Inject, Singleton}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.Request
import play.api.mvc.RequestHeader
import play.twirl.api.Html
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import views.html.ErrorTemplate

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class ErrorHandler @Inject() (
val messagesApi: MessagesApi,
view: ErrorTemplate
) extends FrontendErrorHandler
)(implicit val ec: ExecutionContext)
extends FrontendErrorHandler
with I18nSupport {

override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit
rh: Request[_]
): Html =
view(pageTitle, heading, message)
request: RequestHeader
): Future[Html] =
Future.successful(view(pageTitle, heading, message))

}
2 changes: 2 additions & 0 deletions app/utils/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ case object Constants {
val goodsDescriptionKey = "goodsDescription"
val countryOfOriginKey = "countryOfOrigin"
val commodityCodeKey = "commodityCode"

val maximumEmailLength: Int = 254
}
2 changes: 1 addition & 1 deletion app/views/DownloadRequestSuccessView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h2 class="govuk-heading-m">@messages("downloadRequestSuccess.h2")</h2>
<p class="govuk-body">@messages("downloadRequestSuccess.p2")</p>
<p class="govuk-body">@messages("downloadRequestSuccess.p3")</p>

<p class="govuk-body"><a href="@routes.GoodsRecordsController.onPageLoad(1).url" class="govuk-link" >@messages("site.goBackToTGPRecords")</a></p>
<p class="govuk-body"><a href="@routes.FileManagementController.onPageLoad().url" class="govuk-link" >@messages("site.goBackToTGPRecords")</a></p>
<p class="govuk-body"><a href="@routes.HomePageController.onPageLoad().url" class="govuk-link" >@messages("site.goBackToHomePage")</a></p>

@feedbackSection()
Expand Down
6 changes: 4 additions & 2 deletions app/views/ErrorTemplate.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*@

@import views.ViewUtils.titleNoForm

@this(
layout: templates.Layout
layout: templates.Layout
)

@(pageTitle: String, heading: String, message: String)(implicit request: Request[_], messages: Messages)
@(pageTitle: String, heading: String, message: String)(implicit request: RequestHeader, messages: Messages)

@layout(pageTitle = titleNoForm(pageTitle)) {
<h1 class="govuk-heading-xl">@messages(heading)</h1>
Expand Down
32 changes: 0 additions & 32 deletions app/views/FileInProgressView.scala.html

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/FileManagementView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h2 class="govuk-heading-m">@table.caption</h2>
}
}

<p class="govuk-body"><a href="@routes.DownloadRequestSuccessController.onPageLoad().url" class="govuk-link" >@viewModel.tgpRecordsLink</a></p>
<p class="govuk-body"><a href="@routes.RequestDataController.onPageLoad().url" class="govuk-link" >@viewModel.tgpRecordsLink</a></p>
<p class="govuk-body"><a href="@routes.HomePageController.onPageLoad().url" class="govuk-link" >@viewModel.goBackHomeLink</a></p>

}
Loading

0 comments on commit ac2e562

Please sign in to comment.