From e4b4a7b284ac8f1db6b859b11a3f747d96229c84 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Thu, 31 Oct 2024 15:18:18 +0100 Subject: [PATCH] update: Hard delete user/usergroup when not used --- .../org/isf/menu/service/MenuIoOperations.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/isf/menu/service/MenuIoOperations.java b/src/main/java/org/isf/menu/service/MenuIoOperations.java index fa943d9d7..227a3f9cc 100644 --- a/src/main/java/org/isf/menu/service/MenuIoOperations.java +++ b/src/main/java/org/isf/menu/service/MenuIoOperations.java @@ -99,7 +99,7 @@ public long countAllActiveGroups() { * @throws OHServiceException When error occurs */ public List getUser(String groupID) throws OHServiceException { - return repository.findByDeletedWhereUserGroupNameByOrderUserNameAsc(groupID, false); + return repository.findAllWhereUserGroupNameByOrderUserNameAsc(groupID); } /** @@ -204,8 +204,12 @@ public boolean updatePassword(User user) throws OHServiceException { */ public void deleteUser(User user) throws OHServiceException { ensureUserNotDeleted(user.getUserName()); - user.setDeleted(true); - repository.save(user); + try { + repository.delete(user); + } catch (Exception ex) { + user.setDeleted(true); + repository.save(user); + } } public void updateFailedAttempts(String userName, int newFailAttempts) { @@ -307,8 +311,12 @@ private GroupMenu insertGroupMenu(UserGroup aGroup, UserMenuItem item) throws OH */ public void deleteGroup(UserGroup aGroup) throws OHServiceException { ensureUserGroupNotDeleted(aGroup.getCode()); - aGroup.setDeleted(true); - groupRepository.save(aGroup); + if (getUser(aGroup.getCode()).isEmpty()) { + groupRepository.delete(aGroup); + } else { + aGroup.setDeleted(true); + groupRepository.save(aGroup); + } } /**