@Test public void testUpdateUserRights() { logon(AbstractTestBase.ADMIN); final PFUserDO user = initTestDB.addUser("testUserRightDaoTest"); final Set<GroupDO> groupsToAssign = new HashSet<>(); groupsToAssign.add(getGroup(AbstractTestBase.FINANCE_GROUP)); groupDao.assignGroups(user, groupsToAssign, null); List<UserRightVO> list = userRightDao.getUserRights(user); UserRightVO right1 = null; UserRightVO right2 = null; for (final UserRightVO item : list) { if (item.getRight().getId() == UserRightId.FIBU_AUSGANGSRECHNUNGEN) { right1 = item; } else if (item.getRight().getId() == UserRightId.FIBU_EINGANGSRECHNUNGEN) { right2 = item; } } assertNotNull(right1, "right not found!"); assertNotNull(right2, "right not found!"); assertNull(right1.getValue()); assertNull(right2.getValue()); right1.setValue(UserRightValue.READWRITE); right2.setValue(UserRightValue.READONLY); userRightDao.updateUserRights(user, list); list = userRightDao.getUserRights(user); right1 = right2 = null; for (final UserRightVO item : list) { if (item.getRight().getId() == UserRightId.FIBU_AUSGANGSRECHNUNGEN) { right1 = item; } else if (item.getRight().getId() == UserRightId.FIBU_EINGANGSRECHNUNGEN) { right2 = item; } } assertNotNull(right1, "right not found!"); assertNotNull(right2, "right not found!"); assertEquals(UserRightValue.READWRITE, right1.getValue()); assertEquals(UserRightValue.READONLY, right2.getValue()); right1.setValue(UserRightValue.READONLY); right2.setValue(null); userRightDao.updateUserRights(user, list); list = userRightDao.getUserRights(user); right1 = right2 = null; for (final UserRightVO item : list) { if (item.getRight().getId() == UserRightId.FIBU_AUSGANGSRECHNUNGEN) { right1 = item; } else if (item.getRight().getId() == UserRightId.FIBU_EINGANGSRECHNUNGEN) { right2 = item; } } assertNotNull(right1, "right not found!"); assertNotNull(right2, "right not found!"); assertEquals(UserRightValue.READONLY, right1.getValue()); assertNull(right2.getValue()); }
public void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache) { final List<UserRightDO> dbList = getList(user); dbList.forEach(em::detach); final UserGroupCache userGroupCache = getUserGroupCache(); for (final UserRightVO rightVO : list) { UserRightDO rightDO = null; for (final UserRightDO dbItem : dbList) { IUserRightId rightid = userRightService.getRightId(dbItem.getRightIdString()); if (rightid == rightVO.getRight().getId()) { rightDO = dbItem; } } if (rightDO == null) { if ((rightVO.isBooleanValue() && rightVO.getValue() == UserRightValue.FALSE) || rightVO.getValue() == null) { continue; } rightDO = new UserRightDO(user, rightVO.getRight().getId()).setUser(user); copy(rightDO, rightVO); save(rightDO); } else { copy(rightDO, rightVO); IUserRightId rightId = userRightService.getRightId(rightDO.getRightIdString()); final UserRight right = userRightService.getRight(rightId); if (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue())) { rightDO.setValue(null); } update(rightDO); } } for (final UserRightDO rightDO : dbList) { String rightId = rightDO.getRightIdString(); UserRight right = userRightService.getRight(rightId); if (right != null && (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue()))) { rightDO.setValue(null); update(rightDO); } } if (updateUserGroupCache) { userGroupCache.setExpired(); } }
UserRightDao extends BaseDao<UserRightDO> { public void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache) { final List<UserRightDO> dbList = getList(user); dbList.forEach(em::detach); final UserGroupCache userGroupCache = getUserGroupCache(); for (final UserRightVO rightVO : list) { UserRightDO rightDO = null; for (final UserRightDO dbItem : dbList) { IUserRightId rightid = userRightService.getRightId(dbItem.getRightIdString()); if (rightid == rightVO.getRight().getId()) { rightDO = dbItem; } } if (rightDO == null) { if ((rightVO.isBooleanValue() && rightVO.getValue() == UserRightValue.FALSE) || rightVO.getValue() == null) { continue; } rightDO = new UserRightDO(user, rightVO.getRight().getId()).setUser(user); copy(rightDO, rightVO); save(rightDO); } else { copy(rightDO, rightVO); IUserRightId rightId = userRightService.getRightId(rightDO.getRightIdString()); final UserRight right = userRightService.getRight(rightId); if (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue())) { rightDO.setValue(null); } update(rightDO); } } for (final UserRightDO rightDO : dbList) { String rightId = rightDO.getRightIdString(); UserRight right = userRightService.getRight(rightId); if (right != null && (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue()))) { rightDO.setValue(null); update(rightDO); } } if (updateUserGroupCache) { userGroupCache.setExpired(); } } }
UserRightDao extends BaseDao<UserRightDO> { public void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache) { final List<UserRightDO> dbList = getList(user); dbList.forEach(em::detach); final UserGroupCache userGroupCache = getUserGroupCache(); for (final UserRightVO rightVO : list) { UserRightDO rightDO = null; for (final UserRightDO dbItem : dbList) { IUserRightId rightid = userRightService.getRightId(dbItem.getRightIdString()); if (rightid == rightVO.getRight().getId()) { rightDO = dbItem; } } if (rightDO == null) { if ((rightVO.isBooleanValue() && rightVO.getValue() == UserRightValue.FALSE) || rightVO.getValue() == null) { continue; } rightDO = new UserRightDO(user, rightVO.getRight().getId()).setUser(user); copy(rightDO, rightVO); save(rightDO); } else { copy(rightDO, rightVO); IUserRightId rightId = userRightService.getRightId(rightDO.getRightIdString()); final UserRight right = userRightService.getRight(rightId); if (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue())) { rightDO.setValue(null); } update(rightDO); } } for (final UserRightDO rightDO : dbList) { String rightId = rightDO.getRightIdString(); UserRight right = userRightService.getRight(rightId); if (right != null && (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue()))) { rightDO.setValue(null); update(rightDO); } } if (updateUserGroupCache) { userGroupCache.setExpired(); } } protected  UserRightDao(); }
UserRightDao extends BaseDao<UserRightDO> { public void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache) { final List<UserRightDO> dbList = getList(user); dbList.forEach(em::detach); final UserGroupCache userGroupCache = getUserGroupCache(); for (final UserRightVO rightVO : list) { UserRightDO rightDO = null; for (final UserRightDO dbItem : dbList) { IUserRightId rightid = userRightService.getRightId(dbItem.getRightIdString()); if (rightid == rightVO.getRight().getId()) { rightDO = dbItem; } } if (rightDO == null) { if ((rightVO.isBooleanValue() && rightVO.getValue() == UserRightValue.FALSE) || rightVO.getValue() == null) { continue; } rightDO = new UserRightDO(user, rightVO.getRight().getId()).setUser(user); copy(rightDO, rightVO); save(rightDO); } else { copy(rightDO, rightVO); IUserRightId rightId = userRightService.getRightId(rightDO.getRightIdString()); final UserRight right = userRightService.getRight(rightId); if (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue())) { rightDO.setValue(null); } update(rightDO); } } for (final UserRightDO rightDO : dbList) { String rightId = rightDO.getRightIdString(); UserRight right = userRightService.getRight(rightId); if (right != null && (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue()))) { rightDO.setValue(null); update(rightDO); } } if (updateUserGroupCache) { userGroupCache.setExpired(); } } protected  UserRightDao(); List<UserRightDO> getList(final PFUserDO user); List<UserRightDO> internalGetAllOrdered(); void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache); void updateUserRights(final PFUserDO user, final List<UserRightVO> list); List<UserRightVO> getUserRights(final PFUserDO user); @Override List<UserRightDO> getList(final BaseSearchFilter filter); @Override String[] getAdditionalSearchFields(); @Override boolean hasUserSelectAccess(final PFUserDO user, final boolean throwException); @Override boolean hasUserSelectAccess(final PFUserDO user, final UserRightDO obj, final boolean throwException); @Override boolean hasAccess(final PFUserDO user, final UserRightDO obj, final UserRightDO oldObj,
                           final OperationType operationType,
                           final boolean throwException); @Override UserRightDO newInstance(); }
