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);
|
Errors errors = new RequestBodyErrors(jitsiRoom);
|
||||||
|
|
||||||
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) {
|
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) {
|
||||||
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors);
|
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors);
|
||||||
} else {
|
} else {
|
||||||
jitsiRoomValidator.validate(jitsiRoom, errors);
|
jitsiRoomValidator.validate(jitsiRoom, errors);
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ public class JitsiRoomController extends BaseController {
|
|||||||
Errors errors = new RequestBodyErrors(jitsiRoom);
|
Errors errors = new RequestBodyErrors(jitsiRoom);
|
||||||
|
|
||||||
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) {
|
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_ADMIN)) {
|
||||||
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors);
|
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors);
|
||||||
} else {
|
} else {
|
||||||
jitsiRoomValidator.validate(jitsiRoom, errors);
|
jitsiRoomValidator.validate(jitsiRoom, errors);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class JitsiRoomManagementController extends BaseController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public JitsiRoom createOrUpdateJitsiRoom(@RequestBody JitsiRoom jitsiRoom) {
|
public JitsiRoom createOrUpdateJitsiRoom(@RequestBody JitsiRoom jitsiRoom) {
|
||||||
Errors errors = new RequestBodyErrors(jitsiRoom);
|
Errors errors = new RequestBodyErrors(jitsiRoom);
|
||||||
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors);
|
jitsiRoomValidator.validate(jitsiRoom.getOwner(), jitsiRoom, errors);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT);
|
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class JitsiRoomValidator implements Validator {
|
|||||||
public void validate(Object target, Errors errors) {
|
public void validate(Object target, Errors errors) {
|
||||||
JitsiRoom jitsiRoom = (JitsiRoom) target;
|
JitsiRoom jitsiRoom = (JitsiRoom) target;
|
||||||
|
|
||||||
validate(jitsiRoom.getOwner(), jitsiRoom.getRoom(), errors);
|
validate(jitsiRoom.getOwner(), jitsiRoom, errors);
|
||||||
|
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return;
|
return;
|
||||||
@ -60,7 +60,7 @@ public class JitsiRoomValidator implements Validator {
|
|||||||
|
|
||||||
validateRoom(jitsiRoom.getRoom(), errors);
|
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 roomName the room name
|
||||||
* @param errors the errors
|
* @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) {
|
if (owner == null) {
|
||||||
errors.rejectValue("owner", "REQUIRED");
|
errors.rejectValue("owner", "REQUIRED");
|
||||||
return;
|
return;
|
||||||
@ -82,15 +82,17 @@ public class JitsiRoomValidator implements Validator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtils.hasText(roomName)) {
|
if (!StringUtils.hasText(jitsiRoom.getRoom())) {
|
||||||
errors.rejectValue("room", "REQUIRED");
|
errors.rejectValue("room", "REQUIRED");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!roomName.matches(ROOM_NAME_REGEX)) {
|
if (!jitsiRoom.getRoom().matches(ROOM_NAME_REGEX)) {
|
||||||
errors.rejectValue("room", "NOT_VALID");
|
errors.rejectValue("room", "NOT_VALID");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateExpiry(jitsiRoom, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,8 +141,17 @@ public class JitsiRoomValidator implements Validator {
|
|||||||
&& jitsiRoom.getStarts().isBefore(jitsiRoom.getModerationStarts())) {
|
&& jitsiRoom.getStarts().isBefore(jitsiRoom.getModerationStarts())) {
|
||||||
errors.rejectValue("moderationStarts", "NOT_VALID");
|
errors.rejectValue("moderationStarts", "NOT_VALID");
|
||||||
return;
|
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
|
// no expiry + no start
|
||||||
if (jitsiRoom.getExpires() == null && jitsiRoom.getStarts() == null) {
|
if (jitsiRoom.getExpires() == null && jitsiRoom.getStarts() == null) {
|
||||||
if (jitsiRoomRepository.exists(qJitsiRoom.room.eq(jitsiRoom.getRoom())
|
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.setStarts(InstantHelper.truncate(timeslot.getStarts(), ChronoUnit.SECONDS));
|
||||||
timeslot.setEnds(InstantHelper.truncate(timeslot.getEnds(), 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("starts", "NOT_VALID");
|
||||||
errors.rejectValue("ends", "NOT_VALID");
|
errors.rejectValue("ends", "NOT_VALID");
|
||||||
} else {
|
} else {
|
||||||
|
2
pom.xml
2
pom.xml
@ -13,7 +13,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
<log4j2.version>2.19.0</log4j2.version>
|
<log4j2.version>2.19.0</log4j2.version>
|
||||||
<revision>2.0.3-SNAPSHOT</revision>
|
<revision>2.0.4-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
Loading…
Reference in New Issue
Block a user