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:
@ -83,7 +83,7 @@ public class Gruppen2Controller {
|
|||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
@RequestParam(value = "beschreibung") String beschreibung,
|
@RequestParam(value = "beschreibung") String beschreibung,
|
||||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
@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);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<User> userList = new ArrayList<>();
|
List<User> userList = new ArrayList<>();
|
||||||
@ -96,6 +96,18 @@ public class Gruppen2Controller {
|
|||||||
return "redirect:/gruppen2/";
|
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)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("/createGroup")
|
@GetMapping("/createGroup")
|
||||||
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||||
@ -193,10 +205,11 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("/details/members")
|
@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);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = userService.getGroupById(id);
|
Group group = userService.getGroupById(id);
|
||||||
if(group.getRoles().get(account.getName()) == Role.ADMIN) {
|
if(group.getRoles().get(account.getName()) == Role.ADMIN) {
|
||||||
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("members", group.getMembers());
|
model.addAttribute("members", group.getMembers());
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
return "editMembers";
|
return "editMembers";
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.*;
|
import mops.gruppen2.domain.*;
|
||||||
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -13,7 +14,7 @@ public class ControllerService {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||||
|
|
||||||
public ControllerService(EventService eventService, UserService userService) {
|
public ControllerService(EventService eventService, UserService userService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||||
@ -92,7 +93,7 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(deleteUserEvent);
|
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;
|
Visibility visibility1;
|
||||||
Long group_id = eventService.checkGroup();
|
Long group_id = eventService.checkGroup();
|
||||||
|
|
||||||
@ -104,11 +105,12 @@ public class ControllerService {
|
|||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
addUser(account, group_id);
|
addUser(account, group_id);
|
||||||
updateTitle(account, group_id, title);
|
updateTitle(account, group_id, title);
|
||||||
updateDescription(account, group_id, description);
|
updateDescription(account, group_id, description);
|
||||||
updateRole(account, group_id);
|
updateRole(user, group_id);
|
||||||
addUserList(users, group_id);
|
addUserList(users, group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li th:if="${account.getRoles().contains('orga')}">
|
||||||
|
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
@ -29,6 +32,22 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9">
|
<div class="col-9">
|
||||||
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
|
<!-- absichern im controller nicht vergessen -->
|
||||||
|
<div class="form-group pt-4" th:if="${account.getRoles().contains('orga')}">
|
||||||
|
<form method="post" action="/gruppen2/details/members/addUsersFromCsv" enctype="multipart/form-data">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-9">
|
||||||
|
<div class="custom-file">
|
||||||
|
<input type="file" class="custom-file-input" id="file" th:name="file">
|
||||||
|
<label class="custom-file-label" for="file">CSV Datei von Mitgliedern hochladen</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
<button th:name="group_id" th:value="${group.getId()}" class="btn btn-primary" type="submit" style="background: #52a1eb; border-style: none">Mitglieder hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user