-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/OrganisationServiceImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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 ", |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Jira link (if applicable)
Change description
Checklist