Add validation for setting a new userMaximum
Co-Authored-By: Talha Caliskan <killerber4t@users.noreply.github.com>
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user