Merge remote-tracking branch 'origin/edit-User' into import-csv-in-overview
# Conflicts: # src/main/java/mops/gruppen2/controller/Gruppen2Controller.java # src/main/java/mops/gruppen2/service/ControllerService.java
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -30,3 +30,5 @@ out/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.floo
|
||||||
|
.flooignore
|
||||||
|
|||||||
@ -3,9 +3,12 @@ package mops.gruppen2.controller;
|
|||||||
import mops.gruppen2.config.Gruppen2Config;
|
import mops.gruppen2.config.Gruppen2Config;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
|
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.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import mops.gruppen2.service.*;
|
import mops.gruppen2.service.*;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
@ -23,6 +26,7 @@ import javax.annotation.security.RolesAllowed;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@SessionScope
|
@SessionScope
|
||||||
@ -116,7 +120,7 @@ public class Gruppen2Controller {
|
|||||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
@RequestParam(value = "beschreibung") String beschreibung,
|
@RequestParam(value = "beschreibung") String beschreibung,
|
||||||
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
visibility = visibility == null;
|
visibility = visibility == null;
|
||||||
@ -134,7 +138,9 @@ 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());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("role", group.getRoles().get(user.getUser_id()));
|
model.addAttribute("roles", group.getRoles());
|
||||||
|
model.addAttribute("user", user);
|
||||||
|
model.addAttribute("admin", Role.ADMIN);
|
||||||
return "detailsMember";
|
return "detailsMember";
|
||||||
}
|
}
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
@ -145,6 +151,9 @@ public class Gruppen2Controller {
|
|||||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
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());
|
||||||
|
Group group = userService.getGroupById(id);
|
||||||
|
if(group.getMembers().contains(user)) return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
||||||
controllerService.addUser(account,id);
|
controllerService.addUser(account,id);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
@ -177,10 +186,34 @@ public class Gruppen2Controller {
|
|||||||
@PostMapping("/leaveGroup")
|
@PostMapping("/leaveGroup")
|
||||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long id) {
|
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam(value = "group_id") Long id) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
controllerService.deleteUser(account, id);
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
controllerService.deleteUser(user, id);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@GetMapping("/details/members")
|
||||||
|
public String editMembers(Model model, KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
Group group = userService.getGroupById(id);
|
||||||
|
if(group.getRoles().get(account.getName()) == Role.ADMIN) {
|
||||||
|
model.addAttribute("members", group.getMembers());
|
||||||
|
model.addAttribute("group", group);
|
||||||
|
return "editMembers";
|
||||||
|
} else {
|
||||||
|
return "redirect:/details/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@PostMapping("/changeRole")
|
||||||
|
public String changeRole(KeycloakAuthenticationToken token, @RequestParam (value = "group_id") Long id,
|
||||||
|
@RequestParam (value = "user") User user) throws EventException {
|
||||||
|
controllerService.updateRole(user, id);
|
||||||
|
return "redirect:/details/members/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("*")
|
@GetMapping("*")
|
||||||
public String defaultLink() {
|
public String defaultLink() {
|
||||||
return "errorRenameLater";
|
return "errorRenameLater";
|
||||||
|
|||||||
@ -4,20 +4,18 @@ import mops.gruppen2.domain.*;
|
|||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ControllerService {
|
public class ControllerService {
|
||||||
|
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final UserService userService;
|
||||||
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||||
|
|
||||||
public ControllerService(EventService eventService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
public ControllerService(EventService eventService, UserService userService) {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
|
this.userService = userService;
|
||||||
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +28,7 @@ public class ControllerService {
|
|||||||
* @param title Gruppentitel
|
* @param title Gruppentitel
|
||||||
* @param description Gruppenbeschreibung
|
* @param description Gruppenbeschreibung
|
||||||
*/
|
*/
|
||||||
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException {
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
Long group_id = eventService.checkGroup();
|
Long group_id = eventService.checkGroup();
|
||||||
|
|
||||||
@ -43,11 +41,12 @@ public class ControllerService {
|
|||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.SIMPLE, visibility1);
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
addUser(account, group_id);
|
addUser(account, group_id);
|
||||||
updateTitle(account, group_id, title);
|
updateTitle(account, group_id, title);
|
||||||
updateDescription(account, group_id, description);
|
updateDescription(account, group_id, description);
|
||||||
updateRole(account, group_id);
|
updateRole(user, group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createInviteLink(Long group_id) {
|
private void createInviteLink(Long group_id) {
|
||||||
@ -77,13 +76,19 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(updateGroupDescriptionEvent);
|
eventService.saveEvent(updateGroupDescriptionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRole(Account account,Long group_id){
|
public void updateRole(User user, Long group_id) throws EventException {
|
||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(group_id,account.getName(),Role.ADMIN);
|
UpdateRoleEvent updateRoleEvent;
|
||||||
|
Group group = userService.getGroupById(group_id);
|
||||||
|
if(group.getRoles().get(user.getUser_id()) == Role.ADMIN) {
|
||||||
|
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.MEMBER);
|
||||||
|
} else {
|
||||||
|
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.ADMIN);
|
||||||
|
}
|
||||||
eventService.saveEvent(updateRoleEvent);
|
eventService.saveEvent(updateRoleEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteUser(Account account, Long group_id){
|
public void deleteUser(User user, Long group_id){
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id,account.getName());
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id, user.getUser_id());
|
||||||
eventService.saveEvent(deleteUserEvent);
|
eventService.saveEvent(deleteUserEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,4 +111,9 @@ public class ControllerService {
|
|||||||
updateRole(account, group_id);
|
updateRole(account, group_id);
|
||||||
addUserList(users, group_id);
|
addUserList(users, group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteGroupEvent(User user, Long group_id) {
|
||||||
|
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id());
|
||||||
|
eventService.saveEvent(deleteGroupEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ CREATE TABLE event
|
|||||||
event_id INT PRIMARY KEY AUTO_INCREMENT,
|
event_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
group_id INT NOT NULL,
|
group_id INT NOT NULL,
|
||||||
user_id VARCHAR(50),
|
user_id VARCHAR(50),
|
||||||
event_payload VARCHAR(255),
|
event_payload VARCHAR(2500),
|
||||||
visibility BOOLEAN
|
visibility BOOLEAN
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -35,11 +35,11 @@
|
|||||||
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
<h1 style="color: dodgerblue; font-weight: bold" th:text="${group.getTitle()}"></h1>
|
||||||
<p style="font-weight: bold">
|
<p style="font-weight: bold">
|
||||||
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if="${group.getVisibility() == group.getVisibility().PRIVATE }">Private Gruppe</span>
|
<span class="badge badge-pill badge-dark" style="background: darkslategray" th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span>
|
||||||
<span class="badge badge-pill badge-primary" th:if="${group.getVisibility() == group.getVisibility().PUBLIC}">Öffentliche Gruppe</span>
|
<span class="badge badge-pill badge-primary" th:if="${group.getVisibility() == group.getVisibility().PUBLIC}">Öffentliche Gruppe</span>
|
||||||
<span class="badge badge-pill badge-success" style="background: lightseagreen" th:if="${group.getType() == group.getType().LECTURE}"> Veranstaltung</span>
|
<span class="badge badge-pill badge-success" style="background: lightseagreen" th:if='${group.getType() == group.getType().LECTURE}'> Veranstaltung</span>
|
||||||
</p>
|
</p>
|
||||||
<p th:text="${group.getDescription()}"></p>
|
<p style="overflow-wrap: break-word" th:text="${group.getDescription()}"></p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<form method="post" action="/gruppen2/leaveGroup">
|
<form method="post" action="/gruppen2/leaveGroup">
|
||||||
@ -52,14 +52,18 @@
|
|||||||
<div class="col-3" style="white-space: nowrap">
|
<div class="col-3" style="white-space: nowrap">
|
||||||
<div>
|
<div>
|
||||||
<h2 style="display: inline-block; margin: 0">Mitglieder</h2>
|
<h2 style="display: inline-block; margin: 0">Mitglieder</h2>
|
||||||
<button class="btn btn-secondary" type="warning" style="background: slategrey; float: right" >Mitglieder bearbeiten</button>
|
<div th:if='${group.getRoles().get(user.getUser_id()) == admin}'>
|
||||||
|
<form method="get" action="/gruppen2/details/members">
|
||||||
|
<button th:name="group_id" th:value="${group.getId()}" class="btn btn-secondary" type="submit" style="background: slategrey; margin-top: 200px; float: right" >Mitglieder bearbeiten</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ul th:each="member : ${group.getMembers()}" class="list-group-flush" style="background: slategrey">
|
<ul th:each="member : ${group.getMembers()}" class="list-group-flush" style="background: slategrey">
|
||||||
<li class="list-group-item" style="background: aliceblue">
|
<li class="list-group-item" style="background: aliceblue">
|
||||||
<span th:text="${member.getUser_id()}"></span>
|
<span th:text="${member.getUser_id()}"></span>
|
||||||
<span th:if="${role == role.ADMIN}" class="badge badge-success">admin</span>
|
<span th:if='${group.getRoles().get(member.getUser_id()) == admin}' class="badge badge-success">admin</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
58
src/main/resources/templates/editMembers.html
Normal file
58
src/main/resources/templates/editMembers.html
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org"
|
||||||
|
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Gruppendetails</title>
|
||||||
|
<th:block th:fragment="headcontent">
|
||||||
|
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||||
|
</th:block>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||||
|
<ul>
|
||||||
|
<li class="active">
|
||||||
|
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">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-9">
|
||||||
|
<div class="shadow-sm p-4" style="border: 10px solid aliceblue; background: aliceblue">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Mitglied</th>
|
||||||
|
<th scope="col">Rolle</th>
|
||||||
|
<th scope="col" style="width: 320px">Optionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="table-striped">
|
||||||
|
<tr th:each="member : ${group.getMembers()}">
|
||||||
|
<th th:text="${member.getUser_id()}"></th>
|
||||||
|
<td>
|
||||||
|
<span th:if='${group.getRoles().get(member.getUser_id()) == admin}'>Mitglied</span>
|
||||||
|
<span th:if='${group.getRoles().get(member.getUser_id()) != admin}'>Admin</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-warning">Rolle ändern</button> <!-- th:if -->
|
||||||
|
<button class="btn btn-danger">Mitglied entfernen</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<button type="button" class="btn btn-primary" style="margin: auto">
|
<button type="button" class="btn btn-primary" style="margin: auto">
|
||||||
<a style="color: white" href="#" onclick="javascript:window.history.back(-1);return false;">Zurück zur letzten Seite</a>
|
<a style="color: white" href="index.html">Zurück zur Hauptseite</a>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
<h3 style="color: dodgerblue; font-weight: bold;">
|
<h3 style="color: dodgerblue; font-weight: bold;">
|
||||||
<a th:href="@{/gruppen2/details(id=${gruppe.getId()})}" th:text="${gruppe.getTitle()}"></a>
|
<a th:href="@{/gruppen2/details(id=${gruppe.getId()})}" th:text="${gruppe.getTitle()}"></a>
|
||||||
</h3>
|
</h3>
|
||||||
<p th:text="${gruppe.getDescription()}"></p>
|
<p style="overflow-wrap: break-word" th:text="${#strings.abbreviate(gruppe.getDescription(),300)}"></p>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -48,7 +48,6 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Gruppenname</th>
|
<th scope="col">Gruppenname</th>
|
||||||
<th scope="col">Beschreibung</th>
|
<th scope="col">Beschreibung</th>
|
||||||
<th scope="col">Öffentlich/Privat</th>
|
|
||||||
<th scope="col">Mitgliederanzahl</th>
|
<th scope="col">Mitgliederanzahl</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -57,8 +56,7 @@
|
|||||||
<th scope="row">
|
<th scope="row">
|
||||||
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}" th:text="${gruppe.title}">Gruppenname</a>
|
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}" th:text="${gruppe.title}">Gruppenname</a>
|
||||||
</th>
|
</th>
|
||||||
<td th:text="${gruppe.getDescription()}">Beschreibung</td>
|
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">Beschreibung</td>
|
||||||
<td th:text="${gruppe.getVisibility()}">Öffentlich</td>
|
|
||||||
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user