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

Conversation

SabinaHMCTS
Copy link
Contributor

Jira link (if applicable)

Change description

Checklist

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)
  • Does this PR introduce a breaking change

Copy link
Contributor

@lukasz-wolski lukasz-wolski left a comment

Choose a reason for hiding this comment

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

Please see inlined comment

lukasz-wolski
lukasz-wolski previously approved these changes May 13, 2024
Copy link
Contributor

@lukasz-wolski lukasz-wolski left a comment

Choose a reason for hiding this comment

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

Very nice usage of forEach() 👍

@Transactional
public DeleteUserResponse deleteUserForOrganisation(List<String> emails) {
if (emails.isEmpty()) {
throw new InvalidRequest("Please provide both email addresses");
Copy link
Contributor

Choose a reason for hiding this comment

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

dont understand this message why both email addresses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

N/A

.findByEmailAddress(RefDataUtil.removeAllSpaces(email)));
if (!professionalUser.isEmpty()) {
userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier());
userAttributeRepository.deleteByProfessionalUserId(professionalUser.get().getId());
Copy link
Contributor

@rajkatla-hmcts rajkatla-hmcts May 19, 2024

Choose a reason for hiding this comment

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

cascade delete should take care of it

you also need to delete user from user account map table explicitly as its not there in professional user class

}

});
DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted);
Copy link
Contributor

Choose a reason for hiding this comment

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

what if user is not found in professional user table ? this call will make with empty userids set

DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIdsToBeDeleted);
Optional<DeleteOrganisationResponse> deleteOrganisationResponse = Optional.ofNullable(RefDataUtil
.deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient));
if (deleteOrganisationResponse.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this line is not required, response will contain either success or error status or it wont come back if any FeignException

@@ -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

emails.forEach(email -> {
Optional<ProfessionalUser> professionalUser = Optional.ofNullable(professionalUserRepository
.findByEmailAddress(RefDataUtil.removeAllSpaces(email)));
if (!professionalUser.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete users only when user is not ADMIN

Optional<DeleteOrganisationResponse> deleteOrganisationResponse = Optional.ofNullable(RefDataUtil
.deleteUserProfilesFromUp(deleteUserRequest, userProfileFeignClient));
if (deleteOrganisationResponse.isEmpty()) {
throw new InvalidRequest(ERROR_MESSAGE_UP_FAILED);
Copy link
Contributor

Choose a reason for hiding this comment

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

this exception will not process remaining email ids, you need to collect only failed email ids and include them in the error message

if (emails.isEmpty()) {
throw new InvalidRequest("Please provide both email addresses");
}
Set<String> userIdsToBeDeleted = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

you dont need this set object return set from stream itself

Optional<ProfessionalUser> professionalUser = Optional.ofNullable(professionalUserRepository
.findByEmailAddress(RefDataUtil.removeAllSpaces(email)));
if (!professionalUser.isEmpty()) {
userIdsToBeDeleted.add(professionalUser.get().getUserIdentifier());
Copy link
Contributor

Choose a reason for hiding this comment

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

dont need this, return ids from stream map and collect as set

@@ -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

} else if (!IdamStatus.ACTIVE.name().equalsIgnoreCase(newUserResponse.getIdamStatus())) {
// If user is not active in the up will send the request to delete
} else {
// user will be deleted even if he is in active state
var userIds = new HashSet<String>();
userIds.add(user.getUserIdentifier());
DeleteUserProfilesRequest deleteUserRequest = new DeleteUserProfilesRequest(userIds);
deleteOrganisationResponse = RefDataUtil
Copy link
Contributor

Choose a reason for hiding this comment

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

All users who belong to an organization should be deleted, not just one user

Copy link
Contributor Author

@SabinaHMCTS SabinaHMCTS Aug 30, 2024

Choose a reason for hiding this comment

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

i can remove the condition to check fro more than one user and delete all users for the organisation but i

just want to be sure and reconfirm as this is an existing functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

confirmed with Raj that correct logic will be to delete allassociated users witht the organisation when it is being fetched, will inform kiran to inform business users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants