1

temporarily disable tests + rough change from groupid to uuid + remove invitelink old system

This commit is contained in:
Christoph
2020-03-23 16:17:17 +01:00
parent fff8a8a730
commit d562df8826
27 changed files with 152 additions and 384 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.UUID;
/**
* Ein Beispiel für eine API mit Swagger.
@ -45,14 +46,14 @@ public class APIController {
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
@Secured("ROLE_api_user")
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
public List<Long> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
return eventService.getGroupsOfUser(teilnehmer);
public List<UUID> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
return eventService.findGroupIdsByUser(teilnehmer);
}
@GetMapping("/getGroup/{groupId}")
@Secured("ROLE_api_user")
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable UUID groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(groupId);
List<Group> groups = groupService.projectEventList(eventList);

View File

@ -8,17 +8,15 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.CsvService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.InviteLinkRepositoryService;
import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@ -28,11 +26,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.annotation.SessionScope;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.RolesAllowed;
import java.io.CharConversionException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
@Controller
@ -44,16 +44,14 @@ public class Gruppen2Controller {
private final GroupService groupService;
private final UserService userService;
private final ControllerService controllerService;
private final InviteLinkRepositoryService inviteLinkRepositoryService;
private final Gruppen2Config gruppen2Config;
private final Logger logger;
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService, Gruppen2Config gruppen2Config) {
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, Gruppen2Config gruppen2Config) {
this.keyCloakService = keyCloakService;
this.groupService = groupService;
this.userService = userService;
this.controllerService = controllerService;
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
logger = Logger.getLogger("Gruppen2ControllerLogger");
this.gruppen2Config = gruppen2Config;
}
@ -93,7 +91,7 @@ public class Gruppen2Controller {
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam(value = "lecture", required = false) Boolean lecture,
@RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "parent", required = false) Long parent,
@RequestParam(value = "parent", required = false) String parent,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException, EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
@ -114,7 +112,7 @@ public class Gruppen2Controller {
if (lecture) parent = null;
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, parent, userList);
controllerService.createOrga(account, title, description, visibility, lecture, userMaximum, UUID.fromString(parent), userList);
return "redirect:/gruppen2/";
}
@ -135,18 +133,18 @@ public class Gruppen2Controller {
@RequestParam("description") String description,
@RequestParam(value = "visibility", required = false) Boolean visibility,
@RequestParam("userMaximum") Long userMaximum,
@RequestParam(value = "parent", required = false) Long parent) throws EventException {
@RequestParam(value = "parent", required = false) String parent) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
visibility = visibility == null;
controllerService.createGroup(account, title, description, visibility, userMaximum, parent);
controllerService.createGroup(account, title, description, visibility, userMaximum, UUID.fromString(parent));
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv")
public String addUsersFromCsv(@RequestParam("group_id") Long groupId,
public String addUsersFromCsv(@RequestParam("group_id") String groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>();
if (!file.isEmpty()) {
@ -156,7 +154,7 @@ public class Gruppen2Controller {
throw new WrongFileException(file.getOriginalFilename());
}
}
controllerService.addUserList(userList, groupId);
controllerService.addUserList(userList, UUID.fromString(groupId));
return "redirect:/gruppen2/details/members/" + groupId;
}
@ -175,17 +173,17 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException {
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(groupId);
Group group = userService.getGroupById(UUID.fromString(groupId));
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Long parentId = group.getParent();
UUID parentId = group.getParent();
Group parent = new Group();
if(group.getTitle() == null){
if (group.getTitle() == null) {
throw new GroupNotFoundException(this.getClass().toString());
}
if (!group.getMembers().contains(user)){
if (!group.getMembers().contains(user)) {
if (group.getVisibility() == Visibility.PRIVATE){
return "privateGroupNoMember";
}
@ -215,26 +213,28 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
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(groupId);
Group group = userService.getGroupById(UUID.fromString(groupId));
if (group.getMembers().contains(user)) {
return "error"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
}
if (group.getUserMaximum() < group.getMembers().size()) return "error";
controllerService.addUser(account, groupId);
if (group.getUserMaximum() < group.getMembers().size()) {
return "error";
}
controllerService.addUser(account, UUID.fromString(groupId));
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/detailsSearch")
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(groupId);
Long parentId = group.getParent();
Group group = userService.getGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent();
Group parent = new Group();
if (parentId != null) {
parent = userService.getGroupById(parentId);
@ -252,46 +252,46 @@ public class Gruppen2Controller {
@GetMapping("/acceptinvite/{link}")
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(inviteLinkRepositoryService.findGroupIdByInvite(link));
/*Group group = userService.getGroupById(inviteLinkRepositoryService.findGroupIdByInvite(link));
if (group != null) {
model.addAttribute("group", group);
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
}
}*/
throw new GroupNotFoundException(this.getClass().toString());
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId) throws EventException {
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") String groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.passIfLastAdmin(account, groupId);
controllerService.deleteUser(user.getId(), groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(user.getId(), groupId);
controllerService.passIfLastAdmin(account, UUID.fromString(groupId));
controllerService.deleteUser(user.getId(), UUID.fromString(groupId));
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().size() == 0) {
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
}
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/deleteGroup")
public String pDeleteGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId){
public String pDeleteGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(groupId);
if(group.getRoles().get(user.getId()) != Role.ADMIN ){
Group group = userService.getGroupById(UUID.fromString(groupId));
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
return "error";
}
controllerService.deleteGroupEvent(user.getId(), groupId);
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/members/{id}")
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") Long groupId) throws EventException {
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") String groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(groupId);
User user = new User(account.getName(),"", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId));
User user = new User(account.getName(), "", "", "");
if (group.getMembers().contains(user)) {
if (group.getRoles().get(account.getName()) == Role.ADMIN) {
model.addAttribute("account", account);
@ -309,29 +309,29 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole")
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
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, groupId)){
if (controllerService.passIfLastAdmin(account, UUID.fromString(groupId))) {
throw new NoAdminAfterActionException("Du otto bist letzter Admin");
}
controllerService.updateRole(userId, groupId);
controllerService.updateRole(userId, UUID.fromString(groupId));
return "redirect:/gruppen2/details/" + groupId;
}
controllerService.updateRole(userId, groupId);
controllerService.updateRole(userId, UUID.fromString(groupId));
return "redirect:/gruppen2/details/members/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser")
public String deleteUser(@RequestParam("group_id") Long groupId,
public String deleteUser(@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException {
controllerService.deleteUser(userId, groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(userId ,groupId);
controllerService.deleteUser(userId, UUID.fromString(groupId));
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().size() == 0) {
controllerService.deleteGroupEvent(userId, UUID.fromString(groupId));
}
return "redirect:/gruppen2/details/members/" + groupId;
}