1

Add changeMetadata feature

Co-Authored-By: andibuls <andibuls@users.noreply.github.com>
Co-Authored-By: Max Oerter <mahgs@users.noreply.github.com>
Co-Authored-By: Christoph <churl@users.noreply.github.com>
This commit is contained in:
XXNitram
2020-03-24 14:34:52 +01:00
parent 491aeb1b66
commit 59bea22d8e
3 changed files with 119 additions and 1 deletions

View File

@ -6,6 +6,7 @@ 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.WrongFileException; import mops.gruppen2.domain.exception.WrongFileException;
@ -173,6 +174,47 @@ public class Gruppen2Controller {
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/details/changeMetadata/{id}")
public String changeMetadata(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(groupId);
model.addAttribute("account", account);
Long parentId = group.getParent();
Group parent = new Group();
if (!group.getMembers().contains(user)) {
if (group.getVisibility() == Visibility.PRIVATE) {
return "privateGroupNoMember";
}
model.addAttribute("group", group);
model.addAttribute("parentId", parentId);
model.addAttribute("parent", parent);
return "detailsNoMember";
}
model.addAttribute("title", group.getTitle());
model.addAttribute("description", group.getDescription());
model.addAttribute("admin", Role.ADMIN);
model.addAttribute("roles", group.getRoles());
model.addAttribute("groupId", group.getId());
model.addAttribute("user", user);
return "changeMetadata";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/changeMetadata")
public String pChangeMetadata(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@RequestParam("groupId") Long groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
controllerService.updateTitle(account, groupId, title);
controllerService.updateDescription(account, groupId, description);
return "redirect:/gruppen2/details/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup") @GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException { public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException {

View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<title>Gruppenerstellung</title>
<th:block th:fragment="headcontent">
<!-- Links, Skripts, Styles hier einfügen! -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</th:block>
</head>
<body>
<header>
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
<ul>
<li class="active">
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
</li>
<li th:case="${true}">
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
</li>
<li th:case="${false}">
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
</li>
<li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
</li>
</ul>
</nav>
</header>
<main th:fragment="bodycontent">
<div class="container-fluid">
<div class="row">
<div class="col-10">
<h1>Metadaten ändern</h1>
<form method="post" action="/gruppen2/details/changeMetadata">
<div class="shadow-sm p-2"
style=" border: 10px solid aliceblue; background: aliceblue">
<div class="form-group">
<label for="title">Titel</label>
<input class="form-control" id="title" required
type="text" th:name="title" th:value="${title}">
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea class="form-control" id="description" required rows="3"
th:name="description"
th:text="${description}"></textarea>
</div>
<div class="form-group pt-4">
<button class="btn btn-primary"
style="background: #52a1eb; border-style: none"
th:name="groupId"
th:value="${groupId}"
th:if="${roles.get(user.getId()) == admin}"
type="submit">Speichern
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</main>
</body>
</html>

View File

@ -32,7 +32,12 @@
<div class="container-fluid"> <div class="container-fluid">
<div> <div>
<div class="shadow-sm p-4 col-8" style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue"> <div class="shadow-sm p-4 col-8" style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word" th:text="${group.getTitle()}"></h1> <div class="row">
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word" th:text="${group.getTitle()}"></h1>
<a th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
class="btn btn-info btn-lg" th:if="${roles.get(user.getId()) == admin}">Ändern
</a>
</div>
<h3> <h3>
<span class="badge badge-pill badge-dark" style="background: darkslategray" <span class="badge badge-pill badge-dark" style="background: darkslategray"
th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span> th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span>