@Test(expected = ForbiddenException.class) public void updateUserInfo() { UserDO user1 = UserDO.builder().nickname("pedro大大").username("pedro大大").build(); userMapper.insert(user1); Random random = new Random(); UpdateUserInfoDTO dto = new UpdateUserInfoDTO(); dto.setGroupIds(Arrays.asList(rootGroupId, (long) random.nextInt(100))); boolean b = adminService.updateUserInfo(user1.getId(), dto); assertFalse(b); }
@Override public boolean updateUserInfo(Long id, UpdateUserInfoDTO validator) { List<Long> newGroupIds = validator.getGroupIds(); if (newGroupIds == null || newGroupIds.isEmpty()) { return false; } boolean anyMatch = newGroupIds.stream().anyMatch(it -> it.equals(rootGroupId)); if (anyMatch) { throw new ForbiddenException("you can't add user to root group", 10073); } List<Long> existGroupIds = groupService.getUserGroupIdsByUserId(id); List<Long> deleteIds = existGroupIds.stream().filter(it -> !newGroupIds.contains(it)).collect(Collectors.toList()); List<Long> addIds = newGroupIds.stream().filter(it -> !existGroupIds.contains(it)).collect(Collectors.toList()); return groupService.deleteUserGroupRelations(id, deleteIds) && groupService.addUserGroupRelations(id, addIds); }
AdminServiceImpl implements AdminService { @Override public boolean updateUserInfo(Long id, UpdateUserInfoDTO validator) { List<Long> newGroupIds = validator.getGroupIds(); if (newGroupIds == null || newGroupIds.isEmpty()) { return false; } boolean anyMatch = newGroupIds.stream().anyMatch(it -> it.equals(rootGroupId)); if (anyMatch) { throw new ForbiddenException("you can't add user to root group", 10073); } List<Long> existGroupIds = groupService.getUserGroupIdsByUserId(id); List<Long> deleteIds = existGroupIds.stream().filter(it -> !newGroupIds.contains(it)).collect(Collectors.toList()); List<Long> addIds = newGroupIds.stream().filter(it -> !existGroupIds.contains(it)).collect(Collectors.toList()); return groupService.deleteUserGroupRelations(id, deleteIds) && groupService.addUserGroupRelations(id, addIds); } }
AdminServiceImpl implements AdminService { @Override public boolean updateUserInfo(Long id, UpdateUserInfoDTO validator) { List<Long> newGroupIds = validator.getGroupIds(); if (newGroupIds == null || newGroupIds.isEmpty()) { return false; } boolean anyMatch = newGroupIds.stream().anyMatch(it -> it.equals(rootGroupId)); if (anyMatch) { throw new ForbiddenException("you can't add user to root group", 10073); } List<Long> existGroupIds = groupService.getUserGroupIdsByUserId(id); List<Long> deleteIds = existGroupIds.stream().filter(it -> !newGroupIds.contains(it)).collect(Collectors.toList()); List<Long> addIds = newGroupIds.stream().filter(it -> !existGroupIds.contains(it)).collect(Collectors.toList()); return groupService.deleteUserGroupRelations(id, deleteIds) && groupService.addUserGroupRelations(id, addIds); }  }
AdminServiceImpl implements AdminService { @Override public boolean updateUserInfo(Long id, UpdateUserInfoDTO validator) { List<Long> newGroupIds = validator.getGroupIds(); if (newGroupIds == null || newGroupIds.isEmpty()) { return false; } boolean anyMatch = newGroupIds.stream().anyMatch(it -> it.equals(rootGroupId)); if (anyMatch) { throw new ForbiddenException("you can't add user to root group", 10073); } List<Long> existGroupIds = groupService.getUserGroupIdsByUserId(id); List<Long> deleteIds = existGroupIds.stream().filter(it -> !newGroupIds.contains(it)).collect(Collectors.toList()); List<Long> addIds = newGroupIds.stream().filter(it -> !existGroupIds.contains(it)).collect(Collectors.toList()); return groupService.deleteUserGroupRelations(id, deleteIds) && groupService.addUserGroupRelations(id, addIds); }  @Override IPage<UserDO> getUserPageByGroupId(Long groupId, Long count, Long page); @Override boolean changeUserPassword(Long id, ResetPasswordDTO dto); @Transactional @Override boolean deleteUser(Long id); @Override boolean updateUserInfo(Long id, UpdateUserInfoDTO validator); @Override IPage<GroupDO> getGroupPage(Long page, Long count); @Override GroupPermissionsBO getGroup(Long id); @Transactional @Override boolean createGroup(NewGroupDTO dto); @Override boolean updateGroup(Long id, UpdateGroupDTO dto); @Override boolean deleteGroup(Long id); @Override boolean dispatchPermission(DispatchPermissionDTO dto); @Override boolean dispatchPermissions(DispatchPermissionsDTO dto); @Override boolean removePermissions(RemovePermissionsDTO dto); @Override List<GroupDO> getAllGroups(); @Override List<PermissionDO> getAllPermissions(); @Override Map<String, List<PermissionDO>> getAllStructualPermissions(); }
AdminServiceImpl implements AdminService { @Override public boolean updateUserInfo(Long id, UpdateUserInfoDTO validator) { List<Long> newGroupIds = validator.getGroupIds(); if (newGroupIds == null || newGroupIds.isEmpty()) { return false; } boolean anyMatch = newGroupIds.stream().anyMatch(it -> it.equals(rootGroupId)); if (anyMatch) { throw new ForbiddenException("you can't add user to root group", 10073); } List<Long> existGroupIds = groupService.getUserGroupIdsByUserId(id); List<Long> deleteIds = existGroupIds.stream().filter(it -> !newGroupIds.contains(it)).collect(Collectors.toList()); List<Long> addIds = newGroupIds.stream().filter(it -> !existGroupIds.contains(it)).collect(Collectors.toList()); return groupService.deleteUserGroupRelations(id, deleteIds) && groupService.addUserGroupRelations(id, addIds); }  @Override IPage<UserDO> getUserPageByGroupId(Long groupId, Long count, Long page); @Override boolean changeUserPassword(Long id, ResetPasswordDTO dto); @Transactional @Override boolean deleteUser(Long id); @Override boolean updateUserInfo(Long id, UpdateUserInfoDTO validator); @Override IPage<GroupDO> getGroupPage(Long page, Long count); @Override GroupPermissionsBO getGroup(Long id); @Transactional @Override boolean createGroup(NewGroupDTO dto); @Override boolean updateGroup(Long id, UpdateGroupDTO dto); @Override boolean deleteGroup(Long id); @Override boolean dispatchPermission(DispatchPermissionDTO dto); @Override boolean dispatchPermissions(DispatchPermissionsDTO dto); @Override boolean removePermissions(RemovePermissionsDTO dto); @Override List<GroupDO> getAllGroups(); @Override List<PermissionDO> getAllPermissions(); @Override Map<String, List<PermissionDO>> getAllStructualPermissions();  }