remove double validation + improve userlimit update
This commit is contained in:
@ -207,7 +207,6 @@ public class GroupService {
|
||||
*/
|
||||
public void updateTitle(User user, Group group, String title) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateTitle(title.trim());
|
||||
|
||||
if (title.trim().equals(group.getTitle())) {
|
||||
return;
|
||||
@ -226,7 +225,6 @@ public class GroupService {
|
||||
*/
|
||||
public void updateDescription(User user, Group group, String description) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateDescription(description.trim());
|
||||
|
||||
if (description.trim().equals(group.getDescription())) {
|
||||
return;
|
||||
@ -263,13 +261,18 @@ public class GroupService {
|
||||
*/
|
||||
public void updateUserLimit(User user, Group group, long userLimit) {
|
||||
ValidationService.throwIfNoAdmin(group, user);
|
||||
ValidationService.validateUserLimit(userLimit, group);
|
||||
|
||||
if (userLimit == group.getUserLimit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Event event = new UpdateUserLimitEvent(group, user, userLimit);
|
||||
Event event;
|
||||
if (userLimit < group.getMembers().size()) {
|
||||
event = new UpdateUserLimitEvent(group, user, group.getMembers().size());
|
||||
} else {
|
||||
event = new UpdateUserLimitEvent(group, user, userLimit);
|
||||
}
|
||||
|
||||
event.apply(group);
|
||||
|
||||
eventStoreService.saveEvent(event);
|
||||
|
@ -111,33 +111,6 @@ public final class ValidationService {
|
||||
|
||||
// ##################################### VALIDATE FIELDS #####################################
|
||||
|
||||
|
||||
//TODO: max title length?
|
||||
public static void validateTitle(String title) {
|
||||
if (title == null || title.trim().isEmpty()) {
|
||||
log.error("Der Titel {} ist fehlerhaft!", title);
|
||||
throw new BadParameterException("Der Titel darf nicht leer sein!");
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: max description length?
|
||||
public static void validateDescription(String description) {
|
||||
if (description == null || description.trim().isEmpty()) {
|
||||
log.error("Die Beschreibung {} ist fehlerhaft!", description);
|
||||
throw new BadParameterException("Die Beschreibung darf nicht leer sein!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateUserLimit(long userLimit, Group group) {
|
||||
if (userLimit < 1) {
|
||||
throw new BadParameterException("Das Userlimit muss größer als 1 sein!");
|
||||
}
|
||||
|
||||
if (userLimit < group.getMembers().size()) {
|
||||
throw new BadParameterException("Das Userlimit kann nicht unter der momentanen Mitgliederanzahl sein!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateCreateForm(KeycloakAuthenticationToken token, CreateForm form) {
|
||||
if (!token.getAccount().getRoles().contains("orga")
|
||||
&& form.getType() == GroupType.LECTURE) {
|
||||
|
Reference in New Issue
Block a user