Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTSRD-2133. Delete organisation and user from UP even if he is in active status #1590

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c06c1a6
Upgrading perftest branch to V16 and adding subnet_suffix
SabinaHMCTS Dec 11, 2023
443246f
Delete organisation and user even if he is active
SabinaHMCTS Apr 25, 2024
2937807
Delete User
SabinaHMCTS Apr 23, 2024
ed8ec38
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
ee25438
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
d67d971
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
f9b6715
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
510e09d
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
0df25e2
Delete User and User Profile
SabinaHMCTS Apr 26, 2024
3dd7caf
Fix build
SabinaHMCTS Apr 28, 2024
76c03eb
Fix build
SabinaHMCTS Apr 28, 2024
10b6973
Fix build
SabinaHMCTS Apr 29, 2024
bf2049e
Fix build
SabinaHMCTS Apr 29, 2024
1924b8b
Fix build
SabinaHMCTS Apr 29, 2024
0132dbc
Fix build
SabinaHMCTS Apr 29, 2024
b1c7ca4
Fix build
SabinaHMCTS Apr 29, 2024
5fe76bb
Fix build
SabinaHMCTS Apr 29, 2024
42df77c
Fix build
SabinaHMCTS Apr 29, 2024
57fb69d
Fix build
SabinaHMCTS Apr 29, 2024
3a20702
Fix build
SabinaHMCTS Apr 29, 2024
af226cb
Fix build
SabinaHMCTS Apr 29, 2024
9d27d99
Fix build
SabinaHMCTS Apr 29, 2024
1ebfb97
Fix build
SabinaHMCTS Apr 29, 2024
7b24fe2
Fix build
SabinaHMCTS Apr 29, 2024
02cc226
Fix build
SabinaHMCTS Apr 29, 2024
5c6303e
Fix build
SabinaHMCTS Apr 29, 2024
f6a7fd4
Merge branch 'master' into DTSRD-2133
SabinaHMCTS May 13, 2024
f07b996
fixing review comments
SabinaHMCTS May 13, 2024
d08920f
fixing review comments
SabinaHMCTS May 13, 2024
3806151
fixing review comments
SabinaHMCTS May 13, 2024
5fcc971
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
c82455f
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
47e5a12
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
725c733
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
a293465
Merge branch 'master' into DTSRD-2133
SabinaHMCTS Jun 4, 2024
3f0f0e2
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
2045d1e
removed teh extra code for DTSRD-2134
SabinaHMCTS Jun 4, 2024
b4ef9dc
Merge branch 'master' into DTSRD-2133
SabinaHMCTS Aug 29, 2024
c4da7af
merging DTSRD-2132 and DTSRD-2136
SabinaHMCTS Aug 31, 2024
c1c2d81
endpoint to save SraId
SabinaHMCTS Sep 4, 2024
83caf02
endpoint to save SraId
SabinaHMCTS Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -94,6 +95,9 @@ public class OrganisationalExternalControllerProviderUsersTest extends WebMvcPro
@Mock
SecurityContext securityContext;

@Autowired
UserAttributeRepository userAttributeRepository;

private final ObjectMapper objectMapper = new ObjectMapper();
private Organisation organisation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,9 @@ public class OrganisationalExternalControllerProviderUsersTestConfiguration exte
@MockBean
OrgAttributeRepository orgAttributeRepository;

@MockBean
UserAttributeRepository userAttributeRepository;

@Bean
@Primary
protected OrganisationServiceImpl organisationService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +108,10 @@ 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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;
Expand Down Expand Up @@ -58,6 +59,9 @@ public class OrganisationalInternalControllerProviderTestConfiguration extends P

@MockBean
OrganisationMfaStatusRepository organisationMfaStatusRepository;
@MockBean
UserAttributeRepository userAttributeRepository;


@Bean
@Primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ void return_404_when_un_known_org_identifier_in_the_request_to_delete_pending_or
}

@Test
void returns_400_with_error_msg_when_delete_active_organisation_with_active_user_profile() {
void returns_200_when_delete_active_organisation_with_active_user_profile() {
userProfileCreateUserWireMock(HttpStatus.resolve(201));
String orgIdentifier = createAndActivateOrganisation();

getUserProfileByEmailWireMock(HttpStatus.resolve(200));
deleteUserProfileMock(HttpStatus.resolve(204));
Map<String, Object> deleteResponse =
professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier);
assertThat(deleteResponse.get("http_status")).isEqualTo("400");
assertThat((String) deleteResponse.get("response_body"))
.contains("The organisation admin is not in Pending state");
assertThat(deleteResponse.get("http_status")).isEqualTo(204);

}

Expand All @@ -114,13 +113,14 @@ void returns_204_when_delete_active_organisation_with_one_pending_user_profile()
}

