Skip to content

Commit

Permalink
chore: fix orphan removal for rocketchat rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Dec 19, 2024
1 parent d3d8607 commit fe312b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ protected void deleteSession(Session session, List<DeletionWorkflowError> workfl

void performSessionDeletion(Session session, List<DeletionWorkflowError> workflowErrors) {

deleteRocketChatGroup(session.getGroupId(), workflowErrors);
deleteRocketChatGroup(session.getFeedbackGroupId(), workflowErrors);
deleteSessionData(session, workflowErrors);
deleteSession(session, workflowErrors);
deleteRocketChatGroup(session.getGroupId(), workflowErrors);
deleteRocketChatGroup(session.getFeedbackGroupId(), workflowErrors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.persistence.NonUniqueResultException;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/** Service to trigger deletion of inactive sessions and asker accounts. */
@Service
@RequiredArgsConstructor
@Slf4j
public class DeleteInactiveSessionsAndUserService {

private final @NonNull UserRepository userRepository;
Expand Down Expand Up @@ -78,14 +81,20 @@ private List<DeletionWorkflowError> performDeletionWorkflow(

List<DeletionWorkflowError> workflowErrors = new ArrayList<>();

Optional<User> user =
userRepository.findByRcUserIdAndDeleteDateIsNull(userInactiveGroupEntry.getKey());
user.ifPresentOrElse(
u -> workflowErrors.addAll(deleteInactiveGroupsOrUser(userInactiveGroupEntry, u)),
() ->
workflowErrors.addAll(
performUserSessionDeletionForNonExistingUser(userInactiveGroupEntry.getValue())));

try {
Optional<User> user =
userRepository.findByRcUserIdAndDeleteDateIsNull(userInactiveGroupEntry.getKey());
user.ifPresentOrElse(
u -> workflowErrors.addAll(deleteInactiveGroupsOrUser(userInactiveGroupEntry, u)),
() ->
workflowErrors.addAll(
performUserSessionDeletionForNonExistingUser(userInactiveGroupEntry.getValue())));
} catch (NonUniqueResultException ex) {
log.error(
"Non unique result for findByRcUserIdAndDeleteDateIsNull found. RcUserId:",
userInactiveGroupEntry.getKey());
return workflowErrors;
}
return workflowErrors;
}

Expand Down Expand Up @@ -138,7 +147,11 @@ private Collection<? extends DeletionWorkflowError> performUserSessionDeletionFo
String rcGroupId) {
List<DeletionWorkflowError> workflowErrors = new ArrayList<>();
Optional<Session> session = sessionRepository.findByGroupId(rcGroupId);
session.ifPresent(s -> workflowErrors.addAll(deleteSessionService.performSessionDeletion(s)));
if (session.isPresent()) {
workflowErrors.addAll(deleteSessionService.performSessionDeletion(session.get()));
} else {
workflowErrors.addAll(deleteSessionService.performRocketchatSessionDeletion(rcGroupId));
}
return workflowErrors;
}

Expand Down

0 comments on commit fe312b6

Please sign in to comment.