Merge branch 'master' into killertester
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package mops.gruppen2.controller;
|
||||
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@ -17,10 +19,10 @@ public class MopsController {
|
||||
public String logout(HttpServletRequest request) throws Exception {
|
||||
request.logout();
|
||||
return "redirect:/gruppen2/";
|
||||
}/*
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() {
|
||||
return "error";
|
||||
}*/
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
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.Visibility;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupFullException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import mops.gruppen2.domain.exception.NoAccessException;
|
||||
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
@ -17,8 +20,6 @@ import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -30,6 +31,7 @@ import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.CharConversionException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -39,22 +41,18 @@ import java.util.UUID;
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
public class Gruppen2Controller {
|
||||
public class WebController {
|
||||
|
||||
private final KeyCloakService keyCloakService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final Gruppen2Config gruppen2Config;
|
||||
private final Logger logger = LoggerFactory.getLogger("Gruppen2ControllerLogger");
|
||||
;
|
||||
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, Gruppen2Config gruppen2Config) {
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.gruppen2Config = gruppen2Config;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,29 +95,8 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<User> userList = new ArrayList<>();
|
||||
if (userMaximum == null) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
userList = CsvService.read(file.getInputStream());
|
||||
if (userList.size() > userMaximum) {
|
||||
userMaximum = (long) userList.size() + userMaximum;
|
||||
}
|
||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||
logger.warn("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
|
||||
controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, userList);
|
||||
|
||||
controllerService.createOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -143,11 +120,8 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "parent", required = false) String parent) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
visibility = visibility == null;
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
UUID parentUUID = controllerService.getUUID(parent);
|
||||
controllerService.createGroup(account, title, description, visibility, maxInfiniteUsers, userMaximum, parentUUID);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -171,32 +145,73 @@ public class Gruppen2Controller {
|
||||
}
|
||||
|
||||
UUID groupUUID = controllerService.getUUID(groupId);
|
||||
|
||||
controllerService.addUserList(userList, groupUUID);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/details/changeMetadata/{id}")
|
||||
public String changeMetadata(KeycloakAuthenticationToken token, Model model, @PathVariable("id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
model.addAttribute("account", account);
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
if (!group.getMembers().contains(user)) {
|
||||
if (group.getVisibility() == Visibility.PRIVATE) {
|
||||
throw new NoAccessException("Die Gruppe ist privat");
|
||||
}
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
model.addAttribute("title", group.getTitle());
|
||||
model.addAttribute("description", group.getDescription());
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("groupId", group.getId());
|
||||
model.addAttribute("user", user);
|
||||
return "changeMetadata";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/changeMetadata")
|
||||
public String pChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("groupId") String groupId) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
controllerService.updateTitle(account, UUID.fromString(groupId), title);
|
||||
controllerService.updateDescription(account, UUID.fromString(groupId), description);
|
||||
|
||||
return "redirect:/gruppen2/details/" + groupId;
|
||||
}
|
||||
|
||||
@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 {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groupse = new ArrayList<>();
|
||||
|
||||
List<Group> groups = new ArrayList<>();
|
||||
if (search != null) {
|
||||
groupse = groupService.findGroupWith(search, account);
|
||||
groups = groupService.findGroupWith(search, account);
|
||||
}
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("gruppen", groupse);
|
||||
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token,
|
||||
Model model,
|
||||
@PathVariable("id") String groupId) throws EventException {
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @PathVariable("id") String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
@ -205,12 +220,12 @@ public class Gruppen2Controller {
|
||||
Group parent = new Group();
|
||||
|
||||
if (group.getTitle() == null) {
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
throw new GroupNotFoundException("@details");
|
||||
}
|
||||
|
||||
if (!group.getMembers().contains(user)) {
|
||||
if (group.getVisibility() == Visibility.PRIVATE) {
|
||||
return "privateGroupNoMember";
|
||||
throw new NoAccessException("Die Gruppe ist privat");
|
||||
}
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
@ -228,6 +243,12 @@ public class Gruppen2Controller {
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("admin", Role.ADMIN);
|
||||
|
||||
String URL = request.getRequestURL().toString();
|
||||
String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
|
||||
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
||||
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@ -236,17 +257,17 @@ public class Gruppen2Controller {
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
model.addAttribute("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(UUID.fromString(groupId));
|
||||
if (group.getMembers().contains(user)) {
|
||||
return "error"; //TODO: hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
||||
}
|
||||
if (group.getUserMaximum() < group.getMembers().size()) {
|
||||
return "error";
|
||||
throw new UserAlreadyExistsException("Du bist bereits in dieser Gruppe.");
|
||||
}
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
if (group.getUserMaximum() < group.getMembers().size()) {
|
||||
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
|
||||
}
|
||||
//controllerService.addUser(account, groupId);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -260,7 +281,7 @@ public class Gruppen2Controller {
|
||||
UUID parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
|
||||
if (parentId != null) {
|
||||
if (!controllerService.idIsEmpty(parentId)) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
|
||||
@ -271,11 +292,11 @@ public class Gruppen2Controller {
|
||||
|
||||
return "detailsNoMember";
|
||||
}
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
throw new GroupNotFoundException("@search");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
@GetMapping("/acceptinvite/{groupId}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model, @PathVariable String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
@ -284,7 +305,7 @@ public class Gruppen2Controller {
|
||||
model.addAttribute("group", group);
|
||||
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
||||
}
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
throw new GroupNotFoundException("@accept");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@ -311,7 +332,7 @@ public class Gruppen2Controller {
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
|
||||
return "error";
|
||||
throw new NoAccessException("");
|
||||
}
|
||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||
return "redirect:/gruppen2/";
|
||||
@ -336,7 +357,7 @@ public class Gruppen2Controller {
|
||||
return "redirect:/details/";
|
||||
}
|
||||
} else {
|
||||
return "privateGroupNoMember";
|
||||
throw new NoAccessException("Die Gruppe ist privat");
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,8 +366,6 @@ public class Gruppen2Controller {
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
if (userId.equals(account.getName())) {
|
||||
if (controllerService.passIfLastAdmin(account, UUID.fromString(groupId))) {
|
||||
@ -379,4 +398,9 @@ public class Gruppen2Controller {
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class BadParameterException extends EventException {
|
||||
|
||||
public BadParameterException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
|
||||
public class GroupFullException extends EventException {
|
||||
|
||||
public GroupFullException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe ist voll.", info);
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe hat die maximale Midgliederanzahl bereits erreicht!", info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NoAccessException extends EventException {
|
||||
|
||||
public NoAccessException(String info) {
|
||||
super(HttpStatus.FORBIDDEN, "Hier hast du leider keinen Zugriff!", info);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class PageNotFoundException extends EventException {
|
||||
|
||||
public PageNotFoundException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Die Seite wurde nicht gefunden!", info);
|
||||
}
|
||||
}
|
||||
@ -32,4 +32,13 @@ public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("SELECT * FROM event WHERE event_type = :type")
|
||||
List<EventDTO> findAllEventsByType(@Param("type") String type);
|
||||
|
||||
@Query("SELECT * FROM event WHERE event_type = :type AND user_id = :userId")
|
||||
List<EventDTO> findEventsByTypeAndUserId(@Param("type") String type, @Param("userId") String userId);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM event WHERE event_type = :type AND group_id = :groupId")
|
||||
Long countEventsByTypeAndGroupId(@Param("type") String type, @Param("groupId") String groupId);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM event WHERE group_id = :groupId AND user_id = :userId AND event_type = :type")
|
||||
Long countEventsByGroupIdAndUserIdAndEventType(@Param("groupId") String groupId, @Param("userId") String userId, @Param("type") String type);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Role;
|
||||
@ -14,10 +15,15 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.domain.exception.WrongFileException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.CharConversionException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -39,6 +45,26 @@ public class ControllerService {
|
||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||
* @param description
|
||||
* @param title
|
||||
* @param userMaximum
|
||||
*/
|
||||
private void checkFields(String description, String title, Long userMaximum ) {
|
||||
if(description == null) {
|
||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if(title == null) {
|
||||
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||
}
|
||||
|
||||
if (userMaximum == null) {
|
||||
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
|
||||
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
|
||||
@ -48,20 +74,27 @@ public class ControllerService {
|
||||
* @param title Gruppentitel
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean maxInfiniteUsers, Boolean visibility, Long userMaximum, UUID parent) throws EventException {
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility, Boolean maxInfiniteUsers, Long userMaximum, UUID parent) throws EventException {
|
||||
Visibility visibility1;
|
||||
UUID groupId = UUID.randomUUID();
|
||||
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
|
||||
|
||||
if(maxInfiniteUsers) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
checkFields(description, title, userMaximum);
|
||||
|
||||
visibility = visibility == null;
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
if(maxInfiniteUsers){
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, GroupType.SIMPLE, visibility1, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
@ -71,10 +104,30 @@ public class ControllerService {
|
||||
updateRole(account.getName(), groupId);
|
||||
}
|
||||
|
||||
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent, List<User> users) throws EventException {
|
||||
Visibility visibility1;
|
||||
UUID groupId = UUID.randomUUID();
|
||||
public void createOrga(Account account, String title, String description, Boolean visibility, Boolean lecture, Boolean maxInfiniteUsers, Long userMaximum, UUID parent, MultipartFile file) throws EventException, IOException {
|
||||
List<User> userList = new ArrayList<>();
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
if(maxInfiniteUsers) {
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
checkFields(description, title, userMaximum);
|
||||
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
userList = CsvService.read(file.getInputStream());
|
||||
if (userList.size() > userMaximum) {
|
||||
userMaximum = (long) userList.size() + userMaximum;
|
||||
}
|
||||
} catch (UnrecognizedPropertyException | CharConversionException ex) {
|
||||
logger.warning("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
Visibility visibility1;
|
||||
UUID groupId = eventService.checkGroup();
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
@ -88,11 +141,6 @@ public class ControllerService {
|
||||
groupType = GroupType.SIMPLE;
|
||||
}
|
||||
|
||||
|
||||
if(maxInfiniteUsers){
|
||||
userMaximum = 100000L;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, visibility1, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
@ -100,7 +148,7 @@ public class ControllerService {
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(account.getName(), groupId);
|
||||
addUserList(users, groupId);
|
||||
addUserList(userList, groupId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -117,11 +117,13 @@ public class EventService {
|
||||
|
||||
//TODO: Nur AddUserEvents betrachten
|
||||
public List<UUID> findGroupIdsByUser(String userId) {
|
||||
List<String> groupIDs = eventStore.findGroup_idsWhereUser_id(userId);
|
||||
|
||||
return groupIDs.stream()
|
||||
.map(UUID::fromString)
|
||||
.collect(Collectors.toList());
|
||||
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||
.map(UUID::fromString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean userInGroup(UUID groupId, String userId) {
|
||||
return eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "AddUserEvent")
|
||||
> eventStore.countEventsByGroupIdAndUserIdAndEventType(groupId.toString(), userId, "DeleteUserEvent");
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,34 +70,33 @@ public class GroupService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sucht alle Zeilen in der DB mit visibility=true.
|
||||
* Erstellt eine Liste aus öffentlichen Gruppen (ohen bereits beigetretenen Gruppen).
|
||||
* Wird verwendet bei der Suche nach Gruppen: Titel, Beschreibung werden benötigt.
|
||||
* Außerdem wird beachtet, ob der eingeloggte User bereits in entsprechenden Gruppen mitglied ist.
|
||||
*
|
||||
* @return Liste von projizierten Gruppen
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateUserMaxEvent")));
|
||||
|
||||
List<Group> visibleGroups = projectEventList(createEvents);
|
||||
|
||||
List<UUID> userGroupIds = eventService.findGroupIdsByUser(userId);
|
||||
List<Group> visibleGroups = projectEventList(groupEvents);
|
||||
|
||||
return visibleGroups.parallelStream()
|
||||
.filter(group -> group.getType() != null)
|
||||
.filter(group -> !userGroupIds.contains(group.getId()))
|
||||
.filter(group -> !eventService.userInGroup(group.getId(), userId))
|
||||
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
//TODO Rename
|
||||
|
||||
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
|
||||
|
||||
8
src/main/java/mops/gruppen2/service/SearchService.java
Normal file
8
src/main/java/mops/gruppen2/service/SearchService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SearchService {
|
||||
|
||||
}
|
||||
@ -5,7 +5,6 @@ import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -16,12 +15,10 @@ import java.util.UUID;
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final EventRepository eventRepository;
|
||||
private final GroupService groupService;
|
||||
private final EventService eventService;
|
||||
|
||||
public UserService(EventRepository eventRepository, GroupService groupService, EventService eventService) {
|
||||
this.eventRepository = eventRepository;
|
||||
public UserService(GroupService groupService, EventService eventService) {
|
||||
this.groupService = groupService;
|
||||
this.eventService = eventService;
|
||||
}
|
||||
@ -49,7 +46,7 @@ public class UserService {
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
return groupService.projectEventList(events).get(0);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
throw new GroupNotFoundException("@UserService");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,3 +18,4 @@ keycloak.use-resource-role-mappings=true
|
||||
keycloak.autodetect-bearer-only=true
|
||||
keycloak.confidential-port=443
|
||||
server.error.include-stacktrace=always
|
||||
server.port=8080
|
||||
|
||||
73
src/main/resources/templates/changeMetadata.html
Normal file
73
src/main/resources/templates/changeMetadata.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
|
||||
xmlns="http://www.w3.org/1999/html"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gruppenerstellung</title>
|
||||
<th:block th:fragment="headcontent">
|
||||
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
|
||||
rel="stylesheet">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
||||
</th:block>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation"
|
||||
th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li class="active">
|
||||
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
|
||||
</li>
|
||||
<li th:case="${true}">
|
||||
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
|
||||
</li>
|
||||
<li th:case="${false}">
|
||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Metadaten ändern</h1>
|
||||
<form action="/gruppen2/details/changeMetadata" method="post">
|
||||
<div class="shadow-sm p-2"
|
||||
style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<div class="form-group">
|
||||
<label for="title">Titel</label>
|
||||
<input class="form-control" id="title" required
|
||||
th:name="title" th:value="${title}" type="text">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Beschreibung</label>
|
||||
<textarea class="form-control" id="description" required rows="3"
|
||||
th:name="description"
|
||||
th:text="${description}"></textarea>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none"
|
||||
th:if="${roles.get(user.getId()) == admin}"
|
||||
th:name="groupId"
|
||||
th:value="${groupId}"
|
||||
type="submit">Speichern
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -6,7 +6,8 @@
|
||||
<meta charset="utf-8">
|
||||
<title>Gruppendetails</title>
|
||||
<th:block th:fragment="headcontent">
|
||||
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
|
||||
rel="stylesheet">
|
||||
</th:block>
|
||||
</head>
|
||||
<body>
|
||||
@ -31,8 +32,16 @@
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div>
|
||||
<div class="shadow-sm p-4 col-8" style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
|
||||
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word" th:text="${group.getTitle()}"></h1>
|
||||
<div class="shadow-sm p-4 col-8"
|
||||
style="border: 10px solid aliceblue; display: inline-block; border-radius: 5px; background: aliceblue">
|
||||
<div class="row">
|
||||
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word; width: 95%"
|
||||
th:text="${group.getTitle()}"></h1>
|
||||
<a class="fa fa-pencil"
|
||||
style="font-size:30px; width: 5%"
|
||||
th:href="@{/gruppen2/details/changeMetadata/{id}(id=${group.getId()})}"
|
||||
th:if="${roles.get(user.getId()) == admin}"></a>
|
||||
</div>
|
||||
<h3>
|
||||
<span class="badge badge-pill badge-dark" style="background: darkslategray"
|
||||
th:if='${group.getVisibility() == group.getVisibility().PRIVATE }'>Private Gruppe</span>
|
||||
@ -42,6 +51,23 @@
|
||||
th:if='${group.getType() == group.getType().LECTURE}'>Veranstaltung</span>
|
||||
<span class="badge badge-pill badge-info" style="background: mediumorchid"
|
||||
th:text="${parent.getTitle()}">Parent</span>
|
||||
|
||||
<div class="input-group mb-3" style="margin-top: 10px"
|
||||
th:if="${group.getVisibility() == group.getVisibility().PRIVATE}">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="inputGroup-sizing-default"
|
||||
style="background: #52a1eb">Einladungslink:</span>
|
||||
</div>
|
||||
<input aria-describedby="basic-addon2" aria-label="Recipient's username"
|
||||
class="form-control"
|
||||
id="groupLink" readonly style="background: white" th:value="${link}"
|
||||
type="text">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" onclick="copyLink()"
|
||||
type="button">Link kopieren
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
<br>
|
||||
<div class="shadow-sm p-4" style="background: white">
|
||||
@ -100,6 +126,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function copyLink() {
|
||||
var copyText = document.getElementById("groupLink");
|
||||
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 99999);
|
||||
|
||||
document.execCommand("copy");
|
||||
}
|
||||
</script>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation" th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li class="active">
|
||||
<li>
|
||||
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
|
||||
</li>
|
||||
<li th:case="${true}">
|
||||
@ -21,7 +21,7 @@
|
||||
<li th:case="${false}">
|
||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||
</li>
|
||||
<li>
|
||||
<li class="active">
|
||||
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
|
||||
</li>
|
||||
</ul>
|
||||
@ -53,8 +53,8 @@
|
||||
<form method="post" action="/gruppen2/detailsBeitreten">
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none;"
|
||||
th:href="@{/gruppen2/detailsBeitreten(id=${group.getId()})}"
|
||||
th:name="id" th:value="${group.id}"
|
||||
th:href="@{/gruppen2/detailsBeitreten}"
|
||||
th:name="id" th:value="${group.getId()}"
|
||||
type="submit">Gruppe beitreten
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@ -27,10 +27,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button style="color: #52a1eb">
|
||||
<a style="color: white" class="btn btn-primary btn-lg" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a>
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none;">
|
||||
<a href="#" onclick="window.history.back(-1);return false;" role="button"
|
||||
style="color: white">Zurück</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
|
||||
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet">
|
||||
<meta charset="UTF-8">
|
||||
<title>Seite nicht gefunden</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mx-auto" style="vertical-align: border-radius: 5px; center; horiz-align: center; top: 50%; left: 50%;">
|
||||
<div class="jumbotron" style="background: aliceblue">
|
||||
<div class="container">
|
||||
<h1 class="display-3">Kein Zugriff auf die Gruppe</h1>
|
||||
<p class="lead">Sorry, du hast keine Berechtigung auf diese Funktionen der Gruppe zuzugreifen</p><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<p><a class="btn btn-primary btn-lg" href="#" onclick="window.history.back(-1);return false;" role="button">Zurück</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -49,23 +49,26 @@
|
||||
<br>
|
||||
<table class="table">
|
||||
<!-- Erscheint dann, wenn man "Suchen" Button klickt und Ergebnisse angezeigt werden, aber so solls aussehen -->
|
||||
<thead th:if="${!gruppen.isEmpty()}">
|
||||
<thead th:if='${!gruppen.isEmpty()}'>
|
||||
<tr>
|
||||
<th scope="col">Gruppenname</th>
|
||||
<th scope="col">Beschreibung</th>
|
||||
<th scope="col">Mitgliederanzahl</th>
|
||||
<th scope="col">Max. Mitgliederanzahl</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody th:each="gruppe : ${gruppen}">
|
||||
<tr>
|
||||
<tbody>
|
||||
<tr th:each="gruppe : ${gruppen}" th:switch="${gruppe.getUserMaximum() != 100000}">
|
||||
<th scope="row">
|
||||
<a th:href="@{/gruppen2/detailsSearch(id=${gruppe.getId()})}"
|
||||
th:text="${gruppe.title}">Gruppenname</a>
|
||||
th:text="${gruppe.getTitle()}">Gruppenname</a>
|
||||
</th>
|
||||
<td style="" th:text="${#strings.abbreviate(gruppe.getDescription(), 50)}">
|
||||
Beschreibung
|
||||
</td>
|
||||
<td th:text="${gruppe.getMembers().size()}">Mitgliederanzahl</td>
|
||||
<td th:case="${true}">
|
||||
<a th:text="${gruppe.getUserMaximum()}"></a>
|
||||
</td>
|
||||
<td th:case="${false}">unbegrenzt</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user