From f618d1c1a7411bce7a7479dd08230cd8b4f4d395 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Fri, 9 Dec 2022 22:05:29 +0100 Subject: [PATCH] fix validation --- .../jitsi/controller/JitsiRoomController.java | 4 ++-- .../JitsiRoomManagementController.java | 2 +- .../validation/JitsiRoomValidator.java | 22 ++++++++++++++----- .../validation/TimeslotValidator.java | 2 +- pom.xml | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomController.java b/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomController.java index 0b0297e..c97ee74 100644 --- a/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomController.java +++ b/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomController.java @@ -101,7 +101,7 @@ public class JitsiRoomController extends BaseController { Errors errors = new RequestBodyErrors(jitsiRoom); if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) { - jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors); + jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors); } else { jitsiRoomValidator.validate(jitsiRoom, errors); } @@ -152,7 +152,7 @@ public class JitsiRoomController extends BaseController { Errors errors = new RequestBodyErrors(jitsiRoom); if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) { - jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors); + jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors); } else { jitsiRoomValidator.validate(jitsiRoom, errors); } diff --git a/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomManagementController.java b/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomManagementController.java index 28bacd1..c439dde 100644 --- a/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomManagementController.java +++ b/jitsi/src/main/java/de/bstly/we/jitsi/controller/JitsiRoomManagementController.java @@ -64,7 +64,7 @@ public class JitsiRoomManagementController extends BaseController { @PostMapping public JitsiRoom createOrUpdateJitsiRoom(@RequestBody JitsiRoom jitsiRoom) { Errors errors = new RequestBodyErrors(jitsiRoom); - jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors); + jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors); if (errors.hasErrors()) { throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT); } diff --git a/jitsi/src/main/java/de/bstly/we/jitsi/controller/validation/JitsiRoomValidator.java b/jitsi/src/main/java/de/bstly/we/jitsi/controller/validation/JitsiRoomValidator.java index 878a5ab..2b7567a 100644 --- a/jitsi/src/main/java/de/bstly/we/jitsi/controller/validation/JitsiRoomValidator.java +++ b/jitsi/src/main/java/de/bstly/we/jitsi/controller/validation/JitsiRoomValidator.java @@ -52,7 +52,7 @@ public class JitsiRoomValidator implements Validator { public void validate(Object target, Errors errors) { JitsiRoom jitsiRoom = (JitsiRoom) target; - validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors); + validate(jitsiRoom.getOwner(), jitsiRoom, errors); if (errors.hasErrors()) { return; @@ -60,7 +60,7 @@ public class JitsiRoomValidator implements Validator { validateRoom(jitsiRoom.getRoom(), errors); - validateExpiry(jitsiRoom, errors); + validateExistingExpiriy(jitsiRoom, errors); } @@ -71,7 +71,7 @@ public class JitsiRoomValidator implements Validator { * @param roomName the room name * @param errors the errors */ - public void validate(Long owner, String roomName, Errors errors) { + public void validate(Long owner, JitsiRoom jitsiRoom, Errors errors) { if (owner == null) { errors.rejectValue("owner", "REQUIRED"); return; @@ -82,15 +82,17 @@ public class JitsiRoomValidator implements Validator { return; } - if (!StringUtils.hasText(roomName)) { + if (!StringUtils.hasText(jitsiRoom.getRoom())) { errors.rejectValue("room", "REQUIRED"); return; } - if (!roomName.matches(ROOM_NAME_REGEX)) { + if (!jitsiRoom.getRoom().matches(ROOM_NAME_REGEX)) { errors.rejectValue("room", "NOT_VALID"); return; } + + validateExpiry(jitsiRoom, errors); } /** @@ -139,8 +141,17 @@ public class JitsiRoomValidator implements Validator { && jitsiRoom.getStarts().isBefore(jitsiRoom.getModerationStarts())) { errors.rejectValue("moderationStarts", "NOT_VALID"); return; + } else + // no expires before start + if (jitsiRoom.getStarts() != null && jitsiRoom.getExpires() != null + && jitsiRoom.getStarts().isAfter(jitsiRoom.getExpires())) { + errors.rejectValue("expires", "NOT_VALID"); + return; } + } + + public void validateExistingExpiriy(JitsiRoom jitsiRoom, Errors errors) { // no expiry + no start if (jitsiRoom.getExpires() == null && jitsiRoom.getStarts() == null) { if (jitsiRoomRepository.exists(qJitsiRoom.room.eq(jitsiRoom.getRoom()) @@ -196,5 +207,4 @@ public class JitsiRoomValidator implements Validator { } } } - } diff --git a/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java b/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java index 92c3549..c0fd3ea 100644 --- a/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java +++ b/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java @@ -77,7 +77,7 @@ public class TimeslotValidator implements Validator { timeslot.setStarts(InstantHelper.truncate(timeslot.getStarts(), ChronoUnit.SECONDS)); timeslot.setEnds(InstantHelper.truncate(timeslot.getEnds(), ChronoUnit.SECONDS)); - if (timeslot.getStarts().isAfter(timeslot.getStarts())) { + if (timeslot.getStarts().isAfter(timeslot.getEnds())) { errors.rejectValue("starts", "NOT_VALID"); errors.rejectValue("ends", "NOT_VALID"); } else { diff --git a/pom.xml b/pom.xml index 5839dc1..7bc28e5 100755 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 11 2.19.0 - 2.0.3-SNAPSHOT + 2.0.4-SNAPSHOT