UserRightDao extends BaseDao<UserRightDO> { public void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache) { final List<UserRightDO> dbList = getList(user); dbList.forEach(em::detach); final UserGroupCache userGroupCache = getUserGroupCache(); for (final UserRightVO rightVO : list) { UserRightDO rightDO = null; for (final UserRightDO dbItem : dbList) { IUserRightId rightid = userRightService.getRightId(dbItem.getRightIdString()); if (rightid == rightVO.getRight().getId()) { rightDO = dbItem; } } if (rightDO == null) { if ((rightVO.isBooleanValue() && rightVO.getValue() == UserRightValue.FALSE) || rightVO.getValue() == null) { continue; } rightDO = new UserRightDO(user, rightVO.getRight().getId()).setUser(user); copy(rightDO, rightVO); save(rightDO); } else { copy(rightDO, rightVO); IUserRightId rightId = userRightService.getRightId(rightDO.getRightIdString()); final UserRight right = userRightService.getRight(rightId); if (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue())) { rightDO.setValue(null); } update(rightDO); } } for (final UserRightDO rightDO : dbList) { String rightId = rightDO.getRightIdString(); UserRight right = userRightService.getRight(rightId); if (right != null && (!right.isAvailable(userGroupCache, user) || !right.isAvailable(userGroupCache, user, rightDO.getValue()))) { rightDO.setValue(null); update(rightDO); } } if (updateUserGroupCache) { userGroupCache.setExpired(); } } protected  UserRightDao(); List<UserRightDO> getList(final PFUserDO user); List<UserRightDO> internalGetAllOrdered(); void updateUserRights(final PFUserDO user, final List<UserRightVO> list, final boolean updateUserGroupCache); void updateUserRights(final PFUserDO user, final List<UserRightVO> list); List<UserRightVO> getUserRights(final PFUserDO user); @Override List<UserRightDO> getList(final BaseSearchFilter filter); @Override String[] getAdditionalSearchFields(); @Override boolean hasUserSelectAccess(final PFUserDO user, final boolean throwException); @Override boolean hasUserSelectAccess(final PFUserDO user, final UserRightDO obj, final boolean throwException); @Override boolean hasAccess(final PFUserDO user, final UserRightDO obj, final UserRightDO oldObj,
                           final OperationType operationType,
                           final boolean throwException); @Override UserRightDO newInstance();  }