1

added link to controller

This commit is contained in:
[Mahgs]
2020-03-26 17:14:49 +01:00
parent 68a9ddeecc
commit bacf9be7cc
2 changed files with 15 additions and 15 deletions

View File

@ -3,14 +3,11 @@ package mops.gruppen2.controller;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.domain.dto.InviteLinkDTO;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.PageNotFoundException; import mops.gruppen2.domain.exception.PageNotFoundException;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.*;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService;
import mops.gruppen2.service.ValidationService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -39,13 +36,15 @@ public class WebController {
private final UserService userService; private final UserService userService;
private final ControllerService controllerService; private final ControllerService controllerService;
private final ValidationService validationService; private final ValidationService validationService;
private final InviteService inviteService;
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService) { public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService, InviteService inviteService) {
this.keyCloakService = keyCloakService; this.keyCloakService = keyCloakService;
this.groupService = groupService; this.groupService = groupService;
this.userService = userService; this.userService = userService;
this.controllerService = controllerService; this.controllerService = controllerService;
this.validationService = validationService; this.validationService = validationService;
this.inviteService = inviteService;
} }
/** /**
@ -187,12 +186,13 @@ public class WebController {
groups = validationService.checkSearch(search, groups, account); groups = validationService.checkSearch(search, groups, account);
model.addAttribute("account", account); model.addAttribute("account", account);
model.addAttribute("gruppen", groups); model.addAttribute("gruppen", groups);
model.addAttribute("inviteService", inviteService);
return "search"; return "search";
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}") @GetMapping("/details/{link}")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException { public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("link") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
@ -227,14 +227,14 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten") @PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, public String joinGroup(KeycloakAuthenticationToken token,
Model model, @RequestParam("id") String groupId) throws EventException { Model model, @RequestParam("link") String link) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
validationService.checkIfUserInGroupJoin(group, user); validationService.checkIfUserInGroupJoin(group, user);
validationService.checkIfGroupFull(group); validationService.checkIfGroupFull(group);
controllerService.addUser(account, UUID.fromString(groupId)); controllerService.addUser(account, group.getId());
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -258,11 +258,11 @@ public class WebController {
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{groupId}") @GetMapping("/acceptinvite/{link}")
public String acceptInvite(KeycloakAuthenticationToken token, public String acceptInvite(KeycloakAuthenticationToken token,
Model model, @PathVariable String groupId) throws EventException { Model model, @PathVariable String link) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
validationService.checkGroup(group.getTitle()); validationService.checkGroup(group.getTitle());
model.addAttribute("group", group); model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId(); return "redirect:/gruppen2/detailsSearch?id=" + group.getId();

View File

@ -62,7 +62,7 @@
<span class="badge badge-pill badge-success" <span class="badge badge-pill badge-success"
style="background: lightseagreen; margin-right: 25px;" style="background: lightseagreen; margin-right: 25px;"
th:if='${gruppe.getType() == gruppe.getType().LECTURE}'>Veranstaltung</span> th:if='${gruppe.getType() == gruppe.getType().LECTURE}'>Veranstaltung</span>
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}" <a th:href="@{/gruppen2/detailsSearch(link=${inviteService.getLinkFromGroupId(gruppe.getId())})}"
th:text="${#strings.abbreviate(gruppe.getTitle(), 50)}">Gruppenname</a> th:text="${#strings.abbreviate(gruppe.getTitle(), 50)}">Gruppenname</a>
</th> </th>
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}"> <td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">