Skip to content

Commit 0c66790

Browse files
authored
APB-10863 handle removal of last record and update content (#195)
APB-10863 update content to latest
1 parent acdd4e4 commit 0c66790

21 files changed

+255
-137
lines changed

app/uk/gov/hmrc/agentregistrationfrontend/config/AppConfig.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class AppConfig @Inject() (
4747
"urls.taxAndSchemeManagementToSelfServeAssignmentOfAsaEnrolment",
4848
configuration
4949
)
50+
val guidanceForWhatARelevantTaxAdviserIsUrl: String = ConfigHelper.readConfigAsValidUrlString("urls.govuk-guidance-on-relevant-tax-advisers", configuration)
5051
val addressLookupFrontendBaseUrl: String = servicesConfig.baseUrl("address-lookup-frontend")
5152
val agentsExternalStubsBaseUrl: String = servicesConfig.baseUrl("agents-external-stubs")
5253
val companiesHouseApiProxyBaseUrl: String = servicesConfig.baseUrl("companies-house-api-proxy")

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/TaskListController.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ extends FrontendController(mcc, actions):
8282
val amlsDetailsCompleted = agentApplication.amlsDetails.exists(_.isComplete)
8383
val agentDetailsIsComplete = agentApplication.agentDetails.exists(_.isComplete)
8484
val hmrcStandardForAgentsAgreed = agentApplication.hmrcStandardForAgentsAgreed === StateOfAgreement.Agreed
85+
def otherRelevantIndividualsComplete(existingList: List[IndividualProvidedDetails]): Boolean =
86+
agentApplication.hasOtherRelevantIndividuals match
87+
case Some(true) => existingList.exists(!_.isPersonOfControl)
88+
case Some(false) => true
89+
case None => false
8590
def listDetailsCompleted(existingList: List[IndividualProvidedDetails]): Boolean =
8691
agentApplication match
8792
case a: AgentApplication.IsAgentApplicationForDeclaringNumberOfKeyIndividuals =>
8893
NumberOfRequiredKeyIndividuals.isKeyIndividualListComplete(existingList.count(_.isPersonOfControl), a.numberOfRequiredKeyIndividuals)
89-
&& a.hasOtherRelevantIndividuals.isDefined
94+
&& otherRelevantIndividualsComplete(existingList)
9095
case _ => true
9196
val listProgressComplete = listDetailsCompleted(existingList) && existingList.forall(_.hasFinished)
9297
// any state other than Precreated indicates the link has been sent; require the list to be non-empty

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/listdetails/otherrelevantindividuals/ChangeOtherRelevantIndividualController.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import uk.gov.hmrc.agentregistration.shared.lists.IndividualName
2929
import uk.gov.hmrc.agentregistration.shared.util.SafeEquals.===
3030
import uk.gov.hmrc.agentregistrationfrontend.action.applicant.ApplicantActions
3131
import uk.gov.hmrc.agentregistrationfrontend.controllers.applicant.FrontendController
32-
import uk.gov.hmrc.agentregistrationfrontend.forms.IndividualNameForm
32+
import uk.gov.hmrc.agentregistrationfrontend.forms.OtherRelevantIndividualNameForm
3333
import uk.gov.hmrc.agentregistrationfrontend.services.individual.IndividualProvideDetailsService
3434
import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.listdetails.otherrelevantindividuals.EnterIndividualNamePage
3535

@@ -89,13 +89,14 @@ extends FrontendController(mcc, actions):
8989
.individualName
9090

9191
Future.successful(Ok(enterIndividualNamePage(
92-
form = IndividualNameForm.form.fill(nameToChange),
93-
formAction = formAction
92+
form = OtherRelevantIndividualNameForm.form.fill(nameToChange),
93+
formAction = formAction,
94+
ordinalKey = "change"
9495
)))
9596

9697
def submit(individualProvidedDetailsId: IndividualProvidedDetailsId): Action[AnyContent] = baseAction
9798
.ensureValidFormAndRedirectIfSaveForLater[IndividualName](
98-
form = IndividualNameForm.form,
99+
form = OtherRelevantIndividualNameForm.form,
99100
resultToServeWhenFormHasErrors =
100101
implicit request =>
101102
(formWithErrors: Form[IndividualName]) =>
@@ -106,7 +107,8 @@ extends FrontendController(mcc, actions):
106107
BadRequest(
107108
enterIndividualNamePage(
108109
form = formWithErrors,
109-
formAction = formAction
110+
formAction = formAction,
111+
ordinalKey = "change"
110112
)
111113
)
112114
)

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/listdetails/otherrelevantindividuals/ConfirmOtherRelevantIndividualsController.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ extends FrontendController(mcc, actions):
145145
.setTo(Some(hasOtherRelevantIndividuals))
146146
}
147147

148-
val deleteOtherRelevantIndividuals: Future[List[Unit]] = Future.sequence(
149-
otherRelevantIndividuals.map(x =>
150-
individualProvideDetailsService.delete(x.individualProvidedDetailsId)
151-
)
152-
)
148+
// we do not want to delete previous records (that may already be populated by signed in users)
149+
// unless the user has selected that they do not have any
150+
val deleteOtherRelevantIndividuals: Future[Unit] =
151+
if hasOtherRelevantIndividuals
152+
then Future.successful(())
153+
else
154+
Future.sequence(
155+
otherRelevantIndividuals.map(x =>
156+
individualProvideDetailsService.delete(x.individualProvidedDetailsId)
157+
)
158+
).map(_ => ())
153159

154160
for
155161
_ <- deleteOtherRelevantIndividuals

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/listdetails/otherrelevantindividuals/EnterOtherRelevantIndividualController.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import uk.gov.hmrc.agentregistration.shared.individual.IndividualProvidedDetails
2525
import uk.gov.hmrc.agentregistration.shared.lists.IndividualName
2626
import uk.gov.hmrc.agentregistrationfrontend.action.applicant.ApplicantActions
2727
import uk.gov.hmrc.agentregistrationfrontend.controllers.applicant.FrontendController
28-
import uk.gov.hmrc.agentregistrationfrontend.forms.IndividualNameForm
28+
import uk.gov.hmrc.agentregistrationfrontend.forms.OtherRelevantIndividualNameForm
2929
import uk.gov.hmrc.agentregistrationfrontend.services.individual.IndividualProvideDetailsService
30+
import uk.gov.hmrc.agentregistrationfrontend.util.MessageKeys
3031
import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.listdetails.otherrelevantindividuals.EnterIndividualNamePage
3132

3233
import javax.inject.Inject
@@ -65,27 +66,39 @@ extends FrontendController(mcc, actions):
6566
individualProvideDetailsService.findAllByApplicationId(agentApplication.agentApplicationId).map: individualsList =>
6667
request.add[List[IndividualProvidedDetails]](individualsList)
6768

68-
// TODO: extract logic of choosing view and rendering it based on NumberOfRequiredKeyIndividuals, Form[] and businessPartnerRecord
69-
7069
def show: Action[AnyContent] = baseAction
7170
.async:
7271
implicit request: RequestWithData[DataWithList] =>
7372
val formAction: Call = AppRoutes.apply.listdetails.otherrelevantindividuals.EnterOtherRelevantIndividualController.submit
7473
Future.successful(Ok(enterIndividualNameSimplePage(
75-
form = IndividualNameForm.form,
76-
formAction = formAction
74+
form = OtherRelevantIndividualNameForm.form,
75+
formAction = formAction,
76+
ordinalKey = MessageKeys.ordinalKey(
77+
existingSize =
78+
request.get[List[IndividualProvidedDetails]]
79+
.filterNot(_.isPersonOfControl)
80+
.size,
81+
isOnlyOne = false
82+
)
7783
)))
7884

