diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index d7ec39d..3623712 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -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 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 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"; diff --git a/src/main/java/mops/gruppen2/service/ControllerService.java b/src/main/java/mops/gruppen2/service/ControllerService.java index f1fe45a..1152832 100644 --- a/src/main/java/mops/gruppen2/service/ControllerService.java +++ b/src/main/java/mops/gruppen2/service/ControllerService.java @@ -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 users) { + public void createLecture(Account account, String title, String description, Boolean visibility, List 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); } diff --git a/src/main/resources/templates/editMembers.html b/src/main/resources/templates/editMembers.html index 9988370..f71895e 100644 --- a/src/main/resources/templates/editMembers.html +++ b/src/main/resources/templates/editMembers.html @@ -21,6 +21,9 @@
  • Suche
  • +
  • + Veranstaltung +
  • @@ -29,6 +32,22 @@
    + +
    +
    +
    +
    +
    + + +
    +
    +
    + +
    +
    +
    +