Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ This should start this service and any dependent services.

Once the script has finished, the service will be available on http://localhost:9618/api-test-user

For CTC users, the service will be available on http://localhost:9618/api-test-user/create
http://localhost:9485/manage-transit-movements/what-do-you-want-to-do


## Running tests

Expand Down
14 changes: 8 additions & 6 deletions app/uk/gov/hmrc/testuser/config/ApplicationConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class ApplicationConfig @Inject() (config: Configuration) {
private lazy val urlFooterConfig = config.underlying.getConfig("urls.footer")
private lazy val feedbackSurveyConfig = config.underlying.getConfig("feedbackBanner.generic")

lazy val cookies: String = urlFooterConfig.getString("cookies")
lazy val privacy: String = urlFooterConfig.getString("privacy")
lazy val termsConditions: String = urlFooterConfig.getString("termsConditions")
lazy val govukHelp: String = urlFooterConfig.getString("govukHelp")
lazy val accessibility: String = urlFooterConfig.getString("accessibility")
lazy val feedbackSurveyUrl = feedbackSurveyConfig.getString("surveyUrl")
lazy val cookies: String = urlFooterConfig.getString("cookies")
lazy val privacy: String = urlFooterConfig.getString("privacy")
lazy val termsConditions: String = urlFooterConfig.getString("termsConditions")
lazy val govukHelp: String = urlFooterConfig.getString("govukHelp")
lazy val accessibility: String = urlFooterConfig.getString("accessibility")
lazy val feedbackSurveyUrl = feedbackSurveyConfig.getString("surveyUrl")
lazy val routingLoginUrls = config.get[Seq[String]]("routing-login-urls")
lazy val serviceKeys = config.get[Seq[String]]("services")
}
57 changes: 42 additions & 15 deletions app/uk/gov/hmrc/testuser/controllers/TestUserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,32 @@ import uk.gov.hmrc.testuser.config.ApplicationConfig
import uk.gov.hmrc.testuser.connectors.ApiPlatformTestUserConnector
import uk.gov.hmrc.testuser.models.{NavLink, UserTypes}
import uk.gov.hmrc.testuser.services.{NavigationService, TestUserService}
import uk.gov.hmrc.testuser.views.html.{CreateTestUserView, TestUserView}
import uk.gov.hmrc.testuser.views.html.{CreateTestUserView, CreateTestUserViewGeneric, TestUserView, TestUserViewGeneric}

class TestUserController @Inject() (
override val messagesApi: MessagesApi,
testUserService: TestUserService,
navigationService: NavigationService,
apiPlatformTestUserConnector: ApiPlatformTestUserConnector,
messagesControllerComponents: MessagesControllerComponents,
createTestUser: CreateTestUserView,
testUser: TestUserView
)(implicit val ec: ExecutionContext, config: ApplicationConfig)
extends FrontendController(messagesControllerComponents)
with I18nSupport
with ApplicationLogger
with WithUnsafeDefaultFormBinding {
override val messagesApi: MessagesApi,
testUserService: TestUserService,
navigationService: NavigationService,
apiPlatformTestUserConnector: ApiPlatformTestUserConnector,
messagesControllerComponents: MessagesControllerComponents,
createTestUser: CreateTestUserView,
createTestUserGeneric: CreateTestUserViewGeneric,
testUser: TestUserView,
testUserGeneric: TestUserViewGeneric
)(implicit val ec: ExecutionContext,
config: ApplicationConfig
) extends FrontendController(messagesControllerComponents) with I18nSupport with ApplicationLogger with WithUnsafeDefaultFormBinding {

def showCreateUserPage() = headerNavigation { implicit request => navLinks =>
Future.successful(Ok(createTestUser(navLinks, CreateUserForm.form)))
}

def showCreateUserPageGeneric() = headerNavigation { implicit request =>navLinks =>
testUserService.services.flatMap(services =>
Future.successful(Ok(createTestUserGeneric(services.filter(s => config.serviceKeys.contains(s.key)), navLinks, CreateUserForm.form)))
)
}

def createUser() = headerNavigation { implicit request => navLinks =>
def validForm(form: CreateUserForm) = {
UserTypes.from(form.userType.getOrElse("")) match {
Expand All @@ -66,6 +72,26 @@ class TestUserController @Inject() (

CreateUserForm.form.bindFromRequest().fold(invalidForm, validForm)
}
def createUserGeneric() = headerNavigation { implicit request =>navLinks =>
def validForm(form: CreateUserForm) = {
val x = UserTypes.from(form.userType.getOrElse(""))
val y = form.services

(x, y) match {
case (Some(uType), Some(services)) =>
testUserService.createUserGeneric(uType, services.split(",").toSeq) map (user => Ok(testUserGeneric(navLinks, user)))
case _ => Future.failed(new BadRequestException("Invalid request"))
}
}

def invalidForm(invalidForm: Form[CreateUserForm]) = {
testUserService.services.flatMap(services =>
Future.successful(BadRequest(createTestUserGeneric(services.filter(s => config.serviceKeys.contains(s.key)), navLinks, invalidForm)))
)
}

CreateUserForm.form.bindFromRequest().fold(invalidForm, validForm)
}

private def headerNavigation(f: Request[AnyContent] => Seq[NavLink] => Future[Result]): Action[AnyContent] = {
Action.async { implicit request =>
Expand All @@ -81,13 +107,14 @@ class TestUserController @Inject() (
}
}

case class CreateUserForm(userType: Option[String])
case class CreateUserForm(userType: Option[String], services: Option[String])

object CreateUserForm {

val form: Form[CreateUserForm] = Form(
mapping(
"userType" -> optional(text).verifying(FormKeys.createUserTypeNoChoiceKey, s => s.isDefined)
"userType" -> optional(text).verifying(FormKeys.createUserTypeNoChoiceKey, userType => userType.isDefined),
"serviceSelection" -> optional(text).verifying(FormKeys.createServicesNoChoiceKey, selectedServices => selectedServices.isDefined),
)(CreateUserForm.apply)(CreateUserForm.unapply)
)
}
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/testuser/controllers/controllers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ package object controllers {

object FormKeys {
val createUserTypeNoChoiceKey = "create.user.type.no.choice.field"
val createServicesNoChoiceKey = "create.user.services.no.choice.field"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ object FieldDefinitions {
FieldDefinition("individualDetails", "Individual Details", Seq()),
FieldDefinition("groupIdentifier", "Group Identifier", Seq(INDIVIDUAL, ORGANISATION))
)

def getCtc(): Seq[FieldDefinition] = Seq(
FieldDefinition("eoriNumber", "Economic Operator Registration and Identification (EORI) number", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("userFullName", "Full Name", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("emailAddress", "Email Address", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("organisationDetails", "Organisation Details", Seq(ORGANISATION)),
FieldDefinition("individualDetails", "Individual Details", Seq(INDIVIDUAL)),
FieldDefinition("groupIdentifier", "Group Identifier", Seq(INDIVIDUAL, ORGANISATION))
)
}
10 changes: 10 additions & 0 deletions app/uk/gov/hmrc/testuser/services/TestUserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ import uk.gov.hmrc.testuser.models.{Service, TestUser, UserTypes}

class TestUserService @Inject() (apiPlatformTestUserConnector: ApiPlatformTestUserConnector)(implicit ec: ExecutionContext) {

def services(implicit hc: HeaderCarrier) = apiPlatformTestUserConnector.getServices()

def createUser(userType: UserType)(implicit hc: HeaderCarrier): Future[TestUser] = {
for {
services <- apiPlatformTestUserConnector.getServices()
testUser <- createUserWithServices(userType, services)
} yield testUser

}
def createUserGeneric(userType: UserType, selectedServices: Seq[String])(implicit hc: HeaderCarrier): Future[TestUser] = {
println(s"ACHI: $selectedServices")
for {
services <- apiPlatformTestUserConnector.getServices()
testUser <- createUserWithServices(userType, services.filter(x => selectedServices.contains(x.key)))
} yield testUser

}

private def createUserWithServices(userType: UserType, services: Seq[Service])(implicit hc: HeaderCarrier) = {
Expand Down
137 changes: 137 additions & 0 deletions app/uk/gov/hmrc/testuser/views/CreateTestUserViewGeneric.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
@*
* 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.
*@

@import uk.gov.hmrc.testuser.models.NavLink
@import uk.gov.hmrc.testuser.controllers.CreateUserForm
@import uk.gov.hmrc.testuser.views.html.includes._
@import uk.gov.hmrc.testuser.models.FieldDefinitions
@import uk.gov.hmrc.testuser.models.UserTypes.{INDIVIDUAL, ORGANISATION}
@import uk.gov.hmrc.testuser.views.html.govuk_wrapper
@import uk.gov.hmrc.testuser.models.views.FeedbackBanner
@import uk.gov.hmrc.testuser.models.views.GenericFeedbackBanner
@import uk.gov.hmrc.testuser.config.ApplicationConfig
@import uk.gov.hmrc.testuser.models.Service


@this(govUkWrapper: govuk_wrapper, feedbackBannerView: FeedbackBannerView)

@(services: Seq[Service], navLinks: Seq[NavLink], form: Form[CreateUserForm], feedbackBanner: Option[FeedbackBanner] = Some(GenericFeedbackBanner))(implicit request: Request[_], messages: Messages, config: ApplicationConfig)

@govUkWrapper(pageTitle = Some("Create test user - HMRC Developer Hub - GOV.UK"), navLinks = navLinks, feedbackBanner = feedbackBanner) {
<h1 class="govuk-heading-xl">Create a test user for a given service</h1>
@errorSummary(form)
<p class="govuk-body">
A test user is a dummy Government Gateway user ID used for testing a given service in the sandbox with the required enrolment.
</p>
<p class="govuk-body">
A test user ID has:
</p>
<ul class="govuk-list govuk-list--bullet">
<li>a type - individual, organisation or agent</li>
<li>a password</li>
<li>a service enrolment</li>
</ul>
<p class="govuk-body">
Test users and other test data are no longer cleared down every two weeks.
</p>


@helper.form(action = uk.gov.hmrc.testuser.controllers.routes.TestUserController.createUserGeneric()) {
@helper.CSRF.formField

<div class="govuk-form-group @if(form.errors("serviceSelection").nonEmpty) {govuk-form-group--error}">
<fieldset id="serviceSelection" class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h2 class="govuk-fieldset__heading">
Choose the service you need
</h2>
</legend>
@fieldError(form.errors, "serviceSelection")
<div class="govuk-radios">
@services.map(s =>
<p>
<div class="govuk-radios__item">
<input class="govuk-radios__input" type="radio" id={ s.key } name="serviceSelection" value= { s.key }/>
<label class="govuk-label govuk-radios__label" for="Individual" data-type="individual">
<b> { s.name } </b>
</label>
</div>
</p>
)
</div>
</fieldset>
</div>

<div class="govuk-form-group @if(form.errors("userType").nonEmpty) {govuk-form-group--error}">
<fieldset id="userType" class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h2 class="govuk-fieldset__heading">
Choose a type of test user
</h2>
</legend>
@fieldError(form.errors, "userType")
<div class="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="Individual" value="INDIVIDUAL" name="userType" type="radio" aria-describedby="individual-type-hint">
<label class="govuk-label govuk-radios__label" for="Individual" data-type="individual">
<b>Individual</b>
</label>
<details id="individual-type-hint">
<summary class="govuk-summary-text">What dummy data is generated?</summary>
<div class="govuk-inset-text">
<p class="govuk-body">Creates a test user with a:</p>
<ul class="govuk-list govuk-list--bullet">
<li>User ID</li>
<li>Password</li>
@FieldDefinitions.get().filter(field => field.allowedUserTypes.contains(INDIVIDUAL)).map { field =>
<li>@field.name</li>
}
</ul>
<p class="govuk-body">
Enrols them for the selected service
</p>
</div>
</details>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="Organisation" value="ORGANISATION" name="userType" type="radio" aria-describedby="organisation-type-hint">
<label class="govuk-label govuk-radios__label" for="Organisation" data-type="organisation">
<b>Organisation</b>
</label>
<details id="organisation-type-hint">
<summary class="govuk-summary-text">What dummy data is generated?</summary>
<div class="govuk-inset-text">
<p class="govuk-body">Creates a test user with a:</p>
<ul class="govuk-list govuk-list--bullet">
<li>User ID</li>
<li>Password</li>
@FieldDefinitions.get().filter(field => field.allowedUserTypes.contains(ORGANISATION)).map { field =>
<li>@field.name</li>
}
</ul>
<p class="govuk-body">
Enrols them for the selected service
</p>
</div>
</details>
</div>
</div>
</fieldset>
</div>

<button id="submit" class="govuk-button" data-module="govuk-button" type="submit">Create</button>
}
}
57 changes: 57 additions & 0 deletions app/uk/gov/hmrc/testuser/views/TestUserViewGeneric.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@*
* 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.
*@

@import uk.gov.hmrc.testuser.models.TestUser
@import uk.gov.hmrc.testuser.models.NavLink
@import uk.gov.hmrc.testuser.models.Field

@import uk.gov.hmrc.testuser.views.html.field
@import uk.gov.hmrc.testuser.views.html.govuk_wrapper
@import uk.gov.hmrc.testuser.views.html.includes.FeedbackBannerView
@import uk.gov.hmrc.testuser.models.views.FeedbackBanner
@import uk.gov.hmrc.testuser.models.views.GenericFeedbackBanner
@import uk.gov.hmrc.testuser.config.ApplicationConfig

@this(govUkWrapper: govuk_wrapper, feedbackBannerView: FeedbackBannerView)

@(navLinks: Seq[NavLink], user: TestUser, feedbackBanner: Option[FeedbackBanner] = Some(GenericFeedbackBanner))(implicit request: Request[_], messages: Messages, config: ApplicationConfig)

@title = {Generated @user.label.toLowerCase}

@govUkWrapper(Some(s"$title - HMRC Developer Hub - GOV.UK"), navLinks = navLinks, feedbackBanner = feedbackBanner) {
<h1 class="govuk-heading-xl">@title</h1>

<ul class="govuk-list govuk-list--bullet govuk-list--no-style">
@field(Field("userid", "User ID", user.userId))
@field(Field("password", "Password", user.password))
@user.fields.map(f => field(f))
</ul>

<p class="govuk-body govuk-!-padding-bottom-4">
<a class="govuk-link" href="@uk.gov.hmrc.testuser.controllers.routes.TestUserController.showCreateUserPage()">
Add a new user
</a>
</p>

@config.serviceKeys.map(key =>
config.routingLoginUrls.map(url =>
if(url.contains(key)) {
<p class="govuk-body">
Login to <a class="govuk-link" target="_blank" href={ url.split(",")(1) } > { url.split(",")(0).replace("-", " ") } </a>
</p>
}
))
}
5 changes: 1 addition & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import play.core.PlayVersion
import play.sbt.PlayImport._
import bloop.integrations.sbt.BloopDefaults
import sbt.Tests.{Group, SubProcess}
import uk.gov.hmrc.DefaultBuildSettings
import uk.gov.hmrc.DefaultBuildSettings._
import uk.gov.hmrc.SbtAutoBuildPlugin
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin._
import uk.gov.hmrc.versioning.SbtGitVersioning
import uk.gov.hmrc.versioning.SbtGitVersioning.autoImport.majorVersion

import scala.util.Properties
import bloop.integrations.sbt.BloopDefaults

lazy val playSettings: Seq[Setting[_]] = Seq.empty
lazy val appName = "api-platform-test-user-frontend"
Expand Down
2 changes: 2 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
-> /hmrc-frontend hmrcfrontend.Routes

GET / uk.gov.hmrc.testuser.controllers.TestUserController.showCreateUserPage()
GET /create uk.gov.hmrc.testuser.controllers.TestUserController.showCreateUserPageGeneric()

POST /user uk.gov.hmrc.testuser.controllers.TestUserController.createUser()
POST /user/create uk.gov.hmrc.testuser.controllers.TestUserController.createUserGeneric()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
Expand Down
Loading