|
|
|
@ -6,7 +6,6 @@ import mops.gruppen2.domain.Group;
|
|
|
|
|
import mops.gruppen2.domain.Role;
|
|
|
|
|
import mops.gruppen2.domain.User;
|
|
|
|
|
import mops.gruppen2.domain.Visibility;
|
|
|
|
|
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
|
|
|
|
import mops.gruppen2.domain.exception.EventException;
|
|
|
|
|
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
|
|
|
|
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
|
|
|
@ -19,8 +18,6 @@ import mops.gruppen2.service.GroupService;
|
|
|
|
|
import mops.gruppen2.service.KeyCloakService;
|
|
|
|
|
import mops.gruppen2.service.UserService;
|
|
|
|
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
@ -32,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.context.annotation.SessionScope;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.security.RolesAllowed;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.CharConversionException;
|
|
|
|
@ -238,7 +236,7 @@ public class Gruppen2Controller {
|
|
|
|
|
|
|
|
|
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
|
|
|
|
@GetMapping("/details/{id}")
|
|
|
|
|
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") Long groupId) throws EventException {
|
|
|
|
|
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException {
|
|
|
|
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
|
|
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
|
|
|
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
|
|
|
@ -248,7 +246,7 @@ public class Gruppen2Controller {
|
|
|
|
|
Group parent = new Group();
|
|
|
|
|
|
|
|
|
|
if (group.getTitle() == null) {
|
|
|
|
|
throw new GroupNotFoundException(this.getClass().toString());
|
|
|
|
|
throw new GroupNotFoundException("@details");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
@ -272,11 +270,10 @@ public class Gruppen2Controller {
|
|
|
|
|
model.addAttribute("user", user);
|
|
|
|
|
model.addAttribute("admin", Role.ADMIN);
|
|
|
|
|
|
|
|
|
|
String link = inviteLinkRepositoryService.findlinkByGroupId(group.getId());
|
|
|
|
|
String URL = request.getRequestURL().toString();
|
|
|
|
|
String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
|
|
|
|
|
|
|
|
|
|
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + link);
|
|
|
|
|
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
|
|
|
|
|
|
|
|
|
return "detailsMember";
|
|
|
|
|
}
|
|
|
|
@ -291,17 +288,13 @@ public class Gruppen2Controller {
|
|
|
|
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
|
|
|
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
|
|
|
|
if (group.getMembers().contains(user)) {
|
|
|
|
|
return "error"; //TODO: hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
|
|
|
|
throw new UserAlreadyExistsException("Du bist bereits in dieser Gruppe.");
|
|
|
|
|
}
|
|
|
|
|
if (group.getUserMaximum() < group.getMembers().size()) {
|
|
|
|
|
return "error";
|
|
|
|
|
}
|
|
|
|
|
controllerService.addUser(account, UUID.fromString(groupId));
|
|
|
|
|
if (group.getUserMaximum() < group.getMembers().size()) {
|
|
|
|
|
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
|
|
|
|
|
}
|
|
|
|
|
controllerService.addUser(account, groupId);
|
|
|
|
|
//controllerService.addUser(account, groupId);
|
|
|
|
|
return "redirect:/gruppen2/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -309,13 +302,13 @@ public class Gruppen2Controller {
|
|
|
|
|
@GetMapping("/detailsSearch")
|
|
|
|
|
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
|
|
|
|
Model model,
|
|
|
|
|
@RequestParam("id") String groupId) throws EventException {
|
|
|
|
|
@RequestParam("id") String id) throws EventException {
|
|
|
|
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
|
|
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
|
|
|
|
Group group = userService.getGroupById(UUID.fromString(id));
|
|
|
|
|
UUID parentId = group.getParent();
|
|
|
|
|
Group parent = new Group();
|
|
|
|
|
|
|
|
|
|
if (parentId != null) {
|
|
|
|
|
if (!controllerService.idIsEmpty(parentId)) {
|
|
|
|
|
parent = userService.getGroupById(parentId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -326,11 +319,11 @@ public class Gruppen2Controller {
|
|
|
|
|
|
|
|
|
|
return "detailsNoMember";
|
|
|
|
|
}
|
|
|
|
|
throw new GroupNotFoundException(this.getClass().toString());
|
|
|
|
|
throw new GroupNotFoundException("@search");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
|
|
|
@GetMapping("/acceptinvite/{link}")
|
|
|
|
|
@GetMapping("/acceptinvite/{groupId}")
|
|
|
|
|
public String acceptInvite(KeycloakAuthenticationToken token,
|
|
|
|
|
Model model, @PathVariable String groupId) throws EventException {
|
|
|
|
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
|
|
@ -339,7 +332,7 @@ public class Gruppen2Controller {
|
|
|
|
|
model.addAttribute("group", group);
|
|
|
|
|
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
|
|
|
|
}
|
|
|
|
|
throw new GroupNotFoundException(this.getClass().toString());
|
|
|
|
|
throw new GroupNotFoundException("@accept");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
|
|
@ -366,7 +359,7 @@ public class Gruppen2Controller {
|
|
|
|
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
|
|
|
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
|
|
|
|
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
|
|
|
|
|
return "error";
|
|
|
|
|
throw new NoAccessException("");
|
|
|
|
|
}
|
|
|
|
|
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
|
|
|
|
return "redirect:/gruppen2/";
|
|
|
|
|