refactor controllers
This commit is contained in:
@ -2,47 +2,11 @@ package mops.gruppen2;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Contact;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCaching
|
|
||||||
@EnableSwagger2
|
|
||||||
public class Gruppen2Application {
|
public class Gruppen2Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Gruppen2Application.class, args);
|
SpringApplication.run(Gruppen2Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket productAPI() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.select()
|
|
||||||
.paths(PathSelectors.ant("/gruppen2/api/**"))
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("mops.gruppen2"))
|
|
||||||
.build()
|
|
||||||
.apiInfo(apiMetadata());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiMetadata() {
|
|
||||||
return new ApiInfo(
|
|
||||||
"Gruppenbildung API",
|
|
||||||
"API zum anfragen/aktualisieren der Gruppendaten.",
|
|
||||||
"0.0.1",
|
|
||||||
"Free to use",
|
|
||||||
new Contact("gruppen2", "https://github.com/hhu-propra2/abschlussprojekt-it-bois", ""),
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
Collections.emptyList()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import lombok.extern.log4j.Log4j2;
|
|||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.api.GroupRequestWrapper;
|
import mops.gruppen2.domain.api.GroupRequestWrapper;
|
||||||
import mops.gruppen2.domain.exception.EventException;
|
|
||||||
import mops.gruppen2.service.APIService;
|
import mops.gruppen2.service.APIService;
|
||||||
import mops.gruppen2.service.EventStoreService;
|
import mops.gruppen2.service.EventStoreService;
|
||||||
import mops.gruppen2.service.IdService;
|
import mops.gruppen2.service.IdService;
|
||||||
@ -22,12 +21,11 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api zum Datenabgleich mit Gruppenfindung.
|
* Api zum Datenabgleich.
|
||||||
*/
|
*/
|
||||||
//TODO: API-Service?
|
@Log4j2
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/gruppen2/api")
|
@RequestMapping("/gruppen2/api")
|
||||||
@Log4j2
|
|
||||||
public class APIController {
|
public class APIController {
|
||||||
|
|
||||||
private final EventStoreService eventStoreService;
|
private final EventStoreService eventStoreService;
|
||||||
@ -38,31 +36,49 @@ public class APIController {
|
|||||||
this.projectionService = projectionService;
|
this.projectionService = projectionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/updateGroups/{lastEventId}")
|
/**
|
||||||
|
* Erzeugt eine Liste aus Gruppen, welche sich seit einer übergebenen Event-Id geändert haben.
|
||||||
|
* Die Gruppen werden vollständig projiziert, enthalten also alle Informationen zum entsprechenden Zeitpunkt.
|
||||||
|
*
|
||||||
|
* @param eventId Die Event-ID, welche der Anfragesteller beim letzten Aufruf erhalten hat
|
||||||
|
*/
|
||||||
|
@GetMapping("/update/{id}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich etwas geändert hat")
|
@ApiOperation("Gibt veränderte Gruppen zurück")
|
||||||
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers")
|
public GroupRequestWrapper update(@ApiParam("Letzte gespeicherte EventId des Anfragestellers")
|
||||||
@PathVariable long lastEventId) throws EventException {
|
@PathVariable("id") long eventId) {
|
||||||
log.info("ApiRequest to /updateGroups\n");
|
|
||||||
|
log.info("ApiRequest to /updateGroups (Event-ID: {})\n", eventId);
|
||||||
|
|
||||||
return APIService.wrap(eventStoreService.findMaxEventId(),
|
return APIService.wrap(eventStoreService.findMaxEventId(),
|
||||||
projectionService.projectNewGroups(lastEventId));
|
projectionService.projectNewGroups(eventId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGroupIdsOfUser/{userId}")
|
/**
|
||||||
|
* Gibt die Gruppen-IDs von Gruppen, in welchen der übergebene Nutzer teilnimmt, zurück.
|
||||||
|
*/
|
||||||
|
@GetMapping("/usergroups/{id}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
|
@ApiOperation("Gibt Gruppen zurück, in welchen ein Nutzer teilnimmt")
|
||||||
public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen")
|
public List<String> usergroups(@ApiParam("Nutzer-Id")
|
||||||
@PathVariable String userId) {
|
@PathVariable("id") String userId) {
|
||||||
log.info("ApiRequest to /getGroupIdsOfUser\n");
|
|
||||||
|
log.info("ApiRequest to /getGroupIdsOfUser (Nutzer-ID: {})\n", userId);
|
||||||
|
|
||||||
return IdService.uuidsToString(eventStoreService.findExistingUserGroups(new User(userId)));
|
return IdService.uuidsToString(eventStoreService.findExistingUserGroups(new User(userId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGroup/{groupId}")
|
/**
|
||||||
|
* Konstruiert eine einzelne, vollständige Gruppe.
|
||||||
|
*/
|
||||||
|
@GetMapping("/group/{id}")
|
||||||
@Secured("ROLE_api_user")
|
@Secured("ROLE_api_user")
|
||||||
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
|
||||||
public Group getGroupById(@ApiParam("GruppenId der gefordeten Gruppe")
|
public Group getGroupById(@ApiParam("Gruppen-Id der gefordeten Gruppe")
|
||||||
@PathVariable String groupId) throws EventException {
|
@PathVariable("id") String groupId) {
|
||||||
log.info("ApiRequest to /getGroup\n");
|
|
||||||
|
log.info("ApiRequest to /getGroup (Gruppen-ID: {})\n", groupId);
|
||||||
|
|
||||||
return projectionService.projectSingleGroup(UUID.fromString(groupId));
|
return projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import mops.gruppen2.domain.Account;
|
import mops.gruppen2.aspect.annotation.TraceMethodCalls;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
@ -9,7 +9,6 @@ import mops.gruppen2.service.CsvService;
|
|||||||
import mops.gruppen2.service.GroupService;
|
import mops.gruppen2.service.GroupService;
|
||||||
import mops.gruppen2.service.IdService;
|
import mops.gruppen2.service.IdService;
|
||||||
import mops.gruppen2.service.ProjectionService;
|
import mops.gruppen2.service.ProjectionService;
|
||||||
import mops.gruppen2.service.ValidationService;
|
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
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;
|
||||||
@ -29,10 +27,10 @@ import static mops.gruppen2.service.ControllerService.getUserLimit;
|
|||||||
import static mops.gruppen2.service.ControllerService.getVisibility;
|
import static mops.gruppen2.service.ControllerService.getVisibility;
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
@Controller
|
|
||||||
@SessionScope
|
|
||||||
@RequestMapping("/gruppen2")
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
@TraceMethodCalls
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/gruppen2")
|
||||||
public class GroupCreationController {
|
public class GroupCreationController {
|
||||||
|
|
||||||
private final GroupService groupService;
|
private final GroupService groupService;
|
||||||
@ -43,37 +41,31 @@ public class GroupCreationController {
|
|||||||
this.projectionService = projectionService;
|
this.projectionService = projectionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
//TODO: /create/orga
|
||||||
|
@RolesAllowed("ROLE_orga")
|
||||||
@GetMapping("/createOrga")
|
@GetMapping("/createOrga")
|
||||||
public String createGroupAsOrga(KeycloakAuthenticationToken token,
|
public String getCreateOrgaPage(Model model) {
|
||||||
Model model) {
|
|
||||||
|
|
||||||
log.info("GET to /createOrga\n");
|
|
||||||
|
|
||||||
model.addAttribute("account", new Account(token));
|
|
||||||
model.addAttribute("lectures", projectionService.projectLectures());
|
model.addAttribute("lectures", projectionService.projectLectures());
|
||||||
|
|
||||||
return "createOrga";
|
return "createOrga";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
//TODO: /create/orga
|
||||||
|
@RolesAllowed("ROLE_orga")
|
||||||
@PostMapping("/createOrga")
|
@PostMapping("/createOrga")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
public String postCreateOrga(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("title") String title,
|
@RequestParam("title") String title,
|
||||||
@RequestParam("description") String description,
|
@RequestParam("description") String description,
|
||||||
@RequestParam("visibility") boolean isPrivate,
|
@RequestParam("visibility") boolean isPrivate,
|
||||||
@RequestParam("lecture") boolean isLecture,
|
@RequestParam("lecture") boolean isLecture,
|
||||||
@RequestParam("maxInfiniteUsers") boolean isInfinite,
|
@RequestParam("maxInfiniteUsers") boolean isInfinite,
|
||||||
@RequestParam("userMaximum") long userLimit,
|
@RequestParam("userMaximum") long userLimit,
|
||||||
@RequestParam("parent") String parent,
|
@RequestParam("parent") String parent,
|
||||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||||
|
|
||||||
log.info("POST to /createOrga\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = groupService.createGroup(user,
|
Group group = groupService.createGroup(user,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
@ -87,37 +79,29 @@ public class GroupCreationController {
|
|||||||
return "redirect:/gruppen2/details/" + IdService.uuidToString(group.getId());
|
return "redirect:/gruppen2/details/" + IdService.uuidToString(group.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: /create/student
|
||||||
@RolesAllowed("ROLE_studentin")
|
@RolesAllowed("ROLE_studentin")
|
||||||
@GetMapping("/createStudent")
|
@GetMapping("/createStudent")
|
||||||
public String createGroupAsStudent(KeycloakAuthenticationToken token,
|
public String getCreateStudentPage(Model model) {
|
||||||
Model model) {
|
|
||||||
|
|
||||||
log.info("GET to /createStudent\n");
|
|
||||||
|
|
||||||
model.addAttribute("account", new Account(token));
|
|
||||||
model.addAttribute("lectures", projectionService.projectLectures());
|
model.addAttribute("lectures", projectionService.projectLectures());
|
||||||
|
|
||||||
return "createStudent";
|
return "createStudent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: /create/student
|
||||||
@RolesAllowed("ROLE_studentin")
|
@RolesAllowed("ROLE_studentin")
|
||||||
@PostMapping("/createStudent")
|
@PostMapping("/createStudent")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
|
public String postCreateStudent(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("title") String title,
|
@RequestParam("title") String title,
|
||||||
@RequestParam("description") String description,
|
@RequestParam("description") String description,
|
||||||
@RequestParam("visibility") boolean isPrivate,
|
@RequestParam("visibility") boolean isPrivate,
|
||||||
@RequestParam("maxInfiniteUsers") boolean isInfinite,
|
@RequestParam("maxInfiniteUsers") boolean isInfinite,
|
||||||
@RequestParam("userMaximum") long userLimit,
|
@RequestParam("userMaximum") long userLimit,
|
||||||
@RequestParam("parent") String parent) {
|
@RequestParam("parent") String parent) {
|
||||||
|
|
||||||
log.info("POST to /createStudent\n");
|
User user = new User(token);
|
||||||
|
|
||||||
ValidationService.validateTitle(title);
|
|
||||||
ValidationService.validateDescription(description);
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
Group group = groupService.createGroup(user,
|
Group group = groupService.createGroup(user,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import mops.gruppen2.domain.Account;
|
import mops.gruppen2.aspect.annotation.TraceMethodCalls;
|
||||||
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.service.CsvService;
|
import mops.gruppen2.service.CsvService;
|
||||||
import mops.gruppen2.service.GroupService;
|
import mops.gruppen2.service.GroupService;
|
||||||
import mops.gruppen2.service.IdService;
|
import mops.gruppen2.service.IdService;
|
||||||
@ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
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;
|
||||||
@ -29,10 +26,10 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
@Controller
|
|
||||||
@SessionScope
|
|
||||||
@RequestMapping("/gruppen2")
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
@TraceMethodCalls
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/gruppen2")
|
||||||
public class GroupDetailsController {
|
public class GroupDetailsController {
|
||||||
|
|
||||||
private final InviteService inviteService;
|
private final InviteService inviteService;
|
||||||
@ -45,132 +42,179 @@ public class GroupDetailsController {
|
|||||||
this.projectionService = projectionService;
|
this.projectionService = projectionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/details/{id}")
|
@GetMapping("/details/{id}")
|
||||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
public String getDetailsPage(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
|
|
||||||
log.info("GET to /details\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
model.addAttribute("group", group);
|
|
||||||
|
|
||||||
// Parent Badge
|
// Parent Badge
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
Group parent = projectionService.projectParent(parentId);
|
Group parent = projectionService.projectParent(parentId);
|
||||||
|
|
||||||
// Detailseite für private Gruppen
|
// Invite Link
|
||||||
if (!ValidationService.checkIfGroupAccess(group, user)) {
|
String actualURL = request.getRequestURL().toString();
|
||||||
return "detailsNoMember";
|
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||||
}
|
String link = serverURL + "gruppen2/join/" + inviteService.getLinkByGroup(group);
|
||||||
|
|
||||||
model.addAttribute("roles", group.getRoles());
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("user", user);
|
|
||||||
model.addAttribute("admin", Role.ADMIN);
|
|
||||||
model.addAttribute("public", Visibility.PUBLIC);
|
|
||||||
model.addAttribute("private", Visibility.PRIVATE);
|
|
||||||
model.addAttribute("parent", parent);
|
model.addAttribute("parent", parent);
|
||||||
|
model.addAttribute("link", link);
|
||||||
|
|
||||||
// Invitelink Anzeige für Admins
|
// Detailseite für nicht-Mitglieder
|
||||||
if (ValidationService.checkIfAdmin(group, user)) {
|
if (!ValidationService.checkIfMember(group, user)) {
|
||||||
String actualURL = request.getRequestURL().toString();
|
return "detailsNoMember";
|
||||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
|
||||||
|
|
||||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroup(group));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "detailsMember";
|
return "detailsMember";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}/join
|
||||||
@GetMapping("/details/changeMetadata/{id}")
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
public String changeMetadata(KeycloakAuthenticationToken token,
|
@PostMapping("/join")
|
||||||
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
|
public String postDetailsJoin(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("id") String groupId) {
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
|
|
||||||
|
groupService.addUser(user, group);
|
||||||
|
|
||||||
|
return "redirect:/gruppen2/details/" + groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: /details/{id}/leave
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/leave")
|
||||||
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
|
public String postDetailsLeave(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("group_id") String groupId) {
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
|
|
||||||
|
groupService.deleteUser(user, group);
|
||||||
|
|
||||||
|
return "redirect:/gruppen2";
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: /details/{id}/destroy
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
|
public String postDetailsDestroy(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("group_id") String groupId) {
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
|
|
||||||
|
groupService.deleteGroup(user, group);
|
||||||
|
|
||||||
|
return "redirect:/gruppen2";
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: /details/{id}/meta
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@GetMapping("/details/meta/{id}")
|
||||||
|
public String getDetailsMeta(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
|
|
||||||
log.info("GET to /details/changeMetadata\n");
|
User user = new User(token);
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
ValidationService.throwIfNoAdmin(group, user);
|
ValidationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("group", group);
|
||||||
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";
|
return "changeMetadata";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}/meta/update
|
||||||
@PostMapping("/details/changeMetadata")
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/details/meta")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String postChangeMetadata(KeycloakAuthenticationToken token,
|
public String postDetailsMetaUpdate(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("title") String title,
|
@RequestParam("title") String title,
|
||||||
@RequestParam("description") String description,
|
@RequestParam("description") String description,
|
||||||
@RequestParam("groupId") String groupId) {
|
@RequestParam("groupId") String groupId) {
|
||||||
|
|
||||||
log.info("POST to /details/changeMetadata\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
ValidationService.throwIfNoAdmin(group, user);
|
|
||||||
groupService.updateTitle(user, group, title);
|
groupService.updateTitle(user, group, title);
|
||||||
groupService.updateDescription(user, group, description);
|
groupService.updateDescription(user, group, description);
|
||||||
|
|
||||||
return "redirect:/gruppen2/details/" + groupId;
|
return "redirect:/gruppen2/details/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}/members
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/details/members/{id}")
|
@GetMapping("/details/members/{id}")
|
||||||
public String editMembers(KeycloakAuthenticationToken token,
|
public String getDetailsMembers(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
|
|
||||||
log.info("GET to /details/members\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
ValidationService.throwIfNoAdmin(group, user);
|
ValidationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
model.addAttribute("members", group.getMembers());
|
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("admin", Role.ADMIN);
|
|
||||||
|
|
||||||
return "editMembers";
|
return "editMembers";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}/members/update/userlimit
|
||||||
@PostMapping("/details/members/changeRole")
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/details/members/setuserlimit")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String changeRole(KeycloakAuthenticationToken token,
|
public String postDetailsMembersUpdateUserLimit(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("group_id") String groupId,
|
@RequestParam("maximum") long userLimit,
|
||||||
@RequestParam("user_id") String userId) {
|
@RequestParam("group_id") String groupId) {
|
||||||
|
|
||||||
log.info("POST to /details/members/changeRole\n");
|
User user = new User(token);
|
||||||
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
|
|
||||||
Account account = new Account(token);
|
groupService.updateUserLimit(user, group, userLimit);
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: /details/{id}/members/update/csv
|
||||||
|
@RolesAllowed("ROLE_orga")
|
||||||
|
@PostMapping("/details/members/csv")
|
||||||
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
|
public String postDetailsMembersUpdateCsv(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("group_id") String groupId,
|
||||||
|
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
|
Group group = projectionService.projectSingleGroup(IdService.stringToUUID(groupId));
|
||||||
|
|
||||||
|
groupService.addUsersToGroup(CsvService.readCsvFile(file), group, user);
|
||||||
|
|
||||||
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Method + view for /details/{id}/members/{id}
|
||||||
|
|
||||||
|
//TODO: /details/{id}/members/{id}/update/role
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/details/members/togglerole")
|
||||||
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
|
public String postDetailsMembersUpdateRole(KeycloakAuthenticationToken token,
|
||||||
|
@RequestParam("group_id") String groupId,
|
||||||
|
@RequestParam("user_id") String userId) {
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
ValidationService.throwIfNoAdmin(group, user);
|
ValidationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
groupService.toggleMemberRole(new User(userId), group);
|
groupService.toggleMemberRole(new User(userId), group);
|
||||||
|
|
||||||
// Falls sich der User selbst die Rechte genommen hat
|
// Falls sich der User selbst die Rechte genommen hat
|
||||||
@ -181,114 +225,22 @@ public class GroupDetailsController {
|
|||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /details/{id}/members/{id}/delete
|
||||||
@PostMapping("/details/members/changeMaximum")
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
|
@PostMapping("/details/members/deleteuser")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String changeMaxSize(KeycloakAuthenticationToken token,
|
public String postDetailsMembersDelete(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("maximum") long userLimit,
|
@RequestParam("group_id") String groupId,
|
||||||
@RequestParam("group_id") String groupId) {
|
@RequestParam("user_id") String userId) {
|
||||||
|
|
||||||
log.info("POST to /details/members/changeMaximum\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
||||||
groupService.updateUserLimit(user, group, userLimit);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@PostMapping("/details/members/deleteUser")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String deleteUser(KeycloakAuthenticationToken token,
|
|
||||||
@RequestParam("group_id") String groupId,
|
|
||||||
@RequestParam("user_id") String userId) {
|
|
||||||
|
|
||||||
log.info("POST to /details/members/deleteUser\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
// Der eingeloggte User kann sich nicht selbst entfernen
|
// Der eingeloggte User kann sich nicht selbst entfernen
|
||||||
if (!userId.equals(user.getId())) {
|
if (!userId.equals(user.getId())) {
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
groupService.deleteUser(new User(userId), group);
|
groupService.deleteUser(new User(userId), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@PostMapping("/detailsBeitreten")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String joinGroup(KeycloakAuthenticationToken token,
|
|
||||||
Model model,
|
|
||||||
@RequestParam("id") String groupId) {
|
|
||||||
|
|
||||||
log.info("POST to /detailsBeitreten\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
groupService.addUser(user, group);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@PostMapping("/leaveGroup")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String leaveGroup(KeycloakAuthenticationToken token,
|
|
||||||
@RequestParam("group_id") String groupId) {
|
|
||||||
|
|
||||||
log.info("POST to /leaveGroup\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
groupService.deleteUser(user, group);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@PostMapping("/deleteGroup")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String deleteGroup(KeycloakAuthenticationToken token,
|
|
||||||
@RequestParam("group_id") String groupId) {
|
|
||||||
|
|
||||||
log.info("POST to /deleteGroup\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
groupService.deleteGroup(user, group);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator"})
|
|
||||||
@PostMapping("/details/members/addUsersFromCsv")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
|
||||||
@RequestParam("group_id") String groupId,
|
|
||||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
|
||||||
|
|
||||||
log.info("POST to /details/members/addUsersFromCsv\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(IdService.stringToUUID(groupId));
|
|
||||||
groupService.addUsersToGroup(CsvService.readCsvFile(file), group, user);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import mops.gruppen2.domain.Account;
|
import mops.gruppen2.aspect.annotation.TraceMethodCall;
|
||||||
import mops.gruppen2.domain.GroupType;
|
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||||
import mops.gruppen2.service.ProjectionService;
|
import mops.gruppen2.service.ProjectionService;
|
||||||
@ -16,8 +15,8 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
@Controller
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
@Controller
|
||||||
public class GruppenfindungController {
|
public class GruppenfindungController {
|
||||||
|
|
||||||
private final ProjectionService projectionService;
|
private final ProjectionService projectionService;
|
||||||
@ -26,25 +25,21 @@ public class GruppenfindungController {
|
|||||||
this.projectionService = projectionService;
|
this.projectionService = projectionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For convenience
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public String redirect() {
|
public String redirect() {
|
||||||
return "redirect:/gruppen2";
|
return "redirect:/gruppen2";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
@TraceMethodCall
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/gruppen2")
|
@GetMapping("/gruppen2")
|
||||||
public String index(KeycloakAuthenticationToken token,
|
public String getIndexPage(KeycloakAuthenticationToken token,
|
||||||
Model model) {
|
Model model) {
|
||||||
|
|
||||||
log.info("GET to /gruppen2\n");
|
User user = new User(token);
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
model.addAttribute("gruppen", projectionService.projectUserGroups(user));
|
model.addAttribute("gruppen", projectionService.projectUserGroups(user));
|
||||||
model.addAttribute("user", user);
|
|
||||||
model.addAttribute("lecture", GroupType.LECTURE);
|
|
||||||
|
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,131 +1,77 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import mops.gruppen2.domain.Account;
|
import mops.gruppen2.aspect.annotation.TraceMethodCalls;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.service.GroupService;
|
|
||||||
import mops.gruppen2.service.InviteService;
|
import mops.gruppen2.service.InviteService;
|
||||||
import mops.gruppen2.service.ProjectionService;
|
import mops.gruppen2.service.ProjectionService;
|
||||||
import mops.gruppen2.service.SearchService;
|
import mops.gruppen2.service.SearchService;
|
||||||
import mops.gruppen2.service.ValidationService;
|
import mops.gruppen2.service.ValidationService;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.context.annotation.SessionScope;
|
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
@Controller
|
|
||||||
@SessionScope
|
|
||||||
@RequestMapping("/gruppen2")
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
@TraceMethodCalls
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/gruppen2")
|
||||||
public class SearchAndInviteController {
|
public class SearchAndInviteController {
|
||||||
|
|
||||||
private final InviteService inviteService;
|
private final InviteService inviteService;
|
||||||
private final GroupService groupService;
|
|
||||||
private final ProjectionService projectionService;
|
private final ProjectionService projectionService;
|
||||||
private final SearchService searchService;
|
private final SearchService searchService;
|
||||||
|
|
||||||
public SearchAndInviteController(InviteService inviteService, GroupService groupService, ProjectionService projectionService, SearchService searchService) {
|
public SearchAndInviteController(InviteService inviteService, ProjectionService projectionService, SearchService searchService) {
|
||||||
this.inviteService = inviteService;
|
this.inviteService = inviteService;
|
||||||
this.groupService = groupService;
|
|
||||||
this.projectionService = projectionService;
|
this.projectionService = projectionService;
|
||||||
this.searchService = searchService;
|
this.searchService = searchService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /search
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/searchPage")
|
@GetMapping("/searchPage")
|
||||||
public String findGroup(KeycloakAuthenticationToken token,
|
public String getSearchPage(Model model) {
|
||||||
Model model) {
|
// Noch keine Suche gestartet: leeres Suchergebnis
|
||||||
|
model.addAttribute("gruppen", Collections.emptyList());
|
||||||
log.info("GET to /searchPage\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
model.addAttribute("gruppen", Collections.emptyList()); // TODO: verschönern
|
|
||||||
model.addAttribute("inviteService", inviteService); //TODO: don't inject service
|
|
||||||
|
|
||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
//TODO: /search/{string}
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/search")
|
@GetMapping("/search")
|
||||||
public String search(KeycloakAuthenticationToken token,
|
public String getSearch(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@RequestParam("suchbegriff") String search) {
|
@RequestParam("suchbegriff") String search) {
|
||||||
|
|
||||||
log.info("GET to /search\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
List<Group> groups = searchService.searchPublicGroups(search, user);
|
List<Group> groups = searchService.searchPublicGroups(search, user);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
model.addAttribute("gruppen", groups);
|
model.addAttribute("gruppen", groups);
|
||||||
model.addAttribute("inviteService", inviteService); //TODO: don't inject service
|
|
||||||
|
|
||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin"})
|
||||||
@GetMapping("/detailsSearch")
|
@GetMapping("/join/{link}")
|
||||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
public String getJoin(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@RequestParam("id") String groupId) {
|
@PathVariable("link") String link) {
|
||||||
|
|
||||||
log.info("GET to /detailsSearch\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
|
|
||||||
// Parent Badge
|
|
||||||
UUID parentId = group.getParent();
|
|
||||||
Group parent = projectionService.projectParent(parentId);
|
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
if (ValidationService.checkIfMember(group, user)) {
|
|
||||||
return "redirect:/gruppen2/details/" + groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("group", group);
|
|
||||||
model.addAttribute("parentId", parentId);
|
|
||||||
model.addAttribute("parent", parent);
|
|
||||||
model.addAttribute("lecture", GroupType.LECTURE);
|
|
||||||
|
|
||||||
return "detailsNoMember";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@GetMapping("/acceptinvite/{link}")
|
|
||||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
|
||||||
Model model,
|
|
||||||
@PathVariable("link") String link) {
|
|
||||||
|
|
||||||
log.info("GET to /acceptInvite\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
|
|
||||||
|
User user = new User(token);
|
||||||
Group group = projectionService.projectSingleGroup(inviteService.getGroupIdFromLink(link));
|
Group group = projectionService.projectSingleGroup(inviteService.getGroupIdFromLink(link));
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
|
|
||||||
// Gruppe öffentlich
|
// Gruppe öffentlich
|
||||||
@ -140,24 +86,4 @@ public class SearchAndInviteController {
|
|||||||
|
|
||||||
return "joinprivate";
|
return "joinprivate";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
|
||||||
@PostMapping("/acceptinvite")
|
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
|
||||||
public String postAcceptInvite(KeycloakAuthenticationToken token,
|
|
||||||
@RequestParam("id") String groupId) {
|
|
||||||
|
|
||||||
log.info("POST to /acceptInvite\n");
|
|
||||||
|
|
||||||
Account account = new Account(token);
|
|
||||||
User user = new User(account);
|
|
||||||
Group group = projectionService.projectSingleGroup(UUID.fromString(groupId));
|
|
||||||
|
|
||||||
ValidationService.throwIfMember(group, user);
|
|
||||||
ValidationService.throwIfGroupFull(group);
|
|
||||||
|
|
||||||
groupService.addUser(user, group);
|
|
||||||
|
|
||||||
return "redirect:/gruppen2/details/" + groupId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.keycloak.KeycloakPrincipal;
|
||||||
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -22,11 +24,12 @@ public class User {
|
|||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
public User(Account account) {
|
public User(KeycloakAuthenticationToken token) {
|
||||||
id = account.getName();
|
KeycloakPrincipal principal = (KeycloakPrincipal) token.getPrincipal();
|
||||||
givenname = account.getGivenname();
|
id = principal.getName();
|
||||||
familyname = account.getFamilyname();
|
givenname = principal.getKeycloakSecurityContext().getIdToken().getGivenName();
|
||||||
email = account.getEmail();
|
familyname = principal.getKeycloakSecurityContext().getIdToken().getFamilyName();
|
||||||
|
email = principal.getKeycloakSecurityContext().getIdToken().getEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -66,11 +66,6 @@ public final class ValidationService {
|
|||||||
.count() == 1;
|
.count() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkIfGroupAccess(Group group, User user) {
|
|
||||||
return (group.getVisibility() == Visibility.PRIVATE && checkIfMember(group, user))
|
|
||||||
|| group.getVisibility() == Visibility.PUBLIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ######################################## THROW ############################################
|
// ######################################## THROW ############################################
|
||||||
|
|
||||||
@ -112,16 +107,10 @@ public final class ValidationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void throwIfNoGroupAccess(Group group, User user) {
|
|
||||||
if (!checkIfGroupAccess(group, user)) {
|
|
||||||
log.error("Der User {} hat keinen Zugriff auf Gruppe {}!", user, group);
|
|
||||||
throw new NoAccessException(group.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ##################################### VALIDATE FIELDS #####################################
|
// ##################################### VALIDATE FIELDS #####################################
|
||||||
|
|
||||||
|
|
||||||
//TODO: max title length?
|
//TODO: max title length?
|
||||||
public static void validateTitle(String title) {
|
public static void validateTitle(String title) {
|
||||||
if (title == null || title.trim().isEmpty()) {
|
if (title == null || title.trim().isEmpty()) {
|
||||||
|
|||||||
@ -46,20 +46,20 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Titel</label>
|
<label for="title">Titel</label>
|
||||||
<input class="form-control" id="title" required
|
<input class="form-control" id="title" required
|
||||||
th:name="title" th:value="${title}" type="text">
|
th:name="title" th:value="${group.getTitle()}" type="text">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="description">Beschreibung</label>
|
<label for="description">Beschreibung</label>
|
||||||
<textarea class="form-control" id="description" required rows="3"
|
<textarea class="form-control" id="description" required rows="3"
|
||||||
th:name="description"
|
th:name="description"
|
||||||
th:text="${description}"></textarea>
|
th:text="${group.getDescription()}"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group pt-4">
|
<div class="form-group pt-4">
|
||||||
<button class="btn btn-primary"
|
<button class="btn btn-primary"
|
||||||
style="background: #52a1eb; border-style: none;"
|
style="background: #52a1eb; border-style: none;"
|
||||||
th:if="${roles.get(user.getId()) == admin}"
|
th:if="${group.getRoles().get(user.getId()) == admin}"
|
||||||
th:name="groupId"
|
th:name="groupId"
|
||||||
th:value="${groupId}"
|
th:value="${group.getId()}"
|
||||||
type="submit">Speichern
|
type="submit">Speichern
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
<a class="fa fa-pencil"
|
<a class="fa fa-pencil"
|
||||||
style="font-size:30px; width: 5%;"
|
style="font-size:30px; width: 5%;"
|
||||||
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
|
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
|
||||||
th:if="${roles.get(user.getId()) == admin}"></a>
|
th:if="${group.getRoles().get(user.getId()) == admin}"></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3>
|
<h3>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
th:text="${parent?.getTitle()}">Parent</span>
|
th:text="${parent?.getTitle()}">Parent</span>
|
||||||
|
|
||||||
<div class="input-group mb-3" style="margin-top: 10px;"
|
<div class="input-group mb-3" style="margin-top: 10px;"
|
||||||
th:if="${roles.get(user.getId()) == admin}">
|
th:if="${group.getRoles().get(user.getId()) == admin}">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" id="inputGroup-sizing-default"
|
<span class="input-group-text" id="inputGroup-sizing-default"
|
||||||
style="background: #52a1eb;">Einladungslink:</span>
|
style="background: #52a1eb;">Einladungslink:</span>
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
<div class="form-group mt-2" th:if="${group.getMembers().size() < group.getUserLimit()}">
|
<div class="form-group mt-2" th:if="${group.getMembers().size() < group.getUserLimit()}">
|
||||||
<h3>Möchtest du dieser privaten Gruppe beitreten?</h3>
|
<h3>Möchtest du dieser privaten Gruppe beitreten?</h3>
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<form method="post" th:action="@{/gruppen2/acceptinvite}">
|
<form method="post" th:action="@{/gruppen2/join}">
|
||||||
<input name="id" th:value="${group.getId()}" type="hidden"/>
|
<input name="id" th:value="${group.getId()}" type="hidden"/>
|
||||||
<button class="btn btn-primary"
|
<button class="btn btn-primary"
|
||||||
style="background: #52a1eb; border-style: none;"
|
style="background: #52a1eb; border-style: none;"
|
||||||
|
|||||||
@ -53,9 +53,9 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<table class="table">
|
<table class="table" th:if='${!gruppen.isEmpty()}'>
|
||||||
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
||||||
<thead th:if='${!gruppen.isEmpty()}'>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Gruppenname</th>
|
<th scope="col">Gruppenname</th>
|
||||||
<th scope="col">Beschreibung</th>
|
<th scope="col">Beschreibung</th>
|
||||||
@ -67,8 +67,8 @@
|
|||||||
<th scope="row">
|
<th scope="row">
|
||||||
<span class="badge badge-pill badge-success"
|
<span class="badge badge-pill badge-success"
|
||||||
style="background: lightseagreen; margin-right: 25px;"
|
style="background: lightseagreen; margin-right: 25px;"
|
||||||
th:if='${gruppe.getType() == gruppe.getType().LECTURE}'>Veranstaltung</span>
|
th:if='${gruppe.getType() == lecture}'>Veranstaltung</span>
|
||||||
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}"
|
<a th:href="@{/gruppen2/details/{id}(id=${gruppe.getId()})}"
|
||||||
th:text="${#strings.abbreviate(gruppe.getTitle(), 50)}">Gruppenname</a>
|
th:text="${#strings.abbreviate(gruppe.getTitle(), 50)}">Gruppenname</a>
|
||||||
</th>
|
</th>
|
||||||
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
||||||
|
|||||||
@ -53,10 +53,10 @@ class APIControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "api_user", roles = "api_user")
|
@WithMockUser(username = "api_user", roles = "api_user")
|
||||||
void updateGroup_noGroup() {
|
void updateGroup_noGroup() {
|
||||||
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(0);
|
assertThat(apiController.update(0L).getGroupList()).hasSize(0);
|
||||||
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(0);
|
assertThat(apiController.update(4L).getGroupList()).hasSize(0);
|
||||||
assertThat(apiController.updateGroups(10L).getGroupList()).hasSize(0);
|
assertThat(apiController.update(10L).getGroupList()).hasSize(0);
|
||||||
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(0);
|
assertThat(apiController.update(0L).getStatus()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -69,10 +69,10 @@ class APIControllerTest {
|
|||||||
addUserEvent(uuidMock(0)),
|
addUserEvent(uuidMock(0)),
|
||||||
addUserEvent(uuidMock(0)));
|
addUserEvent(uuidMock(0)));
|
||||||
|
|
||||||
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(1);
|
assertThat(apiController.update(0L).getGroupList()).hasSize(1);
|
||||||
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
|
assertThat(apiController.update(4L).getGroupList()).hasSize(1);
|
||||||
assertThat(apiController.updateGroups(10L).getGroupList()).hasSize(0);
|
assertThat(apiController.update(10L).getGroupList()).hasSize(0);
|
||||||
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(6);
|
assertThat(apiController.update(0L).getStatus()).isEqualTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,17 +89,17 @@ class APIControllerTest {
|
|||||||
addUserEvent(uuidMock(1)),
|
addUserEvent(uuidMock(1)),
|
||||||
addUserEvent(uuidMock(1)));
|
addUserEvent(uuidMock(1)));
|
||||||
|
|
||||||
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(2);
|
assertThat(apiController.update(0L).getGroupList()).hasSize(2);
|
||||||
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
|
assertThat(apiController.update(4L).getGroupList()).hasSize(1);
|
||||||
assertThat(apiController.updateGroups(6L).getGroupList()).hasSize(1);
|
assertThat(apiController.update(6L).getGroupList()).hasSize(1);
|
||||||
assertThat(apiController.updateGroups(7L).getGroupList()).hasSize(1);
|
assertThat(apiController.update(7L).getGroupList()).hasSize(1);
|
||||||
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(9);
|
assertThat(apiController.update(0L).getStatus()).isEqualTo(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "api_user", roles = "api_user")
|
@WithMockUser(username = "api_user", roles = "api_user")
|
||||||
void getGroupsOfUser_noGroup() {
|
void getGroupsOfUser_noGroup() {
|
||||||
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
|
assertThat(apiController.usergroups("A")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -110,7 +110,7 @@ class APIControllerTest {
|
|||||||
createPrivateGroupEvent(uuidMock(2)),
|
createPrivateGroupEvent(uuidMock(2)),
|
||||||
addUserEvent(uuidMock(0), "A"));
|
addUserEvent(uuidMock(0), "A"));
|
||||||
|
|
||||||
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(1);
|
assertThat(apiController.usergroups("A")).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -120,7 +120,7 @@ class APIControllerTest {
|
|||||||
addUserEvent(uuidMock(0), "A"),
|
addUserEvent(uuidMock(0), "A"),
|
||||||
deleteUserEvent(uuidMock(0), "A"));
|
deleteUserEvent(uuidMock(0), "A"));
|
||||||
|
|
||||||
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
|
assertThat(apiController.usergroups("A")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
@Disabled
|
||||||
@ -131,7 +131,7 @@ class APIControllerTest {
|
|||||||
addUserEvent(uuidMock(0), "A"),
|
addUserEvent(uuidMock(0), "A"),
|
||||||
deleteGroupEvent(uuidMock(0)));
|
deleteGroupEvent(uuidMock(0)));
|
||||||
|
|
||||||
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
|
assertThat(apiController.usergroups("A")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -146,8 +146,8 @@ class APIControllerTest {
|
|||||||
addUserEvent(uuidMock(2), "A"),
|
addUserEvent(uuidMock(2), "A"),
|
||||||
addUserEvent(uuidMock(2), "B"));
|
addUserEvent(uuidMock(2), "B"));
|
||||||
|
|
||||||
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(3);
|
assertThat(apiController.usergroups("A")).hasSize(3);
|
||||||
assertThat(apiController.getGroupIdsOfUser("B")).hasSize(2);
|
assertThat(apiController.usergroups("B")).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user