Merge pull request #129 from hhu-propra2/showInviteLink
Show invite link
This commit is contained in:
@ -6,11 +6,11 @@ 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;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.domain.exception.*;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.CsvService;
|
||||
@ -31,6 +31,7 @@ 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;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -235,9 +236,7 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("id") String 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);
|
||||
@ -247,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)) {
|
||||
@ -270,6 +269,12 @@ public class Gruppen2Controller {
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
String URL = request.getRequestURL().toString();
|
||||
String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
|
||||
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
||||
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@ -283,12 +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
|
||||
}
|
||||
if (group.getUserMaximum() < group.getMembers().size()) {
|
||||
return "error";
|
||||
throw new UserAlreadyExistsException("Du bist bereits in dieser Gruppe.");
|
||||
}
|
||||
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);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -296,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);
|
||||
}
|
||||
|
||||
@ -313,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));
|
||||
@ -326,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"})
|
||||
@ -353,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/";
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@ -17,10 +19,10 @@ public class MopsController {
|
||||
public String logout(HttpServletRequest request) throws Exception {
|
||||
request.logout();
|
||||
return "redirect:/gruppen2/";
|
||||
}/*
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() {
|
||||
return "error";
|
||||
}*/
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
|
||||
public class GroupFullException extends EventException {
|
||||
|
||||
public GroupFullException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Der User existiert bereits.", info);
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe hat die maximale Midgliederanzahl bereits erreicht!", info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NoAccessException extends EventException {
|
||||
public NoAccessException(String info) {
|
||||
super(HttpStatus.FORBIDDEN, "Hier hast du leider keinen Zugriff!", info);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class PageNotFoundException extends EventException {
|
||||
public PageNotFoundException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Die Seite wurde nicht gefunden!", info);
|
||||
}
|
||||
}
|
8
src/main/java/mops/gruppen2/service/SearchService.java
Normal file
8
src/main/java/mops/gruppen2/service/SearchService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SearchService {
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ public class UserService {
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
return groupService.projectEventList(events).get(0);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
throw new GroupNotFoundException("@UserService");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,3 +18,4 @@ keycloak.use-resource-role-mappings=true
|
||||
keycloak.autodetect-bearer-only=true
|
||||
keycloak.confidential-port=443
|
||||
server.error.include-stacktrace=always
|
||||
server.port=8080
|
||||
|
@ -47,6 +47,17 @@
|
||||
th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span>
|
||||
<span class="badge badge-pill badge-info" style="background: mediumorchid"
|
||||
th:text="${parent.getTitle()}">Parent</span>
|
||||
|
||||
<div class="input-group mb-3" style="margin-top: 10px" th:if="${group.getVisibility() == group.getVisibility().PRIVATE}">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="inputGroup-sizing-default" style="background: #52a1eb">Einladungslink:</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" th:value="${link}"
|
||||
aria-label="Recipient's username" aria-describedby="basic-addon2" id="groupLink" style="background: white" readonly>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="button" onclick="copyLink()">Link kopieren</button>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
<br>
|
||||
<div class="shadow-sm p-4" style="background: white">
|
||||
@ -105,6 +116,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function copyLink() {
|
||||
var copyText = document.getElementById("groupLink");
|
||||
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 99999);
|
||||
|
||||
document.execCommand("copy");
|
||||
}
|
||||
</script>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -26,6 +26,7 @@
|
||||
<p th:text="${message}"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none;">
|
||||
<a style="color: white" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a>
|
||||
|
Reference in New Issue
Block a user