7985
def submit: Action[AnyContent] = baseAction
8086
.ensureValidFormAndRedirectIfSaveForLater[IndividualName](
81-
form = IndividualNameForm.form,
87+
form = OtherRelevantIndividualNameForm.form,
8288
resultToServeWhenFormHasErrors =
8389
implicit request =>
8490
(formWithErrors: Form[IndividualName]) =>
8591
val formAction: Call = AppRoutes.apply.listdetails.otherrelevantindividuals.EnterOtherRelevantIndividualController.submit
8692
Future.successful(BadRequest(enterIndividualNameSimplePage(
8793
form = formWithErrors,
88-
formAction = formAction
94+
formAction = formAction,
95+
ordinalKey = MessageKeys.ordinalKey(
96+
existingSize =
97+
request.get[List[IndividualProvidedDetails]]
98+
.filterNot(_.isPersonOfControl)
99+
.size,
100+
isOnlyOne = false
101+
)
89102
)))
90103
)
91104
.async:

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/listdetails/otherrelevantindividuals/RemoveOtherRelevantIndividualController.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import uk.gov.hmrc.agentregistration.shared.AgentApplication
2222
import uk.gov.hmrc.agentregistration.shared.AgentApplicationSoleTrader
2323
import uk.gov.hmrc.agentregistration.shared.individual.IndividualProvidedDetails
2424
import uk.gov.hmrc.agentregistration.shared.individual.IndividualProvidedDetailsId
25+
import uk.gov.hmrc.agentregistration.shared.util.SafeEquals.===
2526
import uk.gov.hmrc.agentregistrationfrontend.action.applicant.ApplicantActions
2627
import uk.gov.hmrc.agentregistrationfrontend.controllers.applicant.FrontendController
2728
import uk.gov.hmrc.agentregistrationfrontend.forms.RemoveKeyIndividualForm
@@ -42,7 +43,7 @@ class RemoveOtherRelevantIndividualController @Inject() (
4243
)
4344
extends FrontendController(mcc, actions):
4445

45-
private type DataWithIndividual = IndividualProvidedDetails *: IsNotSoleTrader *: DataWithAuth
46+
private type DataWithIndividual = IndividualProvidedDetails *: List[IndividualProvidedDetails] *: IsNotSoleTrader *: DataWithAuth
4647

4748
private def baseAction(individualProvidedDetailsId: IndividualProvidedDetailsId): ActionBuilderWithData[DataWithIndividual] = actions
4849
.getApplicationInProgress
@@ -55,15 +56,16 @@ extends FrontendController(mcc, actions):
5556
case aa: IsNotSoleTrader => request.replace[AgentApplication, IsNotSoleTrader](aa)
5657
.refine:
5758
implicit request =>
59+
val agentApplication: IsNotSoleTrader = request.get
5860
individualProvideDetailsService
59-
.findById(individualProvidedDetailsId)
60-
.map[RequestWithData[DataWithIndividual] | Result]:
61-
case Some(individualProvidedDetails) => request.add[IndividualProvidedDetails](individualProvidedDetails)
62-
case None =>
63-
logger.warn(
64-
"Number of required key individuals not specified in application, redirecting to number of key individuals page"
65-
)
66-
Redirect(AppRoutes.apply.AgentApplicationController.genericExitPage.url)
61+
.findAllByApplicationId(agentApplication.agentApplicationId).map: individualsList =>
62+
request.add[List[IndividualProvidedDetails]](individualsList.filterNot(_.isPersonOfControl))
63+
.refine:
64+
implicit request =>
65+
val individualProvidedDetails: IndividualProvidedDetails = request.get[List[IndividualProvidedDetails]]
66+
.find(_._id === individualProvidedDetailsId)
67+
.getOrThrowExpectedDataMissing("Individual to remove is not in the list of other relevant individuals")
68+
request.add[IndividualProvidedDetails](individualProvidedDetails)
6769

6870
def show(individualProvidedDetailsId: IndividualProvidedDetailsId): Action[AnyContent] =
6971
baseAction(individualProvidedDetailsId):
@@ -91,14 +93,15 @@ extends FrontendController(mcc, actions):
9193
implicit request =>
9294
val confirmRemoveIndividual: YesNo = request.get
9395
val individualProvidedDetails: IndividualProvidedDetails = request.get
96+
val existingListBeforeDeletion: List[IndividualProvidedDetails] = request.get
9497
confirmRemoveIndividual match
9598
case YesNo.Yes =>
9699
individualProvideDetailsService
97100
.delete(individualProvidedDetails._id)
98101
.map: _ =>
99-
Redirect(
100-
AppRoutes.apply.listdetails.otherrelevantindividuals.CheckYourAnswersController.show
101-
)
102+
if existingListBeforeDeletion.size > 1
103+
then Redirect(AppRoutes.apply.listdetails.otherrelevantindividuals.CheckYourAnswersController.show)
104+
else Redirect(AppRoutes.apply.listdetails.otherrelevantindividuals.ConfirmOtherRelevantIndividualsController.show)
102105
case YesNo.No =>
103106
Future.successful(
104107
Redirect(AppRoutes.apply.listdetails.otherrelevantindividuals.CheckYourAnswersController.show)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2024 HM Revenue & Customs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package uk.gov.hmrc.agentregistrationfrontend.forms
18+
19+
import play.api.data.Form
20+
import play.api.data.Forms
21+
import play.api.data.Forms.mapping
22+
import uk.gov.hmrc.agentregistration.shared.lists.IndividualName
23+
import uk.gov.hmrc.agentregistrationfrontend.forms.formatters.TextFormatter
24+
import uk.gov.hmrc.agentregistrationfrontend.forms.helpers.ErrorKeys
25+
26+
object OtherRelevantIndividualNameForm:
27+
28+
val key: String = "otherRelevantIndividualName"
29+
30+
private def canonicalise(name: String): String = name.trim.replaceAll("\\s+", " ")
31+
32+
val form: Form[IndividualName] = Form[IndividualName](
33+
mapping(
34+
key -> Forms.of(TextFormatter(ErrorKeys.requiredFieldErrorMessage(key)))
35+
.transform[String](canonicalise, identity)
36+
.verifying(
37+
ErrorKeys.inputTooLongErrorMessage(key),
38+
_.length <= 100
39+
)
40+
.transform[IndividualName](IndividualName(_), _.value)
41+
.verifying(
42+
ErrorKeys.invalidInputErrorMessage(key),
43+
_.isValidName
44+
)
45+
)(identity)(Some(_))
46+
)

app/uk/gov/hmrc/agentregistrationfrontend/views/applicant/listdetails/otherrelevantindividuals/ConfirmOtherRelevantIndividualsPage.scala.html

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
* limitations under the License.
1515
*@
1616

17+
@import uk.gov.hmrc.hmrcfrontend.views.html.helpers.HmrcNewTabLinkHelper
18+
@import uk.gov.hmrc.hmrcfrontend.views.viewmodels.newtablinkhelper.NewTabLinkHelper
19+
1720
@import uk.gov.hmrc.agentregistration.shared.AgentApplication
1821
@import uk.gov.hmrc.agentregistration.shared.AgentApplicationLimitedCompany
1922
@import uk.gov.hmrc.agentregistration.shared.AgentApplicationLlp
2023
@import uk.gov.hmrc.agentregistration.shared.AgentApplicationSoleTrader
24+
@import uk.gov.hmrc.agentregistrationfrontend.config.AppConfig
2125
@import uk.gov.hmrc.agentregistrationfrontend.forms.ConfirmOtherRelevantIndividualsForm
2226
@import uk.gov.hmrc.agentregistrationfrontend.forms.YesNo
2327
@import uk.gov.hmrc.agentregistrationfrontend.forms.YesNo.*
@@ -30,7 +34,9 @@
3034
govukRadios: GovukRadios,
3135
formWithCSRF: FormWithCSRF,
3236
govukButton: GovukButton,
33-
continueOrSaveForLater: ContinueOrSaveForLater
37+
continueOrSaveForLater: ContinueOrSaveForLater,
38+
hmrcNewTabLinkHelper: HmrcNewTabLinkHelper,
39+
appConfig: AppConfig
3440
)
3541

3642
@(
@@ -53,8 +59,7 @@
5359
}
5460
}
5561

56-
@h1 = @{messages(s"$key.heading.$businessTypeKey")}
57-
@question = @{messages(s"$key.question.$businessTypeKey", entityName)}
62+
@h1 = @{messages(s"$key.heading")}
5863

5964
@layout(
6065
pageTitle = h1,
@@ -64,31 +69,22 @@ <h2 class="govuk-caption-l">@messages(s"lists.caption.title.$businessTypeKey")</
6469

6570
<h1 class="govuk-heading-l">@h1</h1>
6671

67-
<p class="govuk-body">@messages(s"$key.intro.$businessTypeKey", entityName)</p>
68-
69-
<ul class="govuk-list govuk-list--bullet">
70-
<li>@messages(s"$key.responsibilities.bullet1")</li>
71-
<li>@messages(s"$key.responsibilities.bullet2")</li>
72-
</ul>
73-
74-
<h2 class="govuk-heading-m">@messages(s"$key.definition.heading.$businessTypeKey")</h2>
75-
76-
<p class="govuk-body">@messages(s"$key.definition.p1.$businessTypeKey")</p>
77-
<p class="govuk-body">@messages(s"$key.definition.p2.$businessTypeKey")</p>
72+
<p class="govuk-body">@messages(s"$key.p1")</p>
73+
<p class="govuk-body">@messages(s"$key.p2.$businessTypeKey", entityName)</p>
7874

79-
<p class="govuk-body">@messages(s"$key.definition.canBe.$businessTypeKey")</p>
80-
<ul class="govuk-list govuk-list--bullet">
81-
<li>@messages(s"$key.definition.bullet1.$businessTypeKey")</li>
82-
<li>@messages(s"$key.definition.bullet2.$businessTypeKey")</li>
83-
<li>@messages(s"$key.definition.bullet3.$businessTypeKey")</li>
84-
</ul>
75+
<p class="govuk-body">
76+
@hmrcNewTabLinkHelper(NewTabLinkHelper(
77+
text = messages(s"$key.guidanceLink"),
78+
href = Some(appConfig.guidanceForWhatARelevantTaxAdviserIsUrl),
79+
))
80+
</p>
8581

8682
@formWithCSRF(action = AppRoutes.apply.listdetails.otherrelevantindividuals.ConfirmOtherRelevantIndividualsController.submit) {
8783

8884
@govukRadios(Radios(
8985
fieldset = Some(Fieldset(
9086
legend = Some(Legend(
91-
content = Text(question),
87+
content = Text(messages(s"$key.label", entityName)),
9288
isPageHeading = false,
9389
classes = "govuk-fieldset__legend--m"
9490
))

app/uk/gov/hmrc/agentregistrationfrontend/views/applicant/listdetails/otherrelevantindividuals/EnterIndividualNamePage.scala.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*@
1616

1717
@import uk.gov.hmrc.agentregistration.shared.lists.IndividualName
18-
@import uk.gov.hmrc.agentregistrationfrontend.forms.IndividualNameForm
18+
@import uk.gov.hmrc.agentregistrationfrontend.forms.OtherRelevantIndividualNameForm
1919
@import uk.gov.hmrc.agentregistrationfrontend.views.html.Layout
2020
@import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.partials.ContinueOrSaveForLater
2121
@import uk.gov.hmrc.govukfrontend.views.html.components.implicits.RichInput
@@ -30,16 +30,17 @@
3030

3131
@(
3232
form: Form[IndividualName],
33-
formAction: Call
33+
formAction: Call,
34+
ordinalKey: String
3435
)(implicit
3536
request: RequestHeader,
3637
messages: Messages
3738
)
3839

3940
@key = @{
40-
IndividualNameForm.key
41+
OtherRelevantIndividualNameForm.key
4142
}
42-
@title = @{messages(s"$key.label.otherRelevantIndividuals")}
43+
@title = @{messages(s"$key.label.$ordinalKey")}
4344

4445
@layout(
4546
pageTitle = title,

conf/application.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ urls {
127127

128128
govuk-start-page = "https://www.gov.uk/guidance/get-an-hmrc-agent-services-account" //TODO: need to confirm
129129
govuk-hmrc-standard-for-agents = "https://www.gov.uk/government/publications/hmrc-the-standard-for-agents"
130+
govuk-guidance-on-relevant-tax-advisers = "https://www.gov.uk" // TODO: missing url
130131

131132
companies-house="https://beta.companieshouse.gov.uk/"
132133
contact-hmrc="https://www.gov.uk/contact-hmrc"

0 commit comments

Comments
 (0)