1

Add validation for setting a new userMaximum

Co-Authored-By: Talha Caliskan <killerber4t@users.noreply.github.com>
This commit is contained in:
XXNitram
2020-03-26 14:14:45 +01:00
parent 1cc52d7dce
commit 677ed4e37b
2 changed files with 14 additions and 0 deletions

View File

@ -327,6 +327,7 @@ public class WebController {
@RequestParam("group_id") String groupId,
KeycloakAuthenticationToken token) {
Account account = keyCloakService.createAccountFromPrincipal(token);
validationService.checkIfNewMaximumIsValid(maximum, groupId);
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
return "redirect:/gruppen2/details/members/" + groupId;
}

View File

@ -148,6 +148,19 @@ public class ValidationService {
}
}
}
public void checkIfNewMaximumIsValid(Long newUserMaximum, String groupId) {
Group group = userService.getGroupById(UUID.fromString(groupId));
if (newUserMaximum == null) {
throw new BadParameterException("Es wurde keine neue maximale Teilnehmeranzahl angegeben!");
}
if (newUserMaximum < 1 || newUserMaximum > 10000L) {
throw new BadParameterException("Die neue maximale Teilnehmeranzahl wurde nicht korrekt angegeben!");
}
if (group.getMembers().size() > newUserMaximum) {
throw new BadParameterException("Die neue maximale Teilnehmeranzahl ist kleiner als die aktuelle Teilnehmeranzahl!");
}
}
}