Skip to content

Commit fc63d76

Browse files
authored
feat: DFPL-2692 Applicant details added to next steps for HMCTS (#6087)
* DFPL-2692 give superuser access to Applicant Details events * DFPL-2692 make appropriate Applicant Details event visible * DFPL-2692 update to handle CTSC superuser updating Applicant Details * DFPL-2692 make Applicant's Details events available in all states except Deleted * linting * updating steps for local integration testing * DFPL-2692 remove unwanted line of code * DFPL-2692 updated for confirmed states event should be visible in * DFPL-2692 Add notification to applicant when CTSC amend details * DFPL-2692 don't exclude LA recipients * DFPL-2692 update integration tests * DFPL-2692 add test for ApplicantsDetailsUpdatedEventHandler * DFPL-2692 add test for ApplicantDetailsUpdatedContentProvider * DFPL-2692 add test to check email sent after Ctsc update * linting * linting * Adding temporary logging for testing * DFPL-2692 remove temporary logging * DFPL-2692 update content provider to handle LA respondents * linting * DFPL-2692 improve naming and tests * DFPL-2692 Exclude secondary LAs and LA Legal Reps from notification * DFPL-2692 change to check for specific idam role * DFPL-2692 fix typo * DFPL-2692 add second unit test
1 parent 52837f4 commit fc63d76

File tree

17 files changed

+370
-17
lines changed

17 files changed

+370
-17
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ Create the file in this location `service/src/integrationTest/resources/applicat
108108
(it's already included in .gitignore)
109109
```
110110
spring:
111-
profiles: email-template-test
111+
config:
112+
activate:
113+
on-profile: email-template-test
112114
113115
integration-test:
114116
notify-service:

ccd-definition/AuthorisationCaseEvent/CareSupervision/AuthorisationCaseEvent.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,8 @@
18331833
"[LASOLICITOR]",
18341834
"[LASHARED]",
18351835
"[LAMANAGING]",
1836-
"[EPSMANAGING]"
1836+
"[EPSMANAGING]",
1837+
"caseworker-publiclaw-superuser"
18371838
],
18381839
"CRUD": "CR"
18391840
}
@@ -1847,7 +1848,8 @@
18471848
{
18481849
"UserRoles": [
18491850
"[SOLICITORA]",
1850-
"[CHILDSOLICITORA]"
1851+
"[CHILDSOLICITORA]",
1852+
"caseworker-publiclaw-superuser"
18511853
],
18521854
"CRUD": "CR"
18531855
}

ccd-definition/AuthorisationCaseField/CareSupervision/superuser.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,5 +1762,40 @@
17621762
"CaseFieldID": "urgentDirectionsOrder",
17631763
"UserRole": "caseworker-publiclaw-superuser",
17641764
"CRUD": "CRUD"
1765+
},
1766+
{
1767+
"LiveFrom": "01/01/2017",
1768+
"CaseTypeID": "CARE_SUPERVISION_EPO",
1769+
"CaseFieldID": "applicantContactLabel",
1770+
"UserRole": "caseworker-publiclaw-superuser",
1771+
"CRUD": "CRUD"
1772+
},
1773+
{
1774+
"LiveFrom": "01/01/2017",
1775+
"CaseTypeID": "CARE_SUPERVISION_EPO",
1776+
"CaseFieldID": "applicantContact",
1777+
"UserRole": "caseworker-publiclaw-superuser",
1778+
"CRUD": "CRUD"
1779+
},
1780+
{
1781+
"LiveFrom": "01/01/2017",
1782+
"CaseTypeID": "CARE_SUPERVISION_EPO",
1783+
"CaseFieldID": "applicantContactOthers",
1784+
"UserRole": "caseworker-publiclaw-superuser",
1785+
"CRUD": "CRUD"
1786+
},
1787+
{
1788+
"LiveFrom": "01/01/2017",
1789+
"CaseTypeID": "CARE_SUPERVISION_EPO",
1790+
"CaseFieldID": "applicantOtherContactLabel",
1791+
"UserRole": "caseworker-publiclaw-superuser",
1792+
"CRUD": "CRUD"
1793+
},
1794+
{
1795+
"LiveFrom": "01/01/2017",
1796+
"CaseTypeID": "CARE_SUPERVISION_EPO",
1797+
"CaseFieldID": "localAuthority",
1798+
"UserRole": "caseworker-publiclaw-superuser",
1799+
"CRUD": "CRUD"
17651800
}
17661801
]

ccd-definition/CaseEvent/CareSupervision/MultiState.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,9 @@
10341034
"CallBackURLAboutToStartEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/about-to-start",
10351035
"CallBackURLAboutToSubmitEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/about-to-submit",
10361036
"CallBackURLSubmittedEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/submitted",
1037+
"EventEnablingCondition": "representativeType=\"LOCAL_AUTHORITY\"",
10371038
"ShowSummary": "Y",
1038-
"ShowEventNotes": "N",
1039+
"ShowEventNotes": "Y",
10391040
"EndButtonLabel": "Save and continue"
10401041
},
10411042
{
@@ -1051,8 +1052,9 @@
10511052
"CallBackURLAboutToStartEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/about-to-start",
10521053
"CallBackURLAboutToSubmitEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/about-to-submit",
10531054
"CallBackURLSubmittedEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/enter-local-authority/submitted",
1055+
"EventEnablingCondition": "representativeType=\"RESPONDENT_SOLICITOR\" OR representativeType=\"CHILD_SOLICITOR\"",
10541056
"ShowSummary": "Y",
1055-
"ShowEventNotes": "N",
1057+
"ShowEventNotes": "Y",
10561058
"EndButtonLabel": "Save and continue"
10571059
},
10581060
{

service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/applicant/ApplicantLocalAuthorityControllerAboutToStartTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import uk.gov.hmcts.reform.fpl.controllers.AbstractCallbackTest;
1313
import uk.gov.hmcts.reform.fpl.controllers.ApplicantLocalAuthorityController;
1414
import uk.gov.hmcts.reform.fpl.enums.State;
15+
import uk.gov.hmcts.reform.fpl.enums.UserRole;
1516
import uk.gov.hmcts.reform.fpl.model.Address;
1617
import uk.gov.hmcts.reform.fpl.model.Applicant;
1718
import uk.gov.hmcts.reform.fpl.model.ApplicantParty;
@@ -23,6 +24,7 @@
2324
import uk.gov.hmcts.reform.fpl.model.common.dynamic.DynamicList;
2425
import uk.gov.hmcts.reform.fpl.model.common.dynamic.DynamicListElement;
2526
import uk.gov.hmcts.reform.fpl.model.event.LocalAuthorityEventData;
27+
import uk.gov.hmcts.reform.fpl.service.UserService;
2628
import uk.gov.hmcts.reform.fpl.service.PbaService;
2729
import uk.gov.hmcts.reform.rd.client.OrganisationApi;
2830
import uk.gov.hmcts.reform.rd.model.ContactInformation;
@@ -47,6 +49,9 @@ class ApplicantLocalAuthorityControllerAboutToStartTest extends AbstractCallback
4749
@MockBean
4850
private OrganisationApi organisationApi;
4951

52+
@MockBean
53+
private UserService userService;
54+
5055
@MockBean
5156
private PbaService pbaService;
5257

@@ -69,6 +74,8 @@ void setup() {
6974
givenFplService();
7075
given(organisationApi.findUserOrganisation(USER_AUTH_TOKEN, SERVICE_AUTH_TOKEN))
7176
.willReturn(organisation);
77+
given(userService.hasAnyIdamRolesFrom(List.of(UserRole.HMCTS_SUPERUSER)))
78+
.willReturn(false);
7279
given(pbaService.populatePbaDynamicList("")).willReturn(DynamicList.builder()
7380
.value(DynamicListElement.builder()
7481
.code("PBA7654321")
@@ -135,7 +142,6 @@ void shouldPrePopulateLocalAuthorityDetailsFromReferenceData() {
135142

136143
@Test
137144
void shouldPopulateLocalAuthorityWithDataFromLegacyApplicant() {
138-
139145
final ApplicantParty legacyApplicant = ApplicantParty.builder()
140146
.organisationName("Applicant")
141147
.build();
@@ -180,8 +186,12 @@ void shouldPopulateLocalAuthorityWithDataFromLegacyApplicant() {
180186
assertThat(updatedCaseData.getLocalAuthorityEventData()).isEqualTo(expectedEventData);
181187
}
182188

183-
@Test
184-
void shouldGetExistingLocalAuthorityDetails() {
189+
@ParameterizedTest
190+
@ValueSource(booleans = {true, false})
191+
void shouldGetExistingLocalAuthorityDetails(boolean isSuperUser) {
192+
given(userService.hasAnyIdamRolesFrom(List.of(UserRole.HMCTS_SUPERUSER)))
193+
.willReturn(isSuperUser);
194+
185195
final Element<Colleague> colleague = element(Colleague.builder()
186196
.role(SOLICITOR)
187197
.fullName("Alex Smith")

service/src/integrationTest/java/uk/gov/hmcts/reform/fpl/controllers/applicant/ApplicantLocalAuthorityControllerSubmittedTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@
77
import org.springframework.boot.test.mock.mockito.MockBean;
88
import uk.gov.hmcts.reform.fpl.controllers.AbstractCallbackTest;
99
import uk.gov.hmcts.reform.fpl.controllers.ApplicantLocalAuthorityController;
10+
import uk.gov.hmcts.reform.fpl.enums.UserRole;
1011
import uk.gov.hmcts.reform.fpl.model.CaseData;
1112
import uk.gov.hmcts.reform.fpl.model.Colleague;
1213
import uk.gov.hmcts.reform.fpl.model.LocalAuthority;
14+
import uk.gov.hmcts.reform.fpl.service.UserService;
1315
import uk.gov.hmcts.reform.fpl.service.ccd.CoreCaseDataService;
16+
import uk.gov.hmcts.reform.fpl.service.email.NotificationService;
17+
18+
import java.util.List;
1419

1520
import static org.apache.commons.lang3.RandomUtils.nextLong;
1621
import static org.mockito.ArgumentMatchers.any;
22+
import static org.mockito.ArgumentMatchers.anyCollection;
1723
import static org.mockito.ArgumentMatchers.eq;
24+
import static org.mockito.BDDMockito.given;
1825
import static org.mockito.Mockito.timeout;
1926
import static org.mockito.Mockito.verify;
2027
import static uk.gov.hmcts.reform.fpl.Constants.LOCAL_AUTHORITY_1_CODE;
28+
import static uk.gov.hmcts.reform.fpl.NotifyTemplates.APPLICANTS_DETAILS_UPDATED;
2129
import static uk.gov.hmcts.reform.fpl.enums.ColleagueRole.SOLICITOR;
30+
import static uk.gov.hmcts.reform.fpl.enums.State.CASE_MANAGEMENT;
2231
import static uk.gov.hmcts.reform.fpl.enums.State.OPEN;
2332
import static uk.gov.hmcts.reform.fpl.enums.State.SUBMITTED;
2433
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements;
@@ -30,6 +39,12 @@ class ApplicantLocalAuthorityControllerSubmittedTest extends AbstractCallbackTes
3039
@MockBean
3140
private CoreCaseDataService coreCaseDataService;
3241

42+
@MockBean
43+
private UserService userService;
44+
45+
@MockBean
46+
private NotificationService notificationService;
47+
3348
ApplicantLocalAuthorityControllerSubmittedTest() {
3449
super("enter-local-authority");
3550
}
@@ -38,6 +53,8 @@ class ApplicantLocalAuthorityControllerSubmittedTest extends AbstractCallbackTes
3853
void setup() {
3954
givenSystemUser();
4055
givenFplService();
56+
given(userService.hasAnyIdamRolesFrom(List.of(UserRole.HMCTS_SUPERUSER)))
57+
.willReturn(false);
4158
}
4259

4360
@Test
@@ -85,6 +102,33 @@ void shouldUpdateCaseSummaryWhenCaseNotInOpenState() {
85102
any());
86103
}
87104

105+
@Test
106+
void shouldNotifyApplicantsWhenUpdatedBySuperuser() {
107+
final CaseData caseDataBefore = CaseData.builder()
108+
.id(nextLong())
109+
.caseLocalAuthority(LOCAL_AUTHORITY_1_CODE)
110+
.state(CASE_MANAGEMENT)
111+
.build();
112+
113+
final CaseData caseData = caseDataBefore.toBuilder()
114+
.localAuthorities(wrapElements(LocalAuthority.builder()
115+
.designated("Yes")
116+
.colleagues(wrapElements(solicitor()))
117+
.build()))
118+
.build();
119+
120+
given(userService.hasAnyIdamRolesFrom(List.of(UserRole.HMCTS_SUPERUSER)))
121+
.willReturn(true);
122+
123+
postSubmittedEvent(toCallBackRequest(caseData, caseDataBefore));
124+
125+
verify(notificationService).sendEmail(
126+
eq(APPLICANTS_DETAILS_UPDATED),
127+
anyCollection(),
128+
any(),
129+
eq(caseData.getId()));
130+
}
131+
88132
private static Colleague solicitor() {
89133
return Colleague.builder()
90134
.role(SOLICITOR)

service/src/main/java/uk/gov/hmcts/reform/fpl/NotifyTemplates.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ private NotifyTemplates() {
109109
public static final String VACATE_HEARING = "738d7a28-4699-4b32-a793-25436bf2d19c";
110110
public static final String GUARDIAN_UPDATED = "efc77c28-c32a-43d3-93f6-d75542d3743b";
111111
public static final String LEGAL_COUNSELLOR_REMOVED_THEMSELVES = "14f0ea3c-6b12-4d56-a1c2-775b3d01329e";
112+
public static final String APPLICANTS_DETAILS_UPDATED = "32ef0278-263c-4d70-983f-1bc68b687ea0";
112113
}

service/src/main/java/uk/gov/hmcts/reform/fpl/controllers/ApplicantLocalAuthorityController.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest;
1111
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
1212
import uk.gov.hmcts.reform.fpl.events.AfterSubmissionCaseDataUpdated;
13+
import uk.gov.hmcts.reform.fpl.events.ApplicantsDetailsUpdatedEvent;
1314
import uk.gov.hmcts.reform.fpl.events.CaseDataChanged;
1415
import uk.gov.hmcts.reform.fpl.model.CaseData;
1516
import uk.gov.hmcts.reform.fpl.model.LocalAuthority;
@@ -42,15 +43,21 @@ public AboutToStartOrSubmitCallbackResponse handleAboutToStart(@RequestBody Call
4243

4344
final CaseDetails caseDetails = request.getCaseDetails();
4445
final CaseData caseData = getCaseData(caseDetails);
45-
final LocalAuthority localAuthority = applicantLocalAuthorityService.getUserLocalAuthority(caseData);
46-
47-
// Only do these checks when not in open/returned states
48-
if (!List.of(OPEN, RETURNED).contains(caseData.getState())
49-
&& !applicantLocalAuthorityService.isApplicantOrOnBehalfOfOrgId(localAuthority.getId(), caseData)) {
50-
// user is not operating on behalf of the applicant - it's likely a respondent solicitor on a 3rd party
51-
// case (both actual applicant + respondent get [SOLICITORA] roles so can't do this via event permissions
52-
return respond(caseDetails,
53-
List.of("You must be the applicant or acting on behalf of the applicant to modify these details."));
46+
final LocalAuthority localAuthority;
47+
48+
if (applicantLocalAuthorityService.isCurrentUserHmctsSuperuser()) {
49+
localAuthority = caseData.getLocalAuthorities().get(0).getValue();
50+
} else {
51+
localAuthority = applicantLocalAuthorityService.getUserLocalAuthority(caseData);
52+
53+
// Only do these checks when not in open/returned states
54+
if (!List.of(OPEN, RETURNED).contains(caseData.getState())
55+
&& !applicantLocalAuthorityService.isApplicantOrOnBehalfOfOrgId(localAuthority.getId(), caseData)) {
56+
// user is not operating on behalf of the applicant (likely a respondent solicitor on a 3rd party case)
57+
// Both actual applicant + respondent get [SOLICITORA] roles so can't control via event permissions.
58+
return respond(caseDetails,
59+
List.of("You must be the applicant or acting on behalf of the applicant to modify these details."));
60+
}
5461
}
5562

5663
localAuthority.setPbaNumberDynamicList(pbaService.populatePbaDynamicList(localAuthority.getPbaNumber()));
@@ -121,5 +128,9 @@ public void handleSubmitted(@RequestBody CallbackRequest request) {
121128
} else {
122129
publishEvent(new AfterSubmissionCaseDataUpdated(caseData, caseDataBefore));
123130
}
131+
132+
if (applicantLocalAuthorityService.isCurrentUserHmctsSuperuser()) {
133+
publishEvent(new ApplicantsDetailsUpdatedEvent(caseData));
134+
}
124135
}
125136
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package uk.gov.hmcts.reform.fpl.events;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
import uk.gov.hmcts.reform.fpl.model.CaseData;
6+
7+
@Getter
8+
@RequiredArgsConstructor
9+
public class ApplicantsDetailsUpdatedEvent {
10+
private final CaseData caseData;
11+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package uk.gov.hmcts.reform.fpl.handlers;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.event.EventListener;
6+
import org.springframework.scheduling.annotation.Async;
7+
import org.springframework.stereotype.Component;
8+
import uk.gov.hmcts.reform.fpl.events.ApplicantsDetailsUpdatedEvent;
9+
import uk.gov.hmcts.reform.fpl.model.CaseData;
10+
import uk.gov.hmcts.reform.fpl.model.notify.RecipientsRequest;
11+
import uk.gov.hmcts.reform.fpl.service.LocalAuthorityRecipientsService;
12+
import uk.gov.hmcts.reform.fpl.service.email.NotificationService;
13+
import uk.gov.hmcts.reform.fpl.service.email.content.ApplicantsDetailsUpdatedContentProvider;
14+
15+
import java.util.Set;
16+
17+
import static uk.gov.hmcts.reform.fpl.NotifyTemplates.APPLICANTS_DETAILS_UPDATED;
18+
19+
@Component
20+
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
21+
public class ApplicantsDetailsUpdatedEventHandler {
22+
private final ApplicantsDetailsUpdatedContentProvider contentProvider;
23+
private final LocalAuthorityRecipientsService localAuthorityRecipients;
24+
private final NotificationService notificationService;
25+
26+
@Async
27+
@EventListener
28+
void notifyLocalAuthorities(final ApplicantsDetailsUpdatedEvent event) {
29+
final CaseData caseData = event.getCaseData();
30+
final RecipientsRequest recipientsRequest = RecipientsRequest.builder()
31+
.caseData(caseData)
32+
.secondaryLocalAuthorityExcluded(true)
33+
.legalRepresentativesExcluded(true)
34+
.build();
35+
36+
final Set<String> recipients = localAuthorityRecipients.getRecipients(recipientsRequest);
37+
38+
notificationService.sendEmail(APPLICANTS_DETAILS_UPDATED, recipients,
39+
contentProvider.getApplicantsDetailsUpdatedNotifyData(caseData), caseData.getId());
40+
}
41+
}

0 commit comments

Comments
 (0)