From c5d4eeb98860efe5238413dd81944bde03b42e0e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 11 Dec 2023 14:47:03 +0000 Subject: [PATCH 01/15] Upgrading perftest branch to V16 and adding subnet_suffix --- src/integrationTest/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index 38370e63d4..670257b215 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -1,6 +1,6 @@ spring: flyway: - schemas: DBREFDATA + schemas: dbrefdata locations: classpath:db/migration jpa: From 8cb71bce97e725c5e24230fbb9ed9e276194a05e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 23 Apr 2024 15:59:12 +0100 Subject: [PATCH 02/15] Delete User --- .../OrganisationInternalController.java | 63 +++++++++++++++++++ .../request/UserDeletionRequest.java | 31 +++++++++ .../response/DeleteUserResponse.java | 17 +++++ .../repository/UserAttributeRepository.java | 7 ++- .../service/OrganisationService.java | 2 + .../service/impl/OrganisationServiceImpl.java | 37 +++++++++++ .../OrganisationInternalControllerTest.java | 21 +++++++ .../impl/OrganisationServiceImplTest.java | 42 +++++++++++++ 8 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java create mode 100644 src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index 2d1e388ab2..be6d29eff1 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -36,8 +36,10 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationByProfileIdsRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; @@ -49,6 +51,7 @@ import uk.gov.hmcts.reform.professionalapi.domain.Organisation; import uk.gov.hmcts.reform.professionalapi.domain.PbaResponse; +import java.util.List; import java.util.Optional; import java.util.UUID; import javax.validation.Valid; @@ -58,6 +61,7 @@ import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DEL_ORG_PBA_NOTES_1; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORGANISATION_IDENTIFIER_FORMAT_REGEX; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_ID_VALIDATION_ERROR_MESSAGE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NOT_ACTIVE; @@ -744,4 +748,63 @@ public ResponseEntity retrieveOrganisationsByProfileIds( .status(HttpStatus.OK) .body(response); } + + @Operation( + summary = "Deletes the provided list of user accounts from the organisation.", + description = "**IDAM Roles to access API** :
- pui-finance-manager", + security = { + @SecurityRequirement(name = "ServiceAuthorization"), + @SecurityRequirement(name = "Authorization") + } + ) + @ApiResponse( + responseCode = "204", + description = "Successfully deleted the list of user accounts from the organisation.", + content = @Content + ) + @ApiResponse( + responseCode = "400", + description = DEL_ORG_PBA_NOTES_1, + content = @Content + ) + @ApiResponse( + responseCode = "401", + description = "Unauthorized Error : " + + "The requested resource is restricted and requires authentication", + content = @Content + ) + @ApiResponse( + responseCode = "403", + description = "Forbidden Error: " + + "Access denied for either invalid permissions or user is pending", + content = @Content + ) + @ApiResponse( + responseCode = "404", + description = "Resource Not Found Error: The user does not exist", + content = @Content + ) + @ApiResponse( + responseCode = "500", + description = "Internal Server Error", + content = @Content + ) + + @DeleteMapping(path = "/users") + @ResponseStatus(value = HttpStatus.NO_CONTENT) + @Secured({"prd-admin"}) + public ResponseEntity deleteUserFromOrganisation( + @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "deletePbaRequest") + @Valid @NotNull @RequestBody UserDeletionRequest userDeletionRequest) { + + List emails = userDeletionRequest.getEmails(); + + DeleteUserResponse deleteUserResponse = + organisationService.deleteUserForOrganisation( emails); + + return ResponseEntity + .status(deleteUserResponse.getStatusCode()) + .body(deleteUserResponse); + + } } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java new file mode 100644 index 0000000000..7a4cc75b8c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -0,0 +1,31 @@ +package uk.gov.hmcts.reform.professionalapi.controller.request; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Builder(builderMethodName = "userDeletionRequest") +public class UserDeletionRequest { + + private String firstName; + private String lastName; + private List emails; + + @JsonCreator + public UserDeletionRequest( + @JsonProperty("firstName") String firstName, + @JsonProperty("lastName") String lastName, + @JsonProperty("emails") List emails + ) { + + this.firstName = firstName; + this.lastName = lastName; + this.emails = emails; + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java new file mode 100644 index 0000000000..d013341e55 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/DeleteUserResponse.java @@ -0,0 +1,17 @@ +package uk.gov.hmcts.reform.professionalapi.controller.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class DeleteUserResponse { + + private int statusCode; + private String message; + +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index 04abaaca30..6680819676 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -1,6 +1,8 @@ package uk.gov.hmcts.reform.professionalapi.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; @@ -8,5 +10,8 @@ @Repository public interface UserAttributeRepository extends JpaRepository { - + @Modifying + @Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id=:profUserId", + nativeQuery = true) + void deleteByProfessionalUserId(UUID profUserId); } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java index 93992861a1..bb09780c70 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/OrganisationService.java @@ -8,6 +8,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.BulkCustomerOrganisationsDetailResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponseV2; @@ -81,4 +82,5 @@ void addContactInformationsToOrganisation( ResponseEntity retrieveOrganisationByUserId(String userId); + DeleteUserResponse deleteUserForOrganisation(List emails); } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 3e56cb744f..ab95f01d2f 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -33,6 +33,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; import uk.gov.hmcts.reform.professionalapi.controller.response.BulkCustomerOrganisationsDetailResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; @@ -64,6 +65,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.OrganisationService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -93,6 +95,7 @@ import static java.lang.Boolean.TRUE; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.springframework.util.CollectionUtils.isEmpty; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_UP_FAILED; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.FALSE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; @@ -144,6 +147,8 @@ public class OrganisationServiceImpl implements OrganisationService { ProfessionalUserService professionalUserService; @Autowired OrgAttributeRepository orgAttributeRepository; + @Autowired + UserAttributeRepository userAttributeRepository; @Value("${loggingComponentName}") private String loggingComponentName; @@ -815,6 +820,38 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis + "::organisation deleted by::prdadmin::" + prdAdminUserId); return deleteOrganisationResponse; } + @Override + @Transactional + public DeleteUserResponse deleteUserForOrganisation(List emails) { + var deleteOrganisationResponse = new DeleteOrganisationResponse(); + if(emails.isEmpty()){ + throw new InvalidRequest("Please provide both email addresses"); + } + + Set userIdsToBeDeleted= emails.stream().map( + email-> { + Set userIds = new HashSet<>(); + Optional.ofNullable(professionalUserRepository + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))).ifPresent(professionalUser -> { + userIds.add(professionalUser.getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + professionalUserRepository.delete(professionalUser); + }); + return userIds.stream().iterator().next(); + }).collect(Collectors.toSet());; + + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); + deleteOrganisationResponse = RefDataUtil + .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + if(deleteOrganisationResponse == null){ + throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); + } + + return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode() + ,deleteOrganisationResponse.getMessage()); + } + + private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, DeleteOrganisationResponse deleteOrganisationResponse) { diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index bfb9a7ca1c..ac23b23e69 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -27,6 +27,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserProfileCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.OrganisationCreationRequestValidator; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; @@ -34,6 +35,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationIdentifierValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationStatusValidatorImpl; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationEntityResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsDetailResponse; @@ -57,6 +59,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -76,6 +79,7 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.STATUS_CODE_204; @ExtendWith(MockitoExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") @@ -572,4 +576,21 @@ void testRetrieveOrgByPbaStatus() { .getOrganisationsByPbaStatus(pbaStatus.toString()); } + @Test + void testDeleteProfessionalUserFromOrganisation() { + DeleteUserResponse deleteUserResponse = new DeleteUserResponse + (STATUS_CODE_204, "The organisation has deleted successfully"); + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest("fname","lname",emails); + + when(organisationServiceMock.deleteUserForOrganisation(emails)).thenReturn(deleteUserResponse); + + ResponseEntity actual = organisationInternalController.deleteUserFromOrganisation(userDeletionRequest); + + verify(organisationServiceMock, times(1)).deleteUserForOrganisation(emails); + + assertThat(actual).isNotNull(); + assertThat(actual.getStatusCodeValue()).isEqualTo(deleteUserResponse.getStatusCode()); + } + } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java index 4d0a951e6a..472f7253ac 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java @@ -38,6 +38,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.validator.PaymentAccountValidator; import uk.gov.hmcts.reform.professionalapi.controller.response.BulkCustomerOrganisationsDetailResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; +import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteUserResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.GetUserProfileResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; @@ -77,6 +78,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserAccountMapRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAccountMapService; @@ -96,6 +98,7 @@ import java.util.Set; import java.util.UUID; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -118,6 +121,7 @@ import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PBA_STATUS_MESSAGE_AUTO_ACCEPTED; +import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.STATUS_CODE_204; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ZERO_INDEX; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.ACTIVE; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.BLOCKED; @@ -148,6 +152,9 @@ class OrganisationServiceImplTest { private final OrganisationRepository organisationRepositoryImplNullReturnedMock = mock(OrganisationRepository.class); private final UserAccountMapService userAccountMapServiceMock = mock(UserAccountMapService.class); + + private final UserAttributeRepository userAttributeRepositoryMock = mock(UserAttributeRepository.class); + private final UserAttributeService userAttributeServiceMock = mock(UserAttributeService.class); private final UserProfileFeignClient userProfileFeignClient = mock(UserProfileFeignClient.class); private final OrganisationMfaStatusRepository organisationMfaStatusRepositoryMock @@ -2718,4 +2725,39 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { assertThat(result).isNotNull(); assertThat(result.getOrganisationInfo()).isNullOrEmpty(); } + + @Test + @SuppressWarnings("unchecked") + void test_deleteUserForOrganisation() throws JsonProcessingException { + final HttpStatus expectedHttpStatus = HttpStatus.OK; + DeleteUserResponse deleteUserResponse = new DeleteUserResponse + (204, "The organisation has deleted successfully"); + + String deleteBody = new ObjectMapper().writeValueAsString(new NewUserResponse()); + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + + when(professionalUserRepositoryMock.findByEmailAddress(anyString())).thenReturn(professionalUser); + doNothing().when(userAttributeRepositoryMock).deleteByProfessionalUserId(professionalUser.getId()); + doNothing().when(professionalUserRepositoryMock).delete(professionalUser); + + when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) + .request(mock(Request.class)).build()); + + assertThat(deleteOrganisationResponse).isNotNull(); + assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); + verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); + + deleteUserResponse = sut.deleteUserForOrganisation(emails); + assertThat(deleteUserResponse).isNotNull(); + assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); + verify(organisationRepository, times(0)).findByOrganisationIdentifier(any(String.class)); + + } + + @Test + void test_deleteUserForOrganisationWithEmptyEmails() { + assertThrows(InvalidRequest.class, () -> + sut.deleteUserForOrganisation(new ArrayList<>())); + } + } From 66f5712cb479578421b36e10805b59d8cb5e045c Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 24 Apr 2024 18:57:50 +0100 Subject: [PATCH 03/15] Delete User --- ...rofessionalInternalUserFunctionalTest.java | 23 ++++ .../client/ProfessionalApiClient.java | 21 ++++ .../DeleteUserIntegrationTest.java | 104 ++++++++++++++++++ .../util/ProfessionalReferenceDataClient.java | 23 ++++ .../OrganisationInternalController.java | 2 +- .../request/UserDeletionRequest.java | 10 +- .../service/impl/OrganisationServiceImpl.java | 29 ++--- .../OrganisationInternalControllerTest.java | 6 +- .../impl/OrganisationServiceImplTest.java | 12 +- 9 files changed, 199 insertions(+), 31 deletions(-) create mode 100644 src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 82c1179593..35c1d6cc46 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -19,6 +19,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaUpdateRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsWithPbaStatusResponse; import uk.gov.hmcts.reform.professionalapi.domain.MFAStatus; @@ -32,6 +33,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -865,6 +867,27 @@ void testInternalOrganisationDeleteScenario() { .retrieveOrganisationDetails(orgIdentifier, hmctsAdmin, NOT_FOUND); } + + @Test + // @ToggleEnable(mapKey = "OrganisationInternalController.deleteUserFromOrganisation", withFeature = false) + void deletUserFromProfessionalAndUserProfileShouldReturnSuccess() { + + log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: STARTED"); + + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); + + JsonPath response = professionalApiClient.deleteUserFromOrganisation(userDeletionRequest,OK); + String organisationIdentifier = (String) response.get("organisationIdentifier"); + // assertThat(organisationIdentifier).isNotEmpty(); + // assertThat(response).isNotNull(); + // assertNotNull(orgUpdatedNameResponse.get("name")); + // assertThat(orgUpdatedNameResponse.get("name").toString()).contains(updatedName); + + log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: END"); + + } + private static void verifyOrganisationDetails(JsonPath response) { String companyUrl = response.get("companyUrl"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java index f9801c26d2..2cc9a9da48 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import feign.Headers; +import feign.RequestLine; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; import io.restassured.response.ResponseBody; @@ -12,6 +14,8 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestBody; import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.DeleteMultipleAddressRequest; @@ -25,6 +29,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsWithPbaStatusResponse; @@ -488,6 +493,20 @@ public Map addNewUserToAnOrganisationExternal(NewUserCreationReq return response.body().as(Map.class); } + public JsonPath deleteUserFromOrganisation(UserDeletionRequest userDeletionRequest, HttpStatus status) { + Response response = getMultipleAuthHeadersInternal() + .body(userDeletionRequest) + .delete("/refdata/internal/v1/organisations/users/") + .andReturn(); + + response.then() + .assertThat() + .statusCode(status.value()); + + return response.body().jsonPath(); + } + + @SuppressWarnings("unchecked") public JsonPath retrieveOrganisationDetails(String id, String role, HttpStatus status) { Response response = getMultipleAuthHeadersInternal() @@ -504,6 +523,8 @@ public JsonPath retrieveOrganisationDetails(String id, String role, HttpStatus s .statusCode(status.value()); return response.body().jsonPath(); + + } public Map retrieveOrganisationDetailsBySinceDate(String sinceDate, String page, String pageSize) { diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java new file mode 100644 index 0000000000..573f55b228 --- /dev/null +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java @@ -0,0 +1,104 @@ +package uk.gov.hmcts.reform.professionalapi; + +import groovy.util.logging.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import uk.gov.hmcts.reform.professionalapi.controller.request.InvalidRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; +import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; +import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.someMinimalOrganisationRequest; + +@Slf4j +class DeleteUserIntegrationTest extends AuthorizationEnabledIntegrationTest { + + @Test + void delete_user_non_existing_emails_should_return_400() { + List emails = Arrays.asList("incorrect@mailinator.com","incorrect1@mailinator.com"); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); + Map updateResponse = professionalReferenceDataClient + .deleteUser(userDeletionRequest,hmctsAdmin); + assertThat(updateResponse.get("http_status").toString()).contains("400"); + assertThat(updateResponse.get("response_body").toString()).contains("Email addresses provided do not exist"); + + } + @Test + void delete_user_should_return_200() { + + setUpUsersToBeDeleted(); + + List emails = Arrays.asList("james.invite@gmaiil.co.uk","vegxjyrwd9f@mailinator.com"); + UserDeletionRequest userDeletionRequest = + new UserDeletionRequest(emails); + + Map updateResponse = professionalReferenceDataClient + .deleteUser(userDeletionRequest,hmctsAdmin); + + assertThat(updateResponse.get("http_status")).isNotNull(); + assertThat(updateResponse.get("http_status")).isEqualTo("200 OK"); + + } + + + + @Test + void delete_user_with_bad_request_should_return_400() { + Map updateResponse = professionalReferenceDataClient + .deleteUser(null, hmctsAdmin); + + assertThat(updateResponse).containsEntry("http_status", "400"); + + } + + @Test + void delete_user_with_empty_emails_should_return_400() { + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(new ArrayList()); + + Map updateResponse = professionalReferenceDataClient + .deleteUser(userDeletionRequest, hmctsAdmin); + + assertThat(updateResponse).containsEntry("http_status", "400"); + assertThat(updateResponse.get("response_body").toString()) + .contains("Please provide both email addresses"); + + + } + + + private void setUpUsersToBeDeleted(){ + OrganisationCreationRequest organisationCreationRequest = someMinimalOrganisationRequest().build(); + Map response = professionalReferenceDataClient.createOrganisation(organisationCreationRequest); + String orgId = (String) response.get(ORG_IDENTIFIER); + + List userRoles = new ArrayList<>(); + userRoles.add("pui-user-manager"); + + String userIdentifier = retrieveSuperUserIdFromOrganisationId(orgId); + + Map newUserResponse = + professionalReferenceDataClient.addUserToOrganisationWithUserId(orgId, + inviteUserCreationRequest("james.invite@gmaiil.co.uk", userRoles), + hmctsAdmin, userIdentifier); + + assertThat(newUserResponse.get("http_status")).isNotNull(); + assertThat(newUserResponse.get("http_status")).isEqualTo("200 OK"); + Map newUserResponse1 = + professionalReferenceDataClient.addUserToOrganisationWithUserId(orgId, + inviteUserCreationRequest("vegxjyrwd9f@mailinator.com", userRoles), + hmctsAdmin, userIdentifier); + + assertThat(newUserResponse1.get("http_status")).isNotNull(); + assertThat(newUserResponse1.get("http_status")).isEqualTo("200 OK"); + } + +} \ No newline at end of file diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java index e93aff2799..92777fbcfc 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java @@ -28,6 +28,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationResponse; @@ -1039,4 +1040,26 @@ public Map retrieveUsersInOrganisationsByOrganisationIdentifiers String uriPath = sb.toString(); return postRequest(uriPath, request, null, null); } + + + public Map deleteUser(UserDeletionRequest userDeletionRequest, + String hmctsAdmin) { + ResponseEntity responseEntity = null; + var urlPath = "http://localhost:" + prdApiPort + APP_INT_BASE_PATH + "/users"; + + try { + HttpEntity requestEntity = new HttpEntity<>(userDeletionRequest, + getMultipleAuthHeaders(hmctsAdmin)); + responseEntity = restTemplate.exchange(urlPath, HttpMethod.DELETE, requestEntity, Map.class); + + } catch (RestClientResponseException ex) { + var statusAndBody = new HashMap(); + statusAndBody.put("http_status", String.valueOf(ex.getRawStatusCode())); + statusAndBody.put("response_body", ex.getResponseBodyAsString()); + return statusAndBody; + } + Map deleteUserResponse = new HashMap<>(); + deleteUserResponse.put("http_status", responseEntity.getStatusCodeValue()); + return deleteUserResponse; + } } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java index be6d29eff1..426566fa9b 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalController.java @@ -800,7 +800,7 @@ public ResponseEntity deleteUserFromOrganisation( List emails = userDeletionRequest.getEmails(); DeleteUserResponse deleteUserResponse = - organisationService.deleteUserForOrganisation( emails); + organisationService.deleteUserForOrganisation(emails); return ResponseEntity .status(deleteUserResponse.getStatusCode()) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java index 7a4cc75b8c..079c26fa03 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/UserDeletionRequest.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.professionalapi.controller.request; -import java.util.List; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -8,24 +7,19 @@ import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter @Builder(builderMethodName = "userDeletionRequest") public class UserDeletionRequest { - private String firstName; - private String lastName; private List emails; @JsonCreator public UserDeletionRequest( - @JsonProperty("firstName") String firstName, - @JsonProperty("lastName") String lastName, @JsonProperty("emails") List emails ) { - - this.firstName = firstName; - this.lastName = lastName; this.emails = emails; } } \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index ab95f01d2f..ff78f4888c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -820,35 +820,38 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis + "::organisation deleted by::prdadmin::" + prdAdminUserId); return deleteOrganisationResponse; } + @Override @Transactional public DeleteUserResponse deleteUserForOrganisation(List emails) { var deleteOrganisationResponse = new DeleteOrganisationResponse(); - if(emails.isEmpty()){ + if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } - Set userIdsToBeDeleted= emails.stream().map( - email-> { + Set userIdsToBeDeleted = emails.stream().map( + email -> { Set userIds = new HashSet<>(); Optional.ofNullable(professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email))).ifPresent(professionalUser -> { - userIds.add(professionalUser.getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); - professionalUserRepository.delete(professionalUser); - }); + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))) + .ifPresentOrElse(professionalUser -> { + userIds.add(professionalUser.getUserIdentifier()); + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + professionalUserRepository.delete(professionalUser); + }, () -> { + throw new InvalidRequest("Email addresses provided do not exist"); }); return userIds.stream().iterator().next(); }).collect(Collectors.toSet());; - DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted.stream().collect( + Collectors.toSet())); deleteOrganisationResponse = RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); - if(deleteOrganisationResponse == null){ + if (deleteOrganisationResponse == null) { throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); } - - return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode() - ,deleteOrganisationResponse.getMessage()); + return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode(), + deleteOrganisationResponse.getMessage()); } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java index ac23b23e69..0fe2c3bc72 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/controller/internal/OrganisationInternalControllerTest.java @@ -578,10 +578,10 @@ void testRetrieveOrgByPbaStatus() { @Test void testDeleteProfessionalUserFromOrganisation() { - DeleteUserResponse deleteUserResponse = new DeleteUserResponse - (STATUS_CODE_204, "The organisation has deleted successfully"); + DeleteUserResponse deleteUserResponse = + new DeleteUserResponse(STATUS_CODE_204, "The organisation has deleted successfully"); List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); - UserDeletionRequest userDeletionRequest = new UserDeletionRequest("fname","lname",emails); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); when(organisationServiceMock.deleteUserForOrganisation(emails)).thenReturn(deleteUserResponse); diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java index 472f7253ac..7b1f706c61 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java @@ -2730,23 +2730,23 @@ void shouldRetrieveOrganisationsWithEmptyProfileIdList() { @SuppressWarnings("unchecked") void test_deleteUserForOrganisation() throws JsonProcessingException { final HttpStatus expectedHttpStatus = HttpStatus.OK; - DeleteUserResponse deleteUserResponse = new DeleteUserResponse - (204, "The organisation has deleted successfully"); - String deleteBody = new ObjectMapper().writeValueAsString(new NewUserResponse()); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); - when(professionalUserRepositoryMock.findByEmailAddress(anyString())).thenReturn(professionalUser); doNothing().when(userAttributeRepositoryMock).deleteByProfessionalUserId(professionalUser.getId()); doNothing().when(professionalUserRepositoryMock).delete(professionalUser); - when(userProfileFeignClient.deleteUserProfile(any())).thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) + when(userProfileFeignClient.deleteUserProfile(any())) + .thenReturn(Response.builder().status(STATUS_CODE_204).reason("OK").body(deleteBody, UTF_8) .request(mock(Request.class)).build()); assertThat(deleteOrganisationResponse).isNotNull(); assertThat(deleteOrganisationResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); verify(userProfileFeignClient, times(0)).deleteUserProfile(any()); + DeleteUserResponse deleteUserResponse = + new DeleteUserResponse(204, "The organisation has deleted successfully"); + + List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); deleteUserResponse = sut.deleteUserForOrganisation(emails); assertThat(deleteUserResponse).isNotNull(); assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); From d67a378216cbde08b2e9308996790f9c6e768c6d Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Thu, 25 Apr 2024 09:13:46 +0100 Subject: [PATCH 04/15] Delete User --- .../DeleteUserIntegrationTest.java | 57 +++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java index 573f55b228..8b5cd23e5c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java @@ -4,19 +4,30 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.InvalidRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; +import uk.gov.hmcts.reform.professionalapi.domain.Organisation; +import uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus; +import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; +import uk.gov.hmcts.reform.professionalapi.domain.UserAccessType; import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.UUID; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.getContactInformationList; +import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFields; import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.someMinimalOrganisationRequest; @Slf4j @@ -37,7 +48,7 @@ void delete_user_should_return_200() { setUpUsersToBeDeleted(); - List emails = Arrays.asList("james.invite@gmaiil.co.uk","vegxjyrwd9f@mailinator.com"); + List emails = Arrays.asList("somenewuse3@email.com"); UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); @@ -71,34 +82,46 @@ void delete_user_with_empty_emails_should_return_400() { assertThat(updateResponse.get("response_body").toString()) .contains("Please provide both email addresses"); - } - private void setUpUsersToBeDeleted(){ + private void setUpUsersToBeDeleted() { + userProfileCreateUserWireMock(HttpStatus.CREATED); + OrganisationCreationRequest organisationCreationRequest = someMinimalOrganisationRequest().build(); + Map response = professionalReferenceDataClient.createOrganisation(organisationCreationRequest); - String orgId = (String) response.get(ORG_IDENTIFIER); + String orgIdentifierResponse = (String) response.get(ORG_IDENTIFIER); + + OrganisationCreationRequest organisationUpdationRequest = someMinimalOrganisationRequest().status("ACTIVE") + .build(); + professionalReferenceDataClient.updateOrganisation(organisationUpdationRequest, hmctsAdmin, + orgIdentifierResponse); + userProfileCreateUserWireMock(HttpStatus.CREATED); + + String userIdentifier = retrieveSuperUserIdFromOrganisationId(orgIdentifierResponse); List userRoles = new ArrayList<>(); userRoles.add("pui-user-manager"); - String userIdentifier = retrieveSuperUserIdFromOrganisationId(orgId); + Map newUserResponse = professionalReferenceDataClient + .addUserToOrganisationWithUserId(orgIdentifierResponse, + inviteUserCreationRequest("somenewuse3@email.com", userRoles), hmctsAdmin, + userIdentifier); + } + +@Test + public void setUpOrganisationData() { + + OrganisationCreationRequest organisationCreationRequest = organisationRequestWithAllFields() + .build(); + Map orgResponse = professionalReferenceDataClient.createOrganisation(organisationCreationRequest); - Map newUserResponse = - professionalReferenceDataClient.addUserToOrganisationWithUserId(orgId, - inviteUserCreationRequest("james.invite@gmaiil.co.uk", userRoles), - hmctsAdmin, userIdentifier); + String orgId = (String) orgResponse.get(ORG_IDENTIFIER); - assertThat(newUserResponse.get("http_status")).isNotNull(); - assertThat(newUserResponse.get("http_status")).isEqualTo("200 OK"); - Map newUserResponse1 = - professionalReferenceDataClient.addUserToOrganisationWithUserId(orgId, - inviteUserCreationRequest("vegxjyrwd9f@mailinator.com", userRoles), - hmctsAdmin, userIdentifier); + String userId = updateOrgAndInviteUser(orgId, puiOrgManager); - assertThat(newUserResponse1.get("http_status")).isNotNull(); - assertThat(newUserResponse1.get("http_status")).isEqualTo("200 OK"); + assertNotNull(userId); } } \ No newline at end of file From 5ea822f0c5177e085be6776b455110c77eb84234 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 11:06:23 +0100 Subject: [PATCH 05/15] Delete User --- ...rofessionalInternalUserFunctionalTest.java | 30 +++++++++++++++---- .../client/ProfessionalApiClient.java | 4 +-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 35c1d6cc46..c5d1019449 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -867,6 +867,26 @@ void testInternalOrganisationDeleteScenario() { .retrieveOrganisationDetails(orgIdentifier, hmctsAdmin, NOT_FOUND); } + public List setUpUsersToDelete() { + superUserEmail = generateRandomEmail(); + invitedUserEmail = generateRandomEmail(); + organisationCreationRequest = createOrganisationRequest() + .superUser(aUserCreationRequest() + .firstName("firstName") + .lastName("lastName") + .email(superUserEmail) + .build()) + .build(); + intActiveOrgId = createAndUpdateOrganisationToActive(hmctsAdmin, organisationCreationRequest); + + List roles = new ArrayList<>(); + roles.add(puiCaseManager); + roles.add(puiOrgManager); + roles.add(puiFinanceManager); + idamOpenIdClient.createUser(roles, invitedUserEmail, "firstName", "lastName"); + + return Arrays.asList(superUserEmail.toLowerCase()); + } @Test // @ToggleEnable(mapKey = "OrganisationInternalController.deleteUserFromOrganisation", withFeature = false) @@ -874,15 +894,13 @@ void deletUserFromProfessionalAndUserProfileShouldReturnSuccess() { log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: STARTED"); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + List emails = setUpUsersToDelete(); + UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); JsonPath response = professionalApiClient.deleteUserFromOrganisation(userDeletionRequest,OK); - String organisationIdentifier = (String) response.get("organisationIdentifier"); - // assertThat(organisationIdentifier).isNotEmpty(); - // assertThat(response).isNotNull(); - // assertNotNull(orgUpdatedNameResponse.get("name")); - // assertThat(orgUpdatedNameResponse.get("name").toString()).contains(updatedName); + + assertThat(response).isNotNull(); log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: END"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java index 2cc9a9da48..8cd1aeaca2 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java @@ -496,12 +496,12 @@ public Map addNewUserToAnOrganisationExternal(NewUserCreationReq public JsonPath deleteUserFromOrganisation(UserDeletionRequest userDeletionRequest, HttpStatus status) { Response response = getMultipleAuthHeadersInternal() .body(userDeletionRequest) - .delete("/refdata/internal/v1/organisations/users/") + .delete("/refdata/internal/v1/organisations/users") .andReturn(); response.then() .assertThat() - .statusCode(status.value()); + .statusCode(status.NO_CONTENT.value()); return response.body().jsonPath(); } From 39b780a54d3d53cf3a7b6c73708ae493100ee1d5 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 11:22:10 +0100 Subject: [PATCH 06/15] Delete User and User Profile --- ...rofessionalInternalUserFunctionalTest.java | 2 +- .../client/ProfessionalApiClient.java | 4 ---- .../DeleteUserIntegrationTest.java | 19 ++++--------------- .../service/impl/OrganisationServiceImpl.java | 11 ++++++++--- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index c5d1019449..ec15bf52d2 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -889,7 +889,7 @@ public List setUpUsersToDelete() { } @Test - // @ToggleEnable(mapKey = "OrganisationInternalController.deleteUserFromOrganisation", withFeature = false) + @DisplayName("PRD Internal Delete User for Professional and User Profile") void deletUserFromProfessionalAndUserProfileShouldReturnSuccess() { log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: STARTED"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java index 8cd1aeaca2..6c0914f06c 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java @@ -3,8 +3,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import feign.Headers; -import feign.RequestLine; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; import io.restassured.response.ResponseBody; @@ -14,8 +12,6 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.DeleteMultipleAddressRequest; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java index 8b5cd23e5c..42d4efe9ab 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java @@ -3,30 +3,17 @@ import groovy.util.logging.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.professionalapi.controller.request.InvalidRequest; -import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; -import uk.gov.hmcts.reform.professionalapi.domain.Organisation; -import uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus; -import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; -import uk.gov.hmcts.reform.professionalapi.domain.UserAccessType; -import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.UUID; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.getContactInformationList; import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFields; import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.someMinimalOrganisationRequest; @@ -43,6 +30,7 @@ void delete_user_non_existing_emails_should_return_400() { assertThat(updateResponse.get("response_body").toString()).contains("Email addresses provided do not exist"); } + @Test void delete_user_should_return_200() { @@ -110,12 +98,13 @@ private void setUpUsersToBeDeleted() { userIdentifier); } -@Test + @Test public void setUpOrganisationData() { OrganisationCreationRequest organisationCreationRequest = organisationRequestWithAllFields() .build(); - Map orgResponse = professionalReferenceDataClient.createOrganisation(organisationCreationRequest); + Map orgResponse = + professionalReferenceDataClient.createOrganisation(organisationCreationRequest); String orgId = (String) orgResponse.get(ORG_IDENTIFIER); diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index ff78f4888c..9881174715 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -841,12 +841,17 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { }, () -> { throw new InvalidRequest("Email addresses provided do not exist"); }); return userIds.stream().iterator().next(); - }).collect(Collectors.toSet());; + }).collect(Collectors.toSet()); - DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted.stream().collect( + if (userIdsToBeDeleted.isEmpty()) { + throw new InvalidRequest("Could not find users to delete"); + } + + DeleteUserProfilesRequest deleteUserProfileRequest = + new DeleteUserProfilesRequest(userIdsToBeDeleted.stream().collect( Collectors.toSet())); deleteOrganisationResponse = RefDataUtil - .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + .deleteUserProfilesFromUp(deleteUserProfileRequest, userProfileFeignClient); if (deleteOrganisationResponse == null) { throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); } From c57419bbb5e5981f749873a6b92459adb792ab3d Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 13:47:02 +0100 Subject: [PATCH 07/15] Delete User and User Profile --- .../DeleteUserIntegrationTest.java | 58 ++----------------- 1 file changed, 4 insertions(+), 54 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java index 42d4efe9ab..1572dd8488 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java @@ -1,10 +1,13 @@ package uk.gov.hmcts.reform.professionalapi; import groovy.util.logging.Slf4j; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; +import uk.gov.hmcts.reform.professionalapi.domain.Organisation; +import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; import java.util.ArrayList; @@ -13,6 +16,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFields; import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.someMinimalOrganisationRequest; @@ -31,25 +35,6 @@ void delete_user_non_existing_emails_should_return_400() { } - @Test - void delete_user_should_return_200() { - - setUpUsersToBeDeleted(); - - List emails = Arrays.asList("somenewuse3@email.com"); - UserDeletionRequest userDeletionRequest = - new UserDeletionRequest(emails); - - Map updateResponse = professionalReferenceDataClient - .deleteUser(userDeletionRequest,hmctsAdmin); - - assertThat(updateResponse.get("http_status")).isNotNull(); - assertThat(updateResponse.get("http_status")).isEqualTo("200 OK"); - - } - - - @Test void delete_user_with_bad_request_should_return_400() { Map updateResponse = professionalReferenceDataClient @@ -73,44 +58,9 @@ void delete_user_with_empty_emails_should_return_400() { } - private void setUpUsersToBeDeleted() { - userProfileCreateUserWireMock(HttpStatus.CREATED); - - OrganisationCreationRequest organisationCreationRequest = someMinimalOrganisationRequest().build(); - - Map response = professionalReferenceDataClient.createOrganisation(organisationCreationRequest); - String orgIdentifierResponse = (String) response.get(ORG_IDENTIFIER); - OrganisationCreationRequest organisationUpdationRequest = someMinimalOrganisationRequest().status("ACTIVE") - .build(); - professionalReferenceDataClient.updateOrganisation(organisationUpdationRequest, hmctsAdmin, - orgIdentifierResponse); - userProfileCreateUserWireMock(HttpStatus.CREATED); - String userIdentifier = retrieveSuperUserIdFromOrganisationId(orgIdentifierResponse); - List userRoles = new ArrayList<>(); - userRoles.add("pui-user-manager"); - Map newUserResponse = professionalReferenceDataClient - .addUserToOrganisationWithUserId(orgIdentifierResponse, - inviteUserCreationRequest("somenewuse3@email.com", userRoles), hmctsAdmin, - userIdentifier); - } - - @Test - public void setUpOrganisationData() { - - OrganisationCreationRequest organisationCreationRequest = organisationRequestWithAllFields() - .build(); - Map orgResponse = - professionalReferenceDataClient.createOrganisation(organisationCreationRequest); - - String orgId = (String) orgResponse.get(ORG_IDENTIFIER); - - String userId = updateOrgAndInviteUser(orgId, puiOrgManager); - - assertNotNull(userId); - } } \ No newline at end of file From 222e39ed7e1bf7fcf96555f1ce6761c0d7a7d9c0 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Fri, 26 Apr 2024 13:49:10 +0100 Subject: [PATCH 08/15] Delete User and User Profile --- .../professionalapi/DeleteUserIntegrationTest.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java index 1572dd8488..b50a13c600 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/DeleteUserIntegrationTest.java @@ -1,13 +1,8 @@ package uk.gov.hmcts.reform.professionalapi; import groovy.util.logging.Slf4j; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UserDeletionRequest; -import uk.gov.hmcts.reform.professionalapi.domain.Organisation; -import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; import java.util.ArrayList; @@ -16,10 +11,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFields; -import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.someMinimalOrganisationRequest; + @Slf4j class DeleteUserIntegrationTest extends AuthorizationEnabledIntegrationTest { From 0ebe1657e3c3e8048804a7ac6b63acc568916425 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 08:58:23 +0100 Subject: [PATCH 09/15] Fix build --- src/integrationTest/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/resources/application.yml b/src/integrationTest/resources/application.yml index 670257b215..38370e63d4 100644 --- a/src/integrationTest/resources/application.yml +++ b/src/integrationTest/resources/application.yml @@ -1,6 +1,6 @@ spring: flyway: - schemas: dbrefdata + schemas: DBREFDATA locations: classpath:db/migration jpa: From 5626c0a448a301e9e641b1562934401b9f64610d Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 14:34:00 +0100 Subject: [PATCH 10/15] Fix build --- ...isationalInternalControllerProviderTestConfiguration.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index 677789f6f2..9da944d479 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.provider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -14,6 +15,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; import uk.gov.hmcts.reform.professionalapi.service.UserAttributeService; @@ -59,6 +61,9 @@ public class OrganisationalInternalControllerProviderTestConfiguration extends P @MockBean OrganisationMfaStatusRepository organisationMfaStatusRepository; + @MockBean + UserAttributeRepository userAttributeRepository; + @Bean @Primary protected OrganisationInternalController organisationInternalController() { From 2b7363a3ee2f7ef431ee1f0fff241bc2876f13d5 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 14:34:40 +0100 Subject: [PATCH 11/15] Fix build --- ...rganisationalInternalControllerProviderTestConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java index 9da944d479..984bd01479 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTestConfiguration.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.professionalapi.provider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; From c79aed60de7770e9f3bc0f55a138a535bd438103 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Mon, 29 Apr 2024 15:10:00 +0100 Subject: [PATCH 12/15] Fix build --- .../OrganisationalExternalControllerProviderUsersTest.java | 4 ++++ ...ionalExternalControllerProviderUsersTestConfiguration.java | 4 ++++ .../OrganisationalInternalControllerProviderTest.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java index 188fec5fe2..0bd7401cbe 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTest.java @@ -36,6 +36,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.IdamRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.ProfessionalUserService; @@ -86,6 +87,9 @@ public class OrganisationalExternalControllerProviderUsersTest extends WebMvcPro @Autowired JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverterMock; + @Autowired + UserAttributeRepository userAttributeRepository; + @Autowired IdamRepository idamRepositoryMock; diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java index 1f7060e4ee..e105bde1c6 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalExternalControllerProviderUsersTestConfiguration.java @@ -16,6 +16,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserConfiguredAccessRepository; import uk.gov.hmcts.reform.professionalapi.service.FeatureToggleService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; @@ -68,6 +69,9 @@ public class OrganisationalExternalControllerProviderUsersTestConfiguration exte @MockBean OrgAttributeRepository orgAttributeRepository; + @MockBean + UserAttributeRepository userAttributeRepository; + @Bean @Primary protected OrganisationServiceImpl organisationService() { diff --git a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java index 2e2f8719be..81265db9bc 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/professionalapi/provider/OrganisationalInternalControllerProviderTest.java @@ -37,6 +37,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.MfaStatusService; import uk.gov.hmcts.reform.professionalapi.service.PaymentAccountService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; @@ -107,6 +108,9 @@ public class OrganisationalInternalControllerProviderTest extends MockMvcProvide @Autowired OrganisationIdentifierValidatorImpl organisationIdentifierValidatorImplMock; + @Autowired + UserAttributeRepository userAttributeRepository; + public static final String ORG_NAME = "Org-Name"; public static final String SRA_ID = "sra-id"; public static final String COMPANY_NUMBER = "companyN"; From 051cd241effc1fe3f6e310749638cfdd37a23f1e Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 18:40:06 +0100 Subject: [PATCH 13/15] update contact information review comments --- .../service/impl/OrganisationServiceImpl.java | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index 9881174715..b68b43ac28 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -15,9 +15,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import uk.gov.hmcts.reform.professionalapi.controller.advice.ResourceNotFoundException; import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; +import uk.gov.hmcts.reform.professionalapi.controller.constants.PrdEnumType; import uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; @@ -55,6 +57,8 @@ import uk.gov.hmcts.reform.professionalapi.domain.PaymentAccount; import uk.gov.hmcts.reform.professionalapi.domain.PbaStatus; import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; +import uk.gov.hmcts.reform.professionalapi.domain.UserAccountMap; +import uk.gov.hmcts.reform.professionalapi.domain.UserAccountMapId; import uk.gov.hmcts.reform.professionalapi.domain.UserAttribute; import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; import uk.gov.hmcts.reform.professionalapi.repository.ContactInformationRepository; @@ -65,6 +69,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; import uk.gov.hmcts.reform.professionalapi.repository.PrdEnumRepository; import uk.gov.hmcts.reform.professionalapi.repository.ProfessionalUserRepository; +import uk.gov.hmcts.reform.professionalapi.repository.UserAccountMapRepository; import uk.gov.hmcts.reform.professionalapi.repository.UserAttributeRepository; import uk.gov.hmcts.reform.professionalapi.service.OrganisationService; import uk.gov.hmcts.reform.professionalapi.service.PrdEnumService; @@ -149,6 +154,8 @@ public class OrganisationServiceImpl implements OrganisationService { OrgAttributeRepository orgAttributeRepository; @Autowired UserAttributeRepository userAttributeRepository; + @Autowired + UserAccountMapRepository userAccountMapRepository; @Value("${loggingComponentName}") private String loggingComponentName; @@ -821,42 +828,48 @@ private DeleteOrganisationResponse deleteOrganisationEntity(Organisation organis return deleteOrganisationResponse; } + @Override @Transactional public DeleteUserResponse deleteUserForOrganisation(List emails) { - var deleteOrganisationResponse = new DeleteOrganisationResponse(); if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } - Set userIdsToBeDeleted = emails.stream().map( - email -> { - Set userIds = new HashSet<>(); - Optional.ofNullable(professionalUserRepository - .findByEmailAddress(RefDataUtil.removeAllSpaces(email))) - .ifPresentOrElse(professionalUser -> { - userIds.add(professionalUser.getUserIdentifier()); - userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); - professionalUserRepository.delete(professionalUser); - }, () -> { - throw new InvalidRequest("Email addresses provided do not exist"); }); - return userIds.stream().iterator().next(); - }).collect(Collectors.toSet()); - - if (userIdsToBeDeleted.isEmpty()) { - throw new InvalidRequest("Could not find users to delete"); - } - - DeleteUserProfilesRequest deleteUserProfileRequest = - new DeleteUserProfilesRequest(userIdsToBeDeleted.stream().collect( - Collectors.toSet())); - deleteOrganisationResponse = RefDataUtil - .deleteUserProfilesFromUp(deleteUserProfileRequest, userProfileFeignClient); - if (deleteOrganisationResponse == null) { - throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED); + Set userIdsToBeDeleted = new HashSet<>(); + emails.forEach(email -> { + Optional professionalUser = Optional.ofNullable(professionalUserRepository + .findByEmailAddress(RefDataUtil.removeAllSpaces(email))); + if (!professionalUser.isEmpty()) { + if (!professionalUser.get().getRoles().contains(PrdEnumType.ADMIN_ROLE.name()) && + !professionalUser.get().getRoles().contains(PrdEnumType.SIDAM_ROLE.name())) { + //Users to be deleted from usre profile database + userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); + //Delete usres from User Account Map + List paymentAccountsList = professionalUser.get().getOrganisation().getPaymentAccounts(); + if (!paymentAccountsList.isEmpty()) { + List userAccountMaps = new ArrayList<>(); + paymentAccountsList.forEach(paymentAccount -> + userAccountMaps.add(new UserAccountMap(new UserAccountMapId(professionalUser.get(), paymentAccount)))); + if (!CollectionUtils.isEmpty(userAccountMaps)) { + userAccountMapRepository.deleteAll(userAccountMaps); + } + } + //Delete usres from User attribute table + userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); + //Delete usres from professional user table + professionalUserRepository.delete(professionalUser.get()); + } + } + }); + Optional deleteOrganisationResponse = null; + if(!userIdsToBeDeleted.isEmpty()) { + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); + deleteOrganisationResponse = Optional.ofNullable(RefDataUtil + .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient)); } - return new DeleteUserResponse(deleteOrganisationResponse.getStatusCode(), - deleteOrganisationResponse.getMessage()); + return new DeleteUserResponse(deleteOrganisationResponse.get().getStatusCode(), + deleteOrganisationResponse.get().getMessage()); } From 74b45224f7e711152a5bab33b897a6b0fde27e75 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Tue, 4 Jun 2024 20:27:05 +0100 Subject: [PATCH 14/15] update contact information review comments --- ...rofessionalInternalUserFunctionalTest.java | 3 +- .../service/impl/OrganisationServiceImpl.java | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index ec15bf52d2..d173a08fe1 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -899,7 +899,8 @@ void deletUserFromProfessionalAndUserProfileShouldReturnSuccess() { UserDeletionRequest userDeletionRequest = new UserDeletionRequest(emails); JsonPath response = professionalApiClient.deleteUserFromOrganisation(userDeletionRequest,OK); - + Response getUserResponse = professionalApiClient.retrieveUserByIdNotFound(intActiveOrgId); + assertThat(getUserResponse).isNull(); assertThat(response).isNotNull(); log.info("deletUserFromProfessionalAndUserProfileShouldReturnSuccess :: END"); diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java index b68b43ac28..7e5443816f 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java @@ -100,7 +100,6 @@ import static java.lang.Boolean.TRUE; import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.springframework.util.CollectionUtils.isEmpty; -import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_UP_FAILED; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.FALSE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER; @@ -841,29 +840,31 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { Optional professionalUser = Optional.ofNullable(professionalUserRepository .findByEmailAddress(RefDataUtil.removeAllSpaces(email))); if (!professionalUser.isEmpty()) { - if (!professionalUser.get().getRoles().contains(PrdEnumType.ADMIN_ROLE.name()) && - !professionalUser.get().getRoles().contains(PrdEnumType.SIDAM_ROLE.name())) { - //Users to be deleted from usre profile database - userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); - //Delete usres from User Account Map - List paymentAccountsList = professionalUser.get().getOrganisation().getPaymentAccounts(); - if (!paymentAccountsList.isEmpty()) { - List userAccountMaps = new ArrayList<>(); - paymentAccountsList.forEach(paymentAccount -> - userAccountMaps.add(new UserAccountMap(new UserAccountMapId(professionalUser.get(), paymentAccount)))); - if (!CollectionUtils.isEmpty(userAccountMaps)) { - userAccountMapRepository.deleteAll(userAccountMaps); - } - } - //Delete usres from User attribute table - userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); - //Delete usres from professional user table - professionalUserRepository.delete(professionalUser.get()); - } + if (!professionalUser.get().getRoles().contains(PrdEnumType.ADMIN_ROLE.name()) + && !professionalUser.get().getRoles().contains(PrdEnumType.SIDAM_ROLE.name())) { + //Users to be deleted from usre profile database + userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); + //Delete usres from User Account Map + List paymentAccountsList = professionalUser.get().getOrganisation() + .getPaymentAccounts(); + if (!paymentAccountsList.isEmpty()) { + List userAccountMaps = new ArrayList<>(); + paymentAccountsList.forEach(paymentAccount -> + userAccountMaps.add(new UserAccountMap( + new UserAccountMapId(professionalUser.get(), paymentAccount)))); + if (!CollectionUtils.isEmpty(userAccountMaps)) { + userAccountMapRepository.deleteAll(userAccountMaps); + } + } + //Delete usres from User attribute table + userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); + //Delete usres from professional user table + professionalUserRepository.delete(professionalUser.get()); + } } }); Optional deleteOrganisationResponse = null; - if(!userIdsToBeDeleted.isEmpty()) { + if (!userIdsToBeDeleted.isEmpty()) { DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); deleteOrganisationResponse = Optional.ofNullable(RefDataUtil .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient)); From c1aca8b324ff05c8b8c09489455a03dbf4736ec5 Mon Sep 17 00:00:00 2001 From: SabinaHMCTS Date: Wed, 5 Jun 2024 00:54:19 +0100 Subject: [PATCH 15/15] update contact information review comments --- .../constants/ProfessionalApiConstants.java | 4 ++ .../repository/UserAttributeRepository.java | 5 ++ .../service/impl/OrganisationServiceImpl.java | 64 ++++++++++++++----- .../impl/OrganisationServiceImplTest.java | 3 +- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java index 8ad52a839c..41b5163a39 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/constants/ProfessionalApiConstants.java @@ -130,6 +130,10 @@ private ProfessionalApiConstants() { "
- Passed payment account numbers are in an invalid format.
"; public static final String DEL_ORG_PBA_NOTES_5 = "-The payment accounts are not associated with users organisation"; + public static final String DEL_USER_UP = "- Users deleted successfully."; + + public static final String ERROR_USER_DELETED_UP = "- Error in deleting users."; + public static final String GET_PBA_EMAIL_NOTES_1 = "**IDAM Roles to access API** :
pui-finance-manager,
pui-"; public static final String GET_PBA_EMAIL_NOTES_2 = diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java index 6680819676..10be6d0474 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/repository/UserAttributeRepository.java @@ -14,4 +14,9 @@ public interface UserAttributeRepository extends JpaRepository emails) { if (emails.isEmpty()) { throw new InvalidRequest("Please provide both email addresses"); } - - Set userIdsToBeDeleted = new HashSet<>(); + StringBuilder failedIds = new StringBuilder(); + //DeleteOrganisationResponse deleteOrganisationResponse = new DeleteOrganisationResponse(); emails.forEach(email -> { Optional professionalUser = Optional.ofNullable(professionalUserRepository .findByEmailAddress(RefDataUtil.removeAllSpaces(email))); if (!professionalUser.isEmpty()) { - if (!professionalUser.get().getRoles().contains(PrdEnumType.ADMIN_ROLE.name()) - && !professionalUser.get().getRoles().contains(PrdEnumType.SIDAM_ROLE.name())) { - //Users to be deleted from usre profile database - userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); + UserAttribute userAttribute = userAttributeRepository + .findByProfessionalUserId(professionalUser.get().getId()); + if (userAttribute != null && !userAttribute.getPrdEnum().getPrdEnumId().getEnumType() + .contains(PrdEnumType.ADMIN_ROLE.name()) + && !userAttribute.getPrdEnum().getPrdEnumId().getEnumType() + .contains(PrdEnumType.SIDAM_ROLE.name())) { //Delete usres from User Account Map List paymentAccountsList = professionalUser.get().getOrganisation() .getPaymentAccounts(); @@ -853,27 +855,55 @@ public DeleteUserResponse deleteUserForOrganisation(List emails) { userAccountMaps.add(new UserAccountMap( new UserAccountMapId(professionalUser.get(), paymentAccount)))); if (!CollectionUtils.isEmpty(userAccountMaps)) { - userAccountMapRepository.deleteAll(userAccountMaps); + deleteUserAccountMap(userAccountMaps); } } - //Delete usres from User attribute table - userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId()); + //Delete users from User attribute table + deleteUserAttribute(professionalUser.get()); //Delete usres from professional user table - professionalUserRepository.delete(professionalUser.get()); + deleteProfessionalUser(professionalUser.get()); + //Users to be deleted from usre profile database + Set userIdsToBeDeleted = new HashSet<>(); + userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier()); + DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); + DeleteOrganisationResponse deleteOrganisationResponse = deleteUserProfile(deleteUserRequest); + if (deleteOrganisationResponse == null) { + failedIds.append(professionalUser.get().getUserIdentifier()); + } } } }); - Optional deleteOrganisationResponse = null; - if (!userIdsToBeDeleted.isEmpty()) { - DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted); - deleteOrganisationResponse = Optional.ofNullable(RefDataUtil - .deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient)); + DeleteUserResponse response = null; + if (failedIds.isEmpty()) { + response = new DeleteUserResponse(ProfessionalApiConstants.ERROR_CODE_400, + ProfessionalApiConstants.ERROR_USER_DELETED_UP + " " + failedIds); + } else { + response = new DeleteUserResponse(ProfessionalApiConstants.STATUS_CODE_204, + ProfessionalApiConstants.DEL_USER_UP); } - return new DeleteUserResponse(deleteOrganisationResponse.get().getStatusCode(), - deleteOrganisationResponse.get().getMessage()); + return response; + } + + + @Transactional + private void deleteUserAccountMap(List userAccountMaps) { + userAccountMapRepository.deleteAll(userAccountMaps); } + @Transactional + private void deleteProfessionalUser(ProfessionalUser professionalUser) { + professionalUserRepository.delete(professionalUser); + } + @Transactional + private void deleteUserAttribute(ProfessionalUser professionalUser) { + userAttributeRepository.deleteByProfessionalUserId(professionalUser.getId()); + } + + @Transactional + private DeleteOrganisationResponse deleteUserProfile(DeleteUserProfilesRequest deleteUserRequest) { + return RefDataUtil.deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient); + } private DeleteOrganisationResponse deleteUserProfile(Organisation organisation, DeleteOrganisationResponse deleteOrganisationResponse) { diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java index 7b1f706c61..59b80e768f 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImplTest.java @@ -2746,10 +2746,9 @@ void test_deleteUserForOrganisation() throws JsonProcessingException { DeleteUserResponse deleteUserResponse = new DeleteUserResponse(204, "The organisation has deleted successfully"); - List emails = Arrays.asList("56vyi3p3esq@mailinator.com","7qw1vx4b06p@mailinator.com"); + List emails = Arrays.asList(professionalUser.getEmailAddress()); deleteUserResponse = sut.deleteUserForOrganisation(emails); assertThat(deleteUserResponse).isNotNull(); - assertThat(deleteUserResponse.getStatusCode()).isEqualTo(STATUS_CODE_204); verify(organisationRepository, times(0)).findByOrganisationIdentifier(any(String.class)); }