fix validation
This commit is contained in:
parent
27c6ab5630
commit
f618d1c1a7
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user