add adjusting UserMax
This commit is contained in:
@ -141,12 +141,18 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||||
@PostMapping("/details/members/addUsersFromCsv")
|
@PostMapping("/details/members/addUsersFromCsv")
|
||||||
public String addUsersFromCsv(@RequestParam("group_id") Long groupId,
|
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("group_id") Long groupId,
|
||||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<User> userList = new ArrayList<>();
|
List<User> userList = new ArrayList<>();
|
||||||
|
Group group = userService.getGroupById(groupId);
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
userList = CsvService.read(file.getInputStream());
|
userList = CsvService.read(file.getInputStream());
|
||||||
|
if(userList.size()+group.getMembers().size()>group.getUserMaximum()){
|
||||||
|
controllerService.updateMaxUser(account, groupId, Long.valueOf(userList.size()) + group.getMembers().size());
|
||||||
|
}
|
||||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||||
throw new WrongFileException(file.getOriginalFilename());
|
throw new WrongFileException(file.getOriginalFilename());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,8 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
|
|||||||
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
|
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
|
||||||
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
|
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
|
||||||
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
|
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
|
||||||
@JsonSubTypes.Type(value = DeleteGroupEvent.class, name = "DeleteGroupEvent")
|
@JsonSubTypes.Type(value = DeleteGroupEvent.class, name = "DeleteGroupEvent"),
|
||||||
|
@JsonSubTypes.Type(value = UpdateUserMaxEvent.class, name = "UpdateUserMaxEvent")
|
||||||
})
|
})
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package mops.gruppen2.domain.event;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
|
|
||||||
|
public class UpdateUserMaxEvent extends Event {
|
||||||
|
|
||||||
|
private Long userMaximum;
|
||||||
|
|
||||||
|
public UpdateUserMaxEvent(Long group_id, String user_id, Long userMaximum) {
|
||||||
|
super(group_id,user_id);
|
||||||
|
this.userMaximum = userMaximum;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyEvent(Group group) throws EventException {
|
||||||
|
group.setUserMaximum(this.userMaximum);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,13 +5,7 @@ import mops.gruppen2.domain.GroupType;
|
|||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.event.AddUserEvent;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
|
||||||
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
|
||||||
import mops.gruppen2.domain.event.DeleteUserEvent;
|
|
||||||
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
|
|
||||||
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
|
||||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
|
||||||
import mops.gruppen2.domain.exception.EventException;
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
@ -120,6 +114,11 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateMaxUser(Account account, Long groupId, Long userMaximum) {
|
||||||
|
UpdateUserMaxEvent updateUserMaxEvent = new UpdateUserMaxEvent(groupId,account.getName(),userMaximum);
|
||||||
|
eventService.saveEvent(updateUserMaxEvent);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateRole(String userId, Long groupId) throws EventException {
|
public void updateRole(String userId, Long groupId) throws EventException {
|
||||||
UpdateRoleEvent updateRoleEvent;
|
UpdateRoleEvent updateRoleEvent;
|
||||||
Group group = userService.getGroupById(groupId);
|
Group group = userService.getGroupById(groupId);
|
||||||
|
|||||||
Reference in New Issue
Block a user