Skip to content

Commit

Permalink
Merge pull request #72 from hmrc/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
TheNickWilson authored Sep 25, 2019
2 parents 1382556 + 200874b commit ab64266
Show file tree
Hide file tree
Showing 159 changed files with 4,339 additions and 1,578 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## v0.12.0 - 2019-09-24

### Changed
* Upgraded to Play 2.6
* Refactored user answers to use a Json object rather than CacheMap
* Introduce paths on each page to allow pages to decide where in the Json object to store data
* Introduce queries, which can be used to look at data in UserAnswers
* Add a scaffold for a date page
* Add a scaffold for a page of checkboxes
* Updated navigator pattern
* Html escape users' answers on CYA pages
* Updated libraries and plugins
* Update assets frontend version

## Fixed
* Stop application in unit tests
* Mock repositories in controller unit tests
* Remove unsafe-inline and data: from CSP
* Fix textarea whitespace issue
* Fix auth action recover block
* Allow field names to be specified on quesitonPage

## v0.11.0 - 2018-09-25

### Changed
Expand Down
43 changes: 22 additions & 21 deletions src/main/g8/app/config/FrontendAppConfig.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package config

import com.google.inject.{Inject, Singleton}
import play.api.{Configuration, Environment}
import play.api.i18n.Lang
import controllers.routes
import uk.gov.hmrc.play.config.ServicesConfig
import play.api.Configuration
import play.api.i18n.Lang
import play.api.mvc.Call

@Singleton
class FrontendAppConfig @Inject() (override val runModeConfiguration: Configuration, environment: Environment) extends ServicesConfig {
class FrontendAppConfig @Inject() (configuration: Configuration) {

override protected def mode = environment.mode
private val contactHost = configuration.get[String]("contact-frontend.host")
private val contactFormServiceIdentifier = "play26frontend"

private def loadConfig(key: String) = runModeConfiguration.getString(key).getOrElse(throw new Exception(s"Missing configuration key: \$key"))
val analyticsToken: String = configuration.get[String](s"google-analytics.token")
val analyticsHost: String = configuration.get[String](s"google-analytics.host")
val reportAProblemPartialUrl = s"\$contactHost/contact/problem_reports_ajax?service=\$contactFormServiceIdentifier"
val reportAProblemNonJSUrl = s"\$contactHost/contact/problem_reports_nonjs?service=\$contactFormServiceIdentifier"
val betaFeedbackUrl = s"\$contactHost/contact/beta-feedback"
val betaFeedbackUnauthenticatedUrl = s"\$contactHost/contact/beta-feedback-unauthenticated"

private lazy val contactHost = runModeConfiguration.getString("contact-frontend.host").getOrElse("")
private val contactFormServiceIdentifier = "$name;format="lower,word"$"
lazy val authUrl: String = configuration.get[Service]("auth").baseUrl
lazy val loginUrl: String = configuration.get[String]("urls.login")
lazy val loginContinueUrl: String = configuration.get[String]("urls.loginContinue")

lazy val analyticsToken = loadConfig(s"google-analytics.token")
lazy val analyticsHost = loadConfig(s"google-analytics.host")
lazy val reportAProblemPartialUrl = s"\$contactHost/contact/problem_reports_ajax?service=\$contactFormServiceIdentifier"
lazy val reportAProblemNonJSUrl = s"\$contactHost/contact/problem_reports_nonjs?service=\$contactFormServiceIdentifier"
lazy val betaFeedbackUrl = s"\$contactHost/contact/beta-feedback"
lazy val betaFeedbackUnauthenticatedUrl = s"\$contactHost/contact/beta-feedback-unauthenticated"
lazy val languageTranslationEnabled: Boolean =
configuration.get[Boolean]("microservice.services.features.welsh-translation")

lazy val authUrl = baseUrl("auth")
lazy val loginUrl = loadConfig("urls.login")
lazy val loginContinueUrl = loadConfig("urls.loginContinue")

lazy val languageTranslationEnabled = runModeConfiguration.getBoolean("microservice.services.features.welsh-translation").getOrElse(true)
def languageMap: Map[String, Lang] = Map(
"english" -> Lang("en"),
"cymraeg" -> Lang("cy"))
def routeToSwitchLanguage = (lang: String) => routes.LanguageSwitchController.switchToLanguage(lang)
"cymraeg" -> Lang("cy")
)

def routeToSwitchLanguage: String => Call =
(lang: String) => routes.LanguageSwitchController.switchToLanguage(lang)
}
21 changes: 2 additions & 19 deletions src/main/g8/app/config/Module.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
/*
* Copyright 2018 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 config

import com.google.inject.AbstractModule
import connectors._
import controllers.actions._
import repositories.{DefaultSessionRepository, SessionRepository}

class Module extends AbstractModule {

override def configure(): Unit = {

// Bind the actions for DI
bind(classOf[DataRetrievalAction]).to(classOf[DataRetrievalActionImpl]).asEagerSingleton()
bind(classOf[DataRequiredAction]).to(classOf[DataRequiredActionImpl]).asEagerSingleton()

// For session based storage instead of cred based, change to SessionIdentifierAction
bind(classOf[IdentifierAction]).to(classOf[AuthenticatedIdentifierAction]).asEagerSingleton()

bind(classOf[DataCacheConnector]).to(classOf[MongoCacheConnector]).asEagerSingleton()
bind(classOf[SessionRepository]).to(classOf[DefaultSessionRepository]).asEagerSingleton()
}
}
32 changes: 32 additions & 0 deletions src/main/g8/app/config/Service.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package config

import play.api.{ConfigLoader, Configuration}

import scala.language.implicitConversions

final case class Service(host: String, port: String, protocol: String) {

def baseUrl: String =
s"\$protocol://\$host:\$port"

override def toString: String =
baseUrl
}

object Service {

implicit lazy val configLoader: ConfigLoader[Service] = ConfigLoader {
config =>
prefix =>

val service = Configuration(config).get[Configuration](prefix)
val host = service.get[String]("host")
val port = service.get[String]("port")
val protocol = service.get[String]("protocol")

Service(host, port, protocol)
}

implicit def convertToString(service: Service): String =
service.baseUrl
}
33 changes: 0 additions & 33 deletions src/main/g8/app/connectors/DataCacheConnector.scala

This file was deleted.

28 changes: 17 additions & 11 deletions src/main/g8/app/controllers/CheckYourAnswersController.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package controllers

import com.google.inject.Inject
import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierAction}
import play.api.i18n.{I18nSupport, MessagesApi}
import controllers.actions.{IdentifierAction, DataRequiredAction, DataRetrievalAction}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.controller.FrontendBaseController
import utils.CheckYourAnswersHelper
import viewmodels.AnswerSection
import views.html.check_your_answers
import config.FrontendAppConfig
import uk.gov.hmrc.play.bootstrap.controller.FrontendController
import views.html.CheckYourAnswersView

class CheckYourAnswersController @Inject()(appConfig: FrontendAppConfig,
override val messagesApi: MessagesApi,
authenticate: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction) extends FrontendController with I18nSupport {
class CheckYourAnswersController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
val controllerComponents: MessagesControllerComponents,
view: CheckYourAnswersView
) extends FrontendBaseController with I18nSupport {

def onPageLoad() = (authenticate andThen getData andThen requireData) {
def onPageLoad(): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>

val checkYourAnswersHelper = new CheckYourAnswersHelper(request.userAnswers)

val sections = Seq(AnswerSection(None, Seq()))
Ok(check_your_answers(appConfig, sections))

Ok(view(sections))
}
}
18 changes: 9 additions & 9 deletions src/main/g8/app/controllers/IndexController.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package controllers

import javax.inject.Inject
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.controller.FrontendBaseController
import views.html.IndexView

import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent}
import uk.gov.hmrc.play.bootstrap.controller.FrontendController
import config.FrontendAppConfig
import views.html.index

class IndexController @Inject()(val appConfig: FrontendAppConfig,
val messagesApi: MessagesApi) extends FrontendController with I18nSupport {
class IndexController @Inject()(
val controllerComponents: MessagesControllerComponents,
view: IndexView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = Action { implicit request =>
Ok(index(appConfig))
Ok(view())
}
}
27 changes: 13 additions & 14 deletions src/main/g8/app/controllers/LanguageSwitchController.scala
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package controllers

import com.google.inject.Inject
import config.FrontendAppConfig
import play.api.Configuration
import play.api.i18n.{I18nSupport, Lang, MessagesApi}
import play.api.mvc.{Action, AnyContent, Call, Controller}
import config.FrontendAppConfig
import uk.gov.hmrc.play.language.LanguageUtils
import play.api.mvc._
import uk.gov.hmrc.play.bootstrap.controller.FrontendBaseController

// TODO, upstream this into play-language
class LanguageSwitchController @Inject() (
configuration: Configuration,
appConfig: FrontendAppConfig,
implicit val messagesApi: MessagesApi
) extends Controller with I18nSupport {

private def langToCall(lang: String): (String) => Call = appConfig.routeToSwitchLanguage
class LanguageSwitchController @Inject()(
configuration: Configuration,
appConfig: FrontendAppConfig,
override implicit val messagesApi: MessagesApi,
val controllerComponents: MessagesControllerComponents
) extends FrontendBaseController with I18nSupport {

private def fallbackURL: String = routes.IndexController.onPageLoad().url

private def languageMap: Map[String, Lang] = appConfig.languageMap

def switchToLanguage(language: String): Action[AnyContent] = Action {
implicit request =>

val enabled = isWelshEnabled
val lang = if (enabled) {
languageMap.getOrElse(language, LanguageUtils.getCurrentLang)
languageMap.getOrElse(language, Lang.defaultLang)
} else {
Lang("en")
}
val redirectURL = request.headers.get(REFERER).getOrElse(fallbackURL)
Redirect(redirectURL).withLang(Lang.apply(lang.code)).flashing(LanguageUtils.FlashWithSwitchIndicator)
Redirect(redirectURL).withLang(Lang.apply(lang.code))
}

private def isWelshEnabled: Boolean =
configuration.getBoolean("microservice.services.features.welsh-translation").getOrElse(true)
configuration.getOptional[Boolean]("microservice.services.features.welsh-translation").getOrElse(true)
}
20 changes: 9 additions & 11 deletions src/main/g8/app/controllers/SessionExpiredController.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package controllers

import javax.inject.Inject
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.controller.FrontendBaseController
import views.html.SessionExpiredView

import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent}
import uk.gov.hmrc.play.bootstrap.controller.FrontendController
import config.FrontendAppConfig
import views.html.session_expired

import scala.concurrent.Future

class SessionExpiredController @Inject()(val appConfig: FrontendAppConfig,
val messagesApi: MessagesApi) extends FrontendController with I18nSupport {
class SessionExpiredController @Inject()(
val controllerComponents: MessagesControllerComponents,
view: SessionExpiredView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = Action { implicit request =>
Ok(session_expired(appConfig))
Ok(view())
}
}
18 changes: 9 additions & 9 deletions src/main/g8/app/controllers/UnauthorisedController.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package controllers

import javax.inject.Inject
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.controller.FrontendBaseController
import views.html.UnauthorisedView

import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent}
import uk.gov.hmrc.play.bootstrap.controller.FrontendController
import config.FrontendAppConfig
import views.html.unauthorised

class UnauthorisedController @Inject()(val appConfig: FrontendAppConfig,
val messagesApi: MessagesApi) extends FrontendController with I18nSupport {
class UnauthorisedController @Inject()(
val controllerComponents: MessagesControllerComponents,
view: UnauthorisedView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = Action { implicit request =>
Ok(unauthorised(appConfig))
Ok(view())
}
}
Loading

0 comments on commit ab64266

Please sign in to comment.