Merge remote-tracking branch 'origin/master' into fix-group-search-number-of-users
# Conflicts: # src/main/java/mops/gruppen2/controller/WebController.java # src/main/resources/templates/detailsMember.html # src/main/resources/templates/search.html
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,15 +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.event.UpdateGroupTitleEvent;
|
||||
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;
|
||||
@ -18,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;
|
||||
@ -31,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;
|
||||
@ -40,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,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/";
|
||||
}
|
||||
|
||||
@ -172,7 +148,6 @@ public class Gruppen2Controller {
|
||||
}
|
||||
|
||||
UUID groupUUID = controllerService.getUUID(groupId);
|
||||
|
||||
controllerService.addUserList(userList, groupUUID);
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
@ -235,10 +210,9 @@ public class Gruppen2Controller {
|
||||
|
||||
@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());
|
||||
@ -247,7 +221,7 @@ 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)) {
|
||||
@ -270,6 +244,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";
|
||||
}
|
||||
|
||||
@ -278,17 +258,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/";
|
||||
}
|
||||
|
||||
@ -306,15 +286,18 @@ public class Gruppen2Controller {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
if (group.getUserMaximum() > group.getMembers().size()) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("parentId", parentId);
|
||||
model.addAttribute("parent", parent);
|
||||
|
||||
return "detailsNoMember";
|
||||
return "detailsNoMember";
|
||||
}
|
||||
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));
|
||||
@ -323,7 +306,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"})
|
||||
@ -350,7 +333,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/";
|
||||
@ -384,8 +367,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))) {
|
||||
@ -418,4 +399,9 @@ public class Gruppen2Controller {
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() throws EventException {
|
||||
throw new PageNotFoundException("\uD83D\uDE41");
|
||||
}
|
||||
}
|
||||
@ -32,14 +32,14 @@ public class AddUserEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) throws EventException {
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
User user = new User(this.userId, this.givenname, this.familyname, this.email);
|
||||
|
||||
if (group.getMembers().contains(user)) {
|
||||
throw new UserAlreadyExistsException(this.getClass().toString());
|
||||
}
|
||||
|
||||
if (group.getMembers().size() == group.getUserMaximum()){
|
||||
if (group.getMembers().size() == group.getUserMaximum()) {
|
||||
throw new GroupFullException(this.getClass().toString());
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ public class CreateGroupEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
protected void applyEvent(Group group) {
|
||||
group.setId(this.groupId);
|
||||
group.setParent(this.groupParent);
|
||||
group.setType(this.groupType);
|
||||
|
||||
@ -15,7 +15,7 @@ public class DeleteGroupEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
protected void applyEvent(Group group) {
|
||||
group.getRoles().clear();
|
||||
group.getMembers().clear();
|
||||
group.setTitle(null);
|
||||
|
||||
@ -21,7 +21,7 @@ public class DeleteUserEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) throws EventException {
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
for (User user : group.getMembers()) {
|
||||
if (user.getId().equals(this.userId)) {
|
||||
group.getMembers().remove(user);
|
||||
|
||||
@ -24,7 +24,7 @@ public class UpdateGroupDescriptionEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
protected void applyEvent(Group group) {
|
||||
if (this.newGroupDescription.isEmpty()) {
|
||||
throw new NoValueException(this.getClass().toString());
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class UpdateGroupTitleEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) {
|
||||
protected void applyEvent(Group group) {
|
||||
if (this.getNewGroupTitle().isEmpty()) {
|
||||
throw new NoValueException(this.getClass().toString());
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ public class UpdateRoleEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEvent(Group group) throws UserNotFoundException {
|
||||
protected void applyEvent(Group group) throws UserNotFoundException {
|
||||
if (group.getRoles().containsKey(this.userId)) {
|
||||
group.getRoles().put(this.userId, this.newRole);
|
||||
return;
|
||||
|
||||
@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
|
||||
public class GroupFullException extends EventException {
|
||||
|
||||
public GroupFullException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Der User existiert bereits.", 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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -15,9 +16,13 @@ import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
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;
|
||||
@ -71,10 +76,27 @@ 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 {
|
||||
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<>();
|
||||
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.warning("File konnte nicht gelesen werden");
|
||||
throw new WrongFileException(file.getOriginalFilename());
|
||||
}
|
||||
}
|
||||
visibility = visibility == null;
|
||||
lecture = lecture != null;
|
||||
maxInfiniteUsers = maxInfiniteUsers != null;
|
||||
Visibility visibility1;
|
||||
UUID groupId = eventService.checkGroup();
|
||||
|
||||
if (visibility) {
|
||||
visibility1 = Visibility.PUBLIC;
|
||||
} else {
|
||||
@ -100,7 +122,7 @@ public class ControllerService {
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
updateRole(account.getName(), groupId);
|
||||
addUserList(users, groupId);
|
||||
addUserList(userList, groupId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user