@Test
void returns_400_when_delete_active_organisation_with_more_than_one__user_profile() {
void returns_200_when_delete_active_organisation_with_more_than_one_user_profile() {
List<String> userRoles = new ArrayList<>();
userRoles.add("pui-user-manager");

userProfileCreateUserWireMock(HttpStatus.resolve(201));
String orgIdentifier = createAndActivateOrganisation();

getUserProfileByEmailWireMock(HttpStatus.resolve(200));
deleteUserProfileMock(HttpStatus.resolve(204));
Map<String, Object> newUserResponse = professionalReferenceDataClient
.addUserToOrganisation(orgIdentifier,
inviteUserCreationRequest("[email protected]", userRoles), hmctsAdmin);
Expand All @@ -132,7 +132,7 @@ void returns_400_when_delete_active_organisation_with_more_than_one__user_profil

Map<String, Object> deleteResponse =
professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier);
assertThat(deleteResponse.get("http_status")).isEqualTo("400");
assertThat(deleteResponse.get("http_status")).isEqualTo(204);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing functional tests

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ void return_forbidden_when_no_role_associated_with_end_point_to_delete_pending_o


@Test
void returns_400_with_error_msg_when_delete_active_otherOrganisation_with_active_user_profile() {
void returns_200_with_error_msg_when_delete_active_otherOrganisation_with_active_user_profile() {
userProfileCreateUserWireMock(HttpStatus.resolve(201));
String orgIdentifier = createAndActivateOtherOrganisation();

getUserProfileByEmailWireMock(HttpStatus.resolve(200));
deleteUserProfileMock(HttpStatus.resolve(204));
Map<String, Object> deleteResponse =
professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier);
assertThat(deleteResponse.get("http_status")).isEqualTo("400");
assertThat((String) deleteResponse.get("response_body"))
.contains("The organisation admin is not in Pending state");
assertThat(deleteResponse.get("http_status")).isEqualTo(204);

}

Expand All @@ -102,13 +101,16 @@ void returns_204_when_delete_active_otherOrganisation_with_one_pending_user_prof
}

@Test
void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_profile() {
void returns_200_when_delete_active_otherOrganisation_with_more_than_one__user_profile() {
List<String> userRoles = new ArrayList<>();
userRoles.add("pui-user-manager");

userProfileCreateUserWireMock(HttpStatus.resolve(201));
String orgIdentifier = createAndActivateOtherOrganisation();

getUserProfileByEmailWireMock(HttpStatus.resolve(200));
deleteUserProfileMock(HttpStatus.resolve(204));

Map<String, Object> newUserResponse = professionalReferenceDataClient
.addUserToOrganisation(orgIdentifier,
inviteUserCreationRequest("[email protected]", userRoles), hmctsAdmin);
Expand All @@ -118,9 +120,11 @@ void returns_400_when_delete_active_otherOrganisation_with_more_than_one__user_p
assertThat(newUserResponse).isNotNull();
assertEquals(newUserResponse.get(USER_IDENTIFIER), userIdentifierResponse);



Map<String, Object> deleteResponse =
professionalReferenceDataClient.deleteOrganisation(hmctsAdmin, orgIdentifier);
assertThat(deleteResponse.get("http_status")).isEqualTo("400");
assertThat(deleteResponse.get("http_status")).isEqualTo(204);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -744,4 +748,63 @@ public ResponseEntity<Object> retrieveOrganisationsByProfileIds(
.status(HttpStatus.OK)
.body(response);
}

@Operation(
summary = "Deletes the provided list of user accounts from the organisation.",
description = "**IDAM Roles to access API** : <br> - 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<DeleteUserResponse> deleteUserFromOrganisation(
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "deletePbaRequest")
@Valid @NotNull @RequestBody UserDeletionRequest userDeletionRequest) {

List<String> emails = userDeletionRequest.getEmails();

DeleteUserResponse deleteUserResponse =
organisationService.deleteUserForOrganisation(emails);

return ResponseEntity
.status(deleteUserResponse.getStatusCode())
.body(deleteUserResponse);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.hmcts.reform.professionalapi.controller.request;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
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<String> emails;

@JsonCreator
public UserDeletionRequest(
@JsonProperty("firstName") String firstName,
@JsonProperty("lastName") String lastName,
@JsonProperty("emails") List<String> emails
) {

this.firstName = firstName;
this.lastName = lastName;
this.emails = emails;
}
}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -9,4 +11,9 @@
@Repository
public interface UserAttributeRepository extends JpaRepository<UserAttribute, UUID> {

@Modifying
@Query(value = "delete from dbrefdata.user_attribute ua where ua.professional_user_id = :profUserId ",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need this native, try cascade delete

nativeQuery = true)
void deleteByProfessionalUserId(UUID profUserId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,4 +82,5 @@ void addContactInformationsToOrganisation(

ResponseEntity<OrganisationEntityResponse> retrieveOrganisationByUserId(String userId);

DeleteUserResponse deleteUserForOrganisation(List<String> emails);
}
Loading