1

Futher further refactor

Co-authored-by: AndiBuls <49692239+andibuls@users.noreply.github.com>
Co-authored-by: XXNitram <17749825+xxnitram@users.noreply.github.com>
This commit is contained in:
Lukas Ettel
2020-03-26 16:57:46 +01:00
parent d58cde597b
commit 3fc4d82dbe
2 changed files with 23 additions and 9 deletions

View File

@ -201,11 +201,10 @@ public class WebController {
UUID parentId = group.getParent(); UUID parentId = group.getParent();
String actualURL = request.getRequestURL().toString(); String actualURL = request.getRequestURL().toString();
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/")); String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
Group parent = controllerService.getParent(parentId);
validationService.throwIfGroupNotExisting(group.getTitle()); validationService.throwIfGroupNotExisting(group.getTitle());
Group parent = controllerService.getParent(parentId);
model.addAttribute("account", account); model.addAttribute("account", account);
if (!validationService.checkIfUserInGroup(group, user)) { if (!validationService.checkIfUserInGroup(group, user)) {
validationService.throwIfNoAccessToPrivate(group, user); validationService.throwIfNoAccessToPrivate(group, user);
@ -232,13 +231,16 @@ public class WebController {
@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("id") String groupId) throws EventException {
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(UUID.fromString(groupId));
validationService.throwIfUserAlreadyInGroup(group, user); validationService.throwIfUserAlreadyInGroup(group, user);
validationService.checkIfGroupFull(group); validationService.throwIfGroupFull(group);
controllerService.addUser(account, UUID.fromString(groupId)); controllerService.addUser(account, UUID.fromString(groupId));
model.addAttribute("account", account);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -247,12 +249,16 @@ public class WebController {
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
Model model, Model model,
@RequestParam("id") String groupId) throws EventException { @RequestParam("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.checkIfGroupFull(group);
UUID parentId = group.getParent(); UUID parentId = group.getParent();
Group parent = controllerService.getParent(parentId); Group parent = controllerService.getParent(parentId);
User user = new User(account.getName(), "", "", "");
model.addAttribute("account", account);
if (validationService.checkIfUserInGroup(group, user)){
return "redirect:/gruppen2/details/" + groupId;
}
model.addAttribute("group", group); model.addAttribute("group", group);
model.addAttribute("parentId", parentId); model.addAttribute("parentId", parentId);
@ -265,13 +271,18 @@ public class WebController {
@GetMapping("/acceptinvite/{groupId}") @GetMapping("/acceptinvite/{groupId}")
public String acceptInvite(KeycloakAuthenticationToken token, public String acceptInvite(KeycloakAuthenticationToken token,
Model model, @PathVariable String groupId) throws EventException { Model model, @PathVariable String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token)); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfGroupNotExisting(group.getTitle()); validationService.throwIfGroupNotExisting(group.getTitle());
model.addAttribute("account", account);
model.addAttribute("group", group); model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId(); return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
} }
//Bis hier gekommen
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup") @PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, public String pLeaveGroup(KeycloakAuthenticationToken token,
@ -318,6 +329,9 @@ public class WebController {
@RequestParam("group_id") String groupId, @RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException { @RequestParam("user_id") String userId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId));
User user = new User(account.getName(), "", "", "");
validationService.throwIfNoAdmin(group, user);
if (validationService.checkIfDemotingSelf(userId, groupId, account)) { if (validationService.checkIfDemotingSelf(userId, groupId, account)) {
return "redirect:/gruppen2/details/" + groupId; return "redirect:/gruppen2/details/" + groupId;
} }

View File

@ -58,7 +58,7 @@ public class ValidationService {
} }
} }
public void checkIfGroupFull(Group group) { public void throwIfGroupFull(Group group) {
if (group.getUserMaximum() < group.getMembers().size() + 1) { if (group.getUserMaximum() < group.getMembers().size() + 1) {
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten."); throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
} }