1

Merge pull request #129 from hhu-propra2/showInviteLink

Show invite link
This commit is contained in:
Max Oerter
2020-03-24 16:36:02 +01:00
committed by GitHub
10 changed files with 79 additions and 22 deletions

View File

@ -6,11 +6,11 @@ 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.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.domain.exception.NoAdminAfterActionException; import mops.gruppen2.domain.exception.NoAdminAfterActionException;
import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.domain.exception.*;
import mops.gruppen2.security.Account; import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.CsvService; import mops.gruppen2.service.CsvService;
@ -31,6 +31,7 @@ import org.springframework.web.context.annotation.SessionScope;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import java.io.CharConversionException; import java.io.CharConversionException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -235,9 +236,7 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}") @GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException {
Model model,
@PathVariable("id") 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));
Account account = keyCloakService.createAccountFromPrincipal(token); Account account = keyCloakService.createAccountFromPrincipal(token);
@ -247,7 +246,7 @@ public class Gruppen2Controller {
Group parent = new Group(); Group parent = new Group();
if (group.getTitle() == null) { if (group.getTitle() == null) {
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@details");
} }
if (!group.getMembers().contains(user)) { if (!group.getMembers().contains(user)) {
@ -270,6 +269,12 @@ public class Gruppen2Controller {
model.addAttribute("roles", group.getRoles()); model.addAttribute("roles", group.getRoles());
model.addAttribute("user", user); model.addAttribute("user", user);
model.addAttribute("admin", Role.ADMIN); 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"; return "detailsMember";
} }
@ -283,12 +288,13 @@ public class Gruppen2Controller {
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));
if (group.getMembers().contains(user)) { 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)); 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/"; return "redirect:/gruppen2/";
} }
@ -296,13 +302,13 @@ public class Gruppen2Controller {
@GetMapping("/detailsSearch") @GetMapping("/detailsSearch")
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
Model model, Model model,
@RequestParam("id") String groupId) throws EventException { @RequestParam("id") String id) 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(id));
UUID parentId = group.getParent(); UUID parentId = group.getParent();
Group parent = new Group(); Group parent = new Group();
if (parentId != null) { if (!controllerService.idIsEmpty(parentId)) {
parent = userService.getGroupById(parentId); parent = userService.getGroupById(parentId);
} }
@ -313,11 +319,11 @@ public class Gruppen2Controller {
return "detailsNoMember"; return "detailsNoMember";
} }
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@search");
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}") @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)); model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
@ -326,7 +332,7 @@ public class Gruppen2Controller {
model.addAttribute("group", group); model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId(); return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
} }
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@accept");
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @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()); 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));
if (group.getRoles().get(user.getId()) != Role.ADMIN) { if (group.getRoles().get(user.getId()) != Role.ADMIN) {
return "error"; throw new NoAccessException("");
} }
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId)); controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";

View File

@ -1,5 +1,7 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.PageNotFoundException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -17,10 +19,10 @@ public class MopsController {
public String logout(HttpServletRequest request) throws Exception { public String logout(HttpServletRequest request) throws Exception {
request.logout(); request.logout();
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
}/* }
@GetMapping("*") @GetMapping("*")
public String defaultLink() { public String defaultLink() throws EventException {
return "error"; throw new PageNotFoundException("\uD83D\uDE41");
}*/ }
} }

View File

@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
public class GroupFullException extends EventException { public class GroupFullException extends EventException {
public GroupFullException(String info) { 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);
} }
} }

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,8 @@
package mops.gruppen2.service;
import org.springframework.stereotype.Service;
@Service
public class SearchService {
}

View File

@ -49,7 +49,7 @@ public class UserService {
List<Event> events = groupService.getGroupEvents(groupIds); List<Event> events = groupService.getGroupEvents(groupIds);
return groupService.projectEventList(events).get(0); return groupService.projectEventList(events).get(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
throw new GroupNotFoundException(this.getClass().toString()); throw new GroupNotFoundException("@UserService");
} }
} }
} }

View File

@ -18,3 +18,4 @@ keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true keycloak.autodetect-bearer-only=true
keycloak.confidential-port=443 keycloak.confidential-port=443
server.error.include-stacktrace=always server.error.include-stacktrace=always
server.port=8080

View File

@ -47,6 +47,17 @@
th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span> th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span>
<span class="badge badge-pill badge-info" style="background: mediumorchid" <span class="badge badge-pill badge-info" style="background: mediumorchid"
th:text="${parent.getTitle()}">Parent</span> 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> </h3>
<br> <br>
<div class="shadow-sm p-4" style="background: white"> <div class="shadow-sm p-4" style="background: white">
@ -105,6 +116,16 @@
</div> </div>
</div> </div>
</div> </div>
<script>
function copyLink() {
var copyText = document.getElementById("groupLink");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
}
</script>
</main> </main>
</body> </body>
</html> </html>

View File

@ -26,6 +26,7 @@
<p th:text="${message}"></p> <p th:text="${message}"></p>
</div> </div>
</div> </div>
<button class="btn btn-primary" <button class="btn btn-primary"
style="background: #52a1eb; border-style: none;"> style="background: #52a1eb; border-style: none;">
<a style="color: white" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a> <a style="color: white" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a>