Skip to content

Commit

Permalink
DDCE-5791: CT-UTR Frontend - Bootstrap-play upgrade (#142)
Browse files Browse the repository at this point in the history
* DDCE-5791: CT-UTR Frontend - Bootstrap-play upgrade

* updated version

* changes related to comment

* changes related to comment

* changes related to comment

* changes related to comment

* changes related to comment
  • Loading branch information
harish-korada1 authored Oct 14, 2024
1 parent 86ef53d commit 473aa84
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 315 deletions.
3 changes: 3 additions & 0 deletions a11y/FrontendAccessibilitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import models.{CompanyDetails, Mode, NormalMode}
import org.scalacheck.Arbitrary
import play.api.data.Form
import play.api.data.Forms.{boolean, text}
import play.api.mvc.RequestHeader
import play.twirl.api.Html
import uk.gov.hmrc.scalatestaccessibilitylinter.views.AutomaticAccessibilitySpec
import views.html._
Expand All @@ -18,11 +19,13 @@ class FrontendAccessibilitySpec extends AutomaticAccessibilitySpec {
implicit val arbFormString: Arbitrary[Form[String]] = fixed(stringForm)
implicit val arbCompanyDetailsForm: Arbitrary[Form[CompanyDetails]] = fixed(companyDetailsForm)
implicit val arbMode: Arbitrary[Mode] = fixed(NormalMode)
implicit val arbRequest1: Arbitrary[RequestHeader] = fixed(fakeRequest)

val viewPackageName = "views.html"

val layoutClasses: Seq[Class[MainTemplate]] = Seq(classOf[views.html.MainTemplate])


override def renderViewByClass: PartialFunction[Any, Html] = {
case checkYourAnswersView: CheckYourAnswersView => render(checkYourAnswersView)
case companyDetailsNoMatchView: CompanyDetailsNoMatchView => render(companyDetailsNoMatchView)
Expand Down
16 changes: 9 additions & 7 deletions app/connectors/CompanyHouseConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@
package connectors

import config.FrontendAppConfig
import http.ProxyHttpClient
import models.CompanyDetails
import play.api.Logging
import play.api.http.Status._
import uk.gov.hmrc.http.HttpReads.Implicits.readRaw
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient, HttpResponse}
import uk.gov.hmrc.http.client.HttpClientV2
import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse, StringContextOps}
import utils.FormHelpers.toLowerCaseRemoveSpacesAndReplaceSmartChars

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
import uk.gov.hmrc.http.HttpReads.Implicits._

class CompanyHouseConnector @Inject()(appConfig: FrontendAppConfig, http: HttpClient, proxyHttp: ProxyHttpClient) extends Logging {

class CompanyHouseConnector @Inject()(appConfig: FrontendAppConfig, http: HttpClientV2) extends Logging {

def getName(response: HttpResponse): String = toLowerCaseRemoveSpacesAndReplaceSmartChars((response.json \ "company_name").as[String])

def validateCRN(data: CompanyDetails)(implicit ec: ExecutionContext): Future[Option[Boolean]] = {
implicit val hc: HeaderCarrier = HeaderCarrier()
val httpClient = if (appConfig.proxyEnabled) proxyHttp else http

httpClient.GET(appConfig.companyHouseRequestUrl + data.companyReferenceNumber, headers = Seq("Authorization" -> appConfig.companyHouseRequestAuth))
val fullUrl = appConfig.companyHouseRequestUrl + data.companyReferenceNumber
http.get(url"$fullUrl").withProxy
.setHeader("Authorization" -> appConfig.companyHouseRequestAuth)
.execute[HttpResponse]
.map { response =>
response.status match {
case OK =>
Expand Down
46 changes: 22 additions & 24 deletions app/connectors/CtutrConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,37 @@
package connectors

import javax.inject.Inject

import config.FrontendAppConfig
import models.SubmissionResponse
import play.api.Logging
import play.api.http.Status.OK
import play.api.libs.json.JsValue
import play.api.http.Status._
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.http.HttpClient
import uk.gov.hmrc.http.HttpReads.Implicits.readRaw

import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse, StringContextOps}
import uk.gov.hmrc.http.client.HttpClientV2
import scala.concurrent.{ExecutionContext, Future}

class CtutrConnector @Inject()(appConfig: FrontendAppConfig, http: HttpClient) extends Logging {
class CtutrConnector @Inject()(appConfig: FrontendAppConfig, http: HttpClientV2) extends Logging {

def ctutrSubmission(submissionJson: JsValue)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Option[SubmissionResponse]] = {

val submissionUrl = s"${appConfig.ctutrUrl}/request-corporation-tax-number/submission"

http.POST(submissionUrl, submissionJson).map {
response =>

response.status match {
case OK =>
response.json.asOpt[SubmissionResponse]

case other =>
logger.warn(s"[CtutrConnector][ctutrSubmission] - received HTTP status $other from $submissionUrl")
None
}
}.recover {
case e: Exception =>
logger.warn(s"[CtutrConnector][ctutrSubmission] - submission to $submissionUrl failed - $e")
None
}
http.post(url"$submissionUrl")
.withBody(submissionJson)
.execute[HttpResponse]
.map {
response =>
response.status match {
case OK =>
response.json.asOpt[SubmissionResponse]

case other =>
logger.warn(s"[CtutrConnector][ctutrSubmission] - received HTTP status $other from $submissionUrl")
None
}
}.recover {
case e: Exception =>
logger.warn(s"[CtutrConnector][ctutrSubmission] - submission to $submissionUrl failed - $e")
None
}
}
}
18 changes: 12 additions & 6 deletions app/handlers/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ package handlers

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

import scala.concurrent.{ExecutionContext, Future}


@Singleton
class ErrorHandler @Inject()(
notFoundView: ErrorTemplateNotFoundView,
internalServerErrorView: ErrorTemplateInternalServerErrorView,
view: ErrorTemplateView,
val messagesApi: MessagesApi
) extends FrontendErrorHandler with I18nSupport {
)(implicit val ec: ExecutionContext) extends FrontendErrorHandler with I18nSupport {

override def notFoundTemplate(implicit request: Request[_]): Html = {

override def notFoundTemplate(implicit request: RequestHeader): Future[Html] = Future.successful {
notFoundView(
Messages("error.pageNotFound.title"),
Messages("error.pageNotFound.heading"),
Expand All @@ -41,15 +45,17 @@ class ErrorHandler @Inject()(
Messages("error.pageNotFound.messageLink"))
}

override def internalServerErrorTemplate(implicit request: Request[_]): Html = {
override def internalServerErrorTemplate(implicit requestHeader: RequestHeader): Future[Html] = Future.successful {
internalServerErrorView(
Messages("error.internalError.title"),
Messages("error.internalError.heading"),
Messages("error.internalError.message1"))
}


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

}

53 changes: 0 additions & 53 deletions app/http/ProxyHttpClient.scala

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/CheckYourAnswersView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
govukButton : GovukButton
)

@(answerSection: AnswerSection)(implicit request: Request[_], messages: Messages)
@(answerSection: AnswerSection)(implicit request: RequestHeader, messages: Messages)

@main_template(title = messages("checkYourAnswers.title"), backLink = Some(routes.CompanyDetailsController.onPageLoad(NormalMode).toString)) {
@formHelper(action = routes.CheckYourAnswersController.onSubmit, Symbol("autoComplete") -> "off") {
Expand Down
2 changes: 1 addition & 1 deletion app/views/CompanyDetailsNoMatchView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
hmrcNewTabLink: HmrcNewTabLink
)

@()(implicit request: Request[_], messages: Messages)
@()(implicit request: RequestHeader, messages: Messages)

@main_template(title = messages("companyDetailsNoMatch.title"), hasTimeOut = false) {

Expand Down
2 changes: 1 addition & 1 deletion app/views/CompanyDetailsView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
hmrcNewTabLink: HmrcNewTabLink
)

@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages)
@(form: Form[_], mode: Mode)(implicit request: RequestHeader, messages: Messages)

@main_template(
title = if(form.errors.nonEmpty) "Error: "+messages("companyDetails.title") else messages("companyDetails.title"),
Expand Down
2 changes: 1 addition & 1 deletion app/views/ConfirmationView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
hmrcNewTabLink: HmrcNewTabLink
)

@()(implicit request: Request[_], messages: Messages)
@()(implicit request: RequestHeader, messages: Messages)

@main_template(title = messages("confirmation.title")){

Expand Down
2 changes: 1 addition & 1 deletion app/views/ErrorTemplateInternalServerErrorView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
main_template: MainTemplate
)

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

@main_template(title = pageTitle) {

Expand Down
2 changes: 1 addition & 1 deletion app/views/ErrorTemplateNotFoundView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
message1: String,
message2: String,
message3: String,
messageLink: String)(implicit request: Request[_], messages: Messages)
messageLink: String)(implicit request: RequestHeader, messages: Messages)

@main_template(title = pageTitle) {

Expand Down
2 changes: 1 addition & 1 deletion app/views/ErrorTemplateView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
main_template: MainTemplate,
)

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

@main_template(title = pageTitle){

Expand Down
2 changes: 1 addition & 1 deletion app/views/FailedToSubmitView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
main_template: MainTemplate
)

@()(implicit request: Request[_], messages: Messages)
@()(implicit request: RequestHeader, messages: Messages)

@main_template(title = messages("failed_to_submit.title")) {

Expand Down
2 changes: 1 addition & 1 deletion app/views/IndexView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
govukNotificationBanner : GovukNotificationBanner)


@(call: Call)(implicit request: Request[_], messages: Messages)
@(call: Call)(implicit request: RequestHeader, messages: Messages)

@bannerHtml = {
<div class="govuk-notification-banner__heading" id="delay-banner-heading">
Expand Down
2 changes: 1 addition & 1 deletion app/views/MainTemplate.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
beforeContentHtml: Option[Html] = None,
hasTimeOut: Boolean = true,
backLink: Option[String] = None
)(mainContent: Html)(implicit request: Request[_], messages: Messages)
)(mainContent: Html)(implicit request: RequestHeader, messages: Messages)

@head = {
<meta name="format-detection" content="telephone=no" />
Expand Down
2 changes: 1 addition & 1 deletion app/views/SessionExpiredView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
govukButton : GovukButton
)

@(startPage : Call)(implicit request: Request[_], messages: Messages)
@(startPage : Call)(implicit request: RequestHeader, messages: Messages)

@main_template(title = messages("session_expired.title"), hasTimeOut = false) {

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scoverage.ScoverageKeys
import uk.gov.hmrc.DefaultBuildSettings.{defaultSettings, scalaSettings}
import uk.gov.hmrc.versioning.SbtGitVersioning.autoImport.majorVersion

scalaVersion := "2.13.14"
scalaVersion := "2.13.15"

lazy val scoverageSettings =
Seq(ScoverageKeys.coverageExcludedFiles := "<empty>;Reverse.*;.*filters.*;.*handlers.*;.*components.*;.*models.*;.*repositories.*;" +
Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ play.filters.enabled += filters.SessionIdFilter
# Play Modules
# ~~~~
# Additional play modules can be added here
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientV2Module"
play.modules.enabled += "uk.gov.hmrc.mongo.play.PlayMongoModule"
play.modules.enabled += ${submissionModule}

Expand Down
12 changes: 6 additions & 6 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import sbt.{ModuleID, *}

object AppDependencies {

private val bootstrapVersion: String = "8.6.0"
private val bootstrapVersion: String = "9.5.0"

val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % "2.2.0",
"uk.gov.hmrc" %% "play-conditional-form-mapping-play-30" % "2.0.0",
"uk.gov.hmrc" %% "play-conditional-form-mapping-play-30" % "3.2.0",
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
"uk.gov.hmrc" %% "play-allowlist-filter" % "1.3.0",
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "9.11.0"
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "10.12.0"
)

val test: Seq[ModuleID] = Seq(
"org.scalatest" %% "scalatest" % "3.2.18",
"org.scalatest" %% "scalatest" % "3.2.19",
"org.scalatestplus" %% "mockito-5-10" % "3.2.18.0",
"org.scalatestplus" %% "scalacheck-1-17" % "3.2.18.0",
"org.jsoup" % "jsoup" % "1.17.2",
"org.scalacheck" %% "scalacheck" % "1.18.0",
"org.jsoup" % "jsoup" % "1.18.1",
"org.scalacheck" %% "scalacheck" % "1.18.1",
"com.vladsch.flexmark" % "flexmark-all" % "0.64.8",
"uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapVersion
).map(_ % "test")
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefact

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.5")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0" exclude("org.scala-lang.modules", "scala-xml_2.12"))
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.1")
addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")
addSbtPlugin("net.ground5hark.sbt" % "sbt-concat" % "0.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "2.0.0")
Expand Down
Loading

0 comments on commit 473aa84

Please sign in to comment.