1

Add addUsersFromCsv in editMembers Overview

Co-Authored-By: Lukas Ettel <lukasettel@users.noreply.github.com>
Co-Authored-By: tomvahl <tomvahl@users.noreply.github.com>
This commit is contained in:
XXNitram
2020-03-18 16:42:06 +01:00
parent 90124a7c15
commit 4450a091de
3 changed files with 39 additions and 5 deletions

View File

@ -83,7 +83,7 @@ public class Gruppen2Controller {
@RequestParam(value = "title") String title,
@RequestParam(value = "beschreibung") String beschreibung,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<User> userList = new ArrayList<>();
@ -96,6 +96,18 @@ public class Gruppen2Controller {
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv")
public String addUsersFromCsv(@RequestParam (value = "group_id") Long id,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>();
if(!file.isEmpty()) {
userList = CsvService.read(file.getInputStream());
}
controllerService.addUserList(userList, id);
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/createGroup")
public String createGroup(KeycloakAuthenticationToken token, Model model) {
@ -193,10 +205,11 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/members")
public String editMembers(Model model, KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
public String editMembers(Model model, KeycloakAuthenticationToken token, @RequestParam (value = "group_id") Long id) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(id);
if(group.getRoles().get(account.getName()) == Role.ADMIN) {
model.addAttribute("account", account);
model.addAttribute("members", group.getMembers());
model.addAttribute("group", group);
return "editMembers";

View File

@ -1,6 +1,7 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.*;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.event.*;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service;
@ -13,7 +14,7 @@ public class ControllerService {
private final UserService userService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
public ControllerService(EventService eventService, UserService userService) {
public ControllerService(EventService eventService, UserService userService, InviteLinkRepositoryService inviteLinkRepositoryService) {
this.eventService = eventService;
this.userService = userService;
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
@ -92,7 +93,7 @@ public class ControllerService {
eventService.saveEvent(deleteUserEvent);
}
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) {
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException {
Visibility visibility1;
Long group_id = eventService.checkGroup();
@ -104,11 +105,12 @@ public class ControllerService {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
eventService.saveEvent(createGroupEvent);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
addUser(account, group_id);
updateTitle(account, group_id, title);
updateDescription(account, group_id, description);
updateRole(account, group_id);
updateRole(user, group_id);
addUserList(users, group_id);
}