Merge pull request #110 from hhu-propra2/merge-create-sites
Merge create sites
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
||||
import mops.gruppen2.config.Gruppen2Config;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
@ -25,8 +27,8 @@ 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 java.io.CharConversionException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -71,27 +73,57 @@ public class Gruppen2Controller {
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@GetMapping("/createLecture")
|
||||
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
||||
@GetMapping("/createOrga")
|
||||
public String createOrga(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "createLecture";
|
||||
return "createOrga";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createLecture")
|
||||
public String pCreateLecture(KeycloakAuthenticationToken token,
|
||||
@PostMapping("/createOrga")
|
||||
public String pCreateOrga(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("beschreibung") String beschreibung,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam(value = "lecture", required = false) Boolean lecture,
|
||||
@RequestParam("userMaximum") Long userMaximum,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<User> userList = new ArrayList<>();
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
userList = CsvService.read(file.getInputStream());
|
||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
visibility = visibility == null;
|
||||
controllerService.createLecture(account, title, beschreibung, visibility, userList);
|
||||
lecture = lecture == null;
|
||||
|
||||
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@GetMapping("/createStudent")
|
||||
public String createStudent(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "createStudent";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@PostMapping("/createStudent")
|
||||
public String pCreateStudent(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("userMaximum") Long userMaximum) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, description, visibility, userMaximum);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -102,19 +134,16 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
||||
List<User> userList = new ArrayList<>();
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
userList = CsvService.read(file.getInputStream());
|
||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
controllerService.addUserList(userList, groupId);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/createGroup")
|
||||
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "create";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
|
||||
@ -128,21 +157,6 @@ public class Gruppen2Controller {
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/createGroup")
|
||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("userMaximum") Long userMaximum) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, description, visibility, userMaximum);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException {
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class WrongFileException extends EventException {
|
||||
public WrongFileException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die entsprechende Datei ist keine valide CSV-Datei!", info);
|
||||
}
|
||||
}
|
||||
@ -66,6 +66,33 @@ public class ControllerService {
|
||||
updateRole(account.getName(), groupId);
|
||||
}
|
||||
|
||||
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Long maximmum, List<User> users) throws EventException {
|
||||
Visibility visibility1;
|
||||
Long groupId = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
GroupType groupType;
|
||||
if (lecture) {
|
||||
groupType = GroupType.SIMPLE;
|
||||
} else {
|
||||
groupType = GroupType.LECTURE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, groupType, visibility1, maximmum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(account.getName(), groupId);
|
||||
addUserList(users, groupId);
|
||||
}
|
||||
|
||||
private void createInviteLink(Long groupId) {
|
||||
inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID());
|
||||
}
|
||||
@ -137,26 +164,6 @@ public class ControllerService {
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException {
|
||||
Visibility visibility1;
|
||||
Long groupId = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1, 1000L); //this has to be changed also Usermaximum
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(account.getName(), groupId);
|
||||
addUserList(users, groupId);
|
||||
}
|
||||
|
||||
public boolean passIfLastAdmin(Account account, Long groupId){
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group.getMembers().size() <= 1){
|
||||
|
||||
@ -16,20 +16,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
<li th:case="${true}" class="active">
|
||||
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
|
||||
</li>
|
||||
<li th:case="${false}" class="active">
|
||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}" class="active">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
@ -37,20 +37,24 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Veranstaltung erstellen</h1>
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/gruppen2/createOrga" enctype="multipart/form-data">
|
||||
<div class="shadow p-2"
|
||||
style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<form action="/gruppen2/createLecture" enctype="multipart/form-data"
|
||||
method="post">
|
||||
<div class="form-group">
|
||||
<label for="titel">Titel</label>
|
||||
<input class="form-control" id="titel" required th:name="title"
|
||||
type="text">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="beschreibung">Beschreibung</label>
|
||||
<textarea class="form-control" id="beschreibung" required
|
||||
rows="3" th:name="beschreibung"></textarea>
|
||||
<label for="description">Beschreibung</label>
|
||||
<textarea class="form-control" id="description" required
|
||||
rows="3" th:name="description"></textarea>
|
||||
</div>
|
||||
<div class="form-group mt-3">
|
||||
<label for="userMaximum">Teilnehmeranzahl</label>
|
||||
<input class="form-control" id="userMaximum" required th:name="userMaximum"
|
||||
type="number" min="1">
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" id="visibility" th:name="visibility"
|
||||
@ -58,6 +62,22 @@
|
||||
<label class="custom-control-label" for="visibility">Private
|
||||
Gruppe</label>
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" id="lecture" th:name="lecture"
|
||||
type="checkbox">
|
||||
<label class="custom-control-label" for="lecture">Veranstaltung</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sel1"></label>
|
||||
<select class="form-control" id="sel1">
|
||||
<option disabled selected="true">--Bitte Veranstaltung auswählen--
|
||||
</option>
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@ -76,8 +96,8 @@
|
||||
type="submit">Erstellen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -11,20 +11,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
<li th:case="${true}" class="active">
|
||||
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
|
||||
</li>
|
||||
<li th:case="${false}" class="active">
|
||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
@ -33,7 +33,7 @@
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/gruppen2/createGroup">
|
||||
<form method="post" action="/gruppen2/createStudent">
|
||||
<div class="shadow p-2" style=" border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
|
||||
<div class="form-group">
|
||||
@ -11,20 +11,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li class="active">
|
||||
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/createGroup" th:href="@{/gruppen2/createGroup}">Erstellen</a>
|
||||
<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 href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a href="/createLecture" th:href="@{/gruppen2/createLecture}">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -10,20 +10,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<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>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
<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>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -15,20 +15,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<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>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
<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>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
@ -46,7 +46,6 @@
|
||||
</h5>
|
||||
</div>
|
||||
<div class="shadow p-2" style="border: 10px solid aliceblue; background: aliceblue">
|
||||
<!-- absichern im controller nicht vergessen -->
|
||||
<div class="form-group pt-4" th:if="${account.getRoles().contains('orga')}">
|
||||
<form action="/gruppen2/details/members/addUsersFromCsv"
|
||||
enctype="multipart/form-data"
|
||||
|
||||
@ -10,21 +10,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li class="active">
|
||||
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/createGroup" th:href="@{/gruppen2/createGroup}">Erstellen</a>
|
||||
<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 href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
|
||||
</li>
|
||||
<!-- Fix double point -->
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a href="/createLecture" th:href="@{/gruppen2/createLecture}">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@ -10,20 +10,20 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
|
||||
<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 class="active">
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
<li th:if="${account.getRoles().contains('orga')}">
|
||||
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user