Merge remote-tracking branch 'origin/master' into JavaDocComments
# Conflicts: # src/main/java/mops/gruppen2/controller/WebController.java
This commit is contained in:
@ -64,6 +64,7 @@ public class WebController {
|
|||||||
public String index(KeycloakAuthenticationToken token, Model model) {
|
public String index(KeycloakAuthenticationToken token, Model model) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
|
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||||
model.addAttribute("user", user);
|
model.addAttribute("user", user);
|
||||||
@ -74,6 +75,7 @@ public class WebController {
|
|||||||
@GetMapping("/createOrga")
|
@GetMapping("/createOrga")
|
||||||
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
|
public String createGroupAsOrga(KeycloakAuthenticationToken token, Model model) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||||
return "createOrga";
|
return "createOrga";
|
||||||
@ -96,8 +98,8 @@ public class WebController {
|
|||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
|
|
||||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||||
controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
|
|
||||||
|
|
||||||
|
controllerService.createGroupAsOrga(account, title, description, visibility, lecture, maxInfiniteUsers, userMaximum, parentUUID, file);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +107,7 @@ public class WebController {
|
|||||||
@GetMapping("/createStudent")
|
@GetMapping("/createStudent")
|
||||||
public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) {
|
public String createGroupAsStudent(KeycloakAuthenticationToken token, Model model) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
model.addAttribute("lectures", groupService.getAllLecturesWithVisibilityPublic());
|
||||||
return "createStudent";
|
return "createStudent";
|
||||||
@ -123,7 +126,9 @@ public class WebController {
|
|||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
UUID parentUUID = controllerService.getUUID(parent);
|
UUID parentUUID = controllerService.getUUID(parent);
|
||||||
|
|
||||||
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
validationService.checkFields(description, title, userMaximum, maxInfiniteUsers);
|
||||||
|
|
||||||
controllerService.createGroup(account, title, description, visibility, null, maxInfiniteUsers, userMaximum, parentUUID);
|
controllerService.createGroup(account, title, description, visibility, null, maxInfiniteUsers, userMaximum, parentUUID);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
@ -135,11 +140,8 @@ public class WebController {
|
|||||||
@RequestParam("group_id") String groupId,
|
@RequestParam("group_id") String groupId,
|
||||||
@RequestParam(value = "file", required = false) MultipartFile file) {
|
@RequestParam(value = "file", required = false) MultipartFile file) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<User> userList = new ArrayList<>();
|
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
controllerService.addUsersFromCsv(account, file, groupId);
|
||||||
userList = validationService.checkFile(file, userList, groupId, group, account);
|
|
||||||
UUID groupUUID = controllerService.getUUID(groupId);
|
|
||||||
controllerService.addUserList(userList, groupUUID);
|
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,16 +151,12 @@ public class WebController {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfAdmin(group, user);
|
|
||||||
model.addAttribute("account", account);
|
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
Group parent = new Group();
|
Group parent = new Group();
|
||||||
if (!validationService.checkIfUserInGroup(group, user)) {
|
|
||||||
model.addAttribute("group", group);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
model.addAttribute("parentId", parentId);
|
|
||||||
model.addAttribute("parent", parent);
|
model.addAttribute("account", account);
|
||||||
return "detailsNoMember";
|
|
||||||
}
|
|
||||||
model.addAttribute("title", group.getTitle());
|
model.addAttribute("title", group.getTitle());
|
||||||
model.addAttribute("description", group.getDescription());
|
model.addAttribute("description", group.getDescription());
|
||||||
model.addAttribute("admin", Role.ADMIN);
|
model.addAttribute("admin", Role.ADMIN);
|
||||||
@ -171,16 +169,19 @@ public class WebController {
|
|||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||||
@PostMapping("/details/changeMetadata")
|
@PostMapping("/details/changeMetadata")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String changeMetadata(KeycloakAuthenticationToken token,
|
public String postChangeMetadata(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) {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), "", "", "");
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfAdmin(group, user);
|
|
||||||
validationService.checkTitleAndDescription(title, description, account, groupId);
|
validationService.throwIfNoAdmin(group, user);
|
||||||
|
validationService.checkFields(title, description);
|
||||||
|
|
||||||
|
controllerService.changeMetaData(account, group, title, description);
|
||||||
return "redirect:/gruppen2/details/" + groupId;
|
return "redirect:/gruppen2/details/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +193,7 @@ public class WebController {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
List<Group> groups = new ArrayList<>();
|
List<Group> groups = new ArrayList<>();
|
||||||
groups = validationService.checkSearch(search, groups, account);
|
groups = validationService.checkSearch(search, groups, account);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("gruppen", groups);
|
model.addAttribute("gruppen", groups);
|
||||||
model.addAttribute("inviteService", inviteService);
|
model.addAttribute("inviteService", inviteService);
|
||||||
@ -204,17 +206,20 @@ public class WebController {
|
|||||||
Model model,
|
Model model,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
@PathVariable("id") String groupId) {
|
@PathVariable("id") String groupId) {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
||||||
|
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
|
String actualURL = request.getRequestURL().toString();
|
||||||
|
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||||
|
Group parent = controllerService.getParent(parentId);
|
||||||
|
|
||||||
validationService.checkGroup(group.getTitle());
|
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||||
Group parent = validationService.checkParent(parentId);
|
|
||||||
|
|
||||||
|
model.addAttribute("account", account);
|
||||||
if (!validationService.checkIfUserInGroup(group, user)) {
|
if (!validationService.checkIfUserInGroup(group, user)) {
|
||||||
|
validationService.throwIfNoAccessToPrivate(group, user);
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("parentId", parentId);
|
model.addAttribute("parentId", parentId);
|
||||||
model.addAttribute("parent", parent);
|
model.addAttribute("parent", parent);
|
||||||
@ -228,10 +233,9 @@ public class WebController {
|
|||||||
model.addAttribute("user", user);
|
model.addAttribute("user", user);
|
||||||
model.addAttribute("admin", Role.ADMIN);
|
model.addAttribute("admin", Role.ADMIN);
|
||||||
|
|
||||||
String actualURL = request.getRequestURL().toString();
|
if (validationService.checkIfAdmin(group, user)) {
|
||||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
||||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
}
|
||||||
|
|
||||||
return "detailsMember";
|
return "detailsMember";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,13 +244,16 @@ public class WebController {
|
|||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String joinGroup(KeycloakAuthenticationToken token,
|
public String joinGroup(KeycloakAuthenticationToken token,
|
||||||
Model model, @RequestParam("id") String groupId) {
|
Model model, @RequestParam("id") String groupId) {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfUserInGroupJoin(group, user);
|
|
||||||
validationService.checkIfGroupFull(group);
|
validationService.throwIfUserAlreadyInGroup(group, user);
|
||||||
controllerService.addUser(account, group.getId());
|
validationService.throwIfGroupFull(group);
|
||||||
|
|
||||||
|
controllerService.addUser(account, UUID.fromString(groupId));
|
||||||
|
|
||||||
|
model.addAttribute("account", account);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,12 +262,16 @@ public class WebController {
|
|||||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@RequestParam("id") String groupId) {
|
@RequestParam("id") String groupId) {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfGroupFull(group);
|
|
||||||
|
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
Group parent = validationService.checkParent(parentId);
|
Group parent = controllerService.getParent(parentId);
|
||||||
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
|
||||||
|
model.addAttribute("account", account);
|
||||||
|
if (validationService.checkIfUserInGroup(group, user)){
|
||||||
|
return "redirect:/gruppen2/details/" + groupId;
|
||||||
|
}
|
||||||
|
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("parentId", parentId);
|
model.addAttribute("parentId", parentId);
|
||||||
@ -275,9 +286,11 @@ public class WebController {
|
|||||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||||
Model model,
|
Model model,
|
||||||
@PathVariable("link") String link) {
|
@PathVariable("link") String link) {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
|
||||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||||
validationService.checkGroup(group.getTitle());
|
|
||||||
|
validationService.throwIfGroupNotExisting(group.getTitle());
|
||||||
|
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
|
|
||||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||||
@ -297,7 +310,7 @@ public class WebController {
|
|||||||
|
|
||||||
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
||||||
|
|
||||||
if (!validationService.checkIfUserInGroupWithoutNoAccessAcception(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
if (!validationService.checkIfUserInGroup(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
||||||
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,10 +323,10 @@ public class WebController {
|
|||||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||||
@RequestParam("group_id") String groupId) {
|
@RequestParam("group_id") String groupId) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), "", "", "");
|
||||||
controllerService.passIfLastAdmin(account, UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
controllerService.deleteUser(user.getId(), UUID.fromString(groupId));
|
|
||||||
validationService.checkIfGroupEmpty(groupId, user);
|
controllerService.deleteUser(account, user, group);
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +338,9 @@ public class WebController {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfAdmin(group, user);
|
|
||||||
|
validationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
}
|
}
|
||||||
@ -338,7 +353,9 @@ public class WebController {
|
|||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
User user = new User(account.getName(), "", "", "");
|
User user = new User(account.getName(), "", "", "");
|
||||||
validationService.checkIfAdmin(group, user);
|
|
||||||
|
validationService.throwIfNoAdmin(group, user);
|
||||||
|
|
||||||
model.addAttribute("account", account);
|
model.addAttribute("account", account);
|
||||||
model.addAttribute("members", group.getMembers());
|
model.addAttribute("members", group.getMembers());
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
@ -353,7 +370,16 @@ public class WebController {
|
|||||||
@RequestParam("group_id") String groupId,
|
@RequestParam("group_id") String groupId,
|
||||||
@RequestParam("user_id") String userId) {
|
@RequestParam("user_id") String userId) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
if (validationService.checkIfDemotingSelf(userId, groupId, account)) {
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
|
User principle = new User(account.getName(), "", "", "");
|
||||||
|
User user = new User(userId, "", "", "");
|
||||||
|
|
||||||
|
validationService.throwIfNoAdmin(group, principle);
|
||||||
|
|
||||||
|
controllerService.changeRole(account, user, group);
|
||||||
|
|
||||||
|
group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
|
if (!validationService.checkIfAdmin(group, principle)) {
|
||||||
return "redirect:/gruppen2/details/" + groupId;
|
return "redirect:/gruppen2/details/" + groupId;
|
||||||
}
|
}
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
@ -366,7 +392,10 @@ public class WebController {
|
|||||||
@RequestParam("group_id") String groupId,
|
@RequestParam("group_id") String groupId,
|
||||||
KeycloakAuthenticationToken token) {
|
KeycloakAuthenticationToken token) {
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
validationService.checkIfNewMaximumIsValid(maximum, groupId);
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
|
validationService.throwIfNewMaximumIsValid(maximum, group);
|
||||||
|
|
||||||
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
controllerService.updateMaxUser(account, UUID.fromString(groupId), maximum);
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
}
|
}
|
||||||
@ -375,10 +404,20 @@ public class WebController {
|
|||||||
@PostMapping("/details/members/deleteUser")
|
@PostMapping("/details/members/deleteUser")
|
||||||
@CacheEvict(value = "groups", allEntries = true)
|
@CacheEvict(value = "groups", allEntries = true)
|
||||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||||
@RequestParam("user_id") String userId) {
|
@RequestParam("user_id") String userId,
|
||||||
|
KeycloakAuthenticationToken token) {
|
||||||
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
|
User principle = new User(account.getName(), "", "", "");
|
||||||
User user = new User(userId, "", "", "");
|
User user = new User(userId, "", "", "");
|
||||||
controllerService.deleteUser(userId, UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
validationService.checkIfGroupEmpty(groupId, user);
|
|
||||||
|
validationService.throwIfNoAdmin(group, principle);
|
||||||
|
|
||||||
|
controllerService.deleteUser(account, user, group);
|
||||||
|
|
||||||
|
if (!validationService.checkIfUserInGroup(group, principle)) {
|
||||||
|
return "redirect:/gruppen2/";
|
||||||
|
}
|
||||||
return "redirect:/gruppen2/details/members/" + groupId;
|
return "redirect:/gruppen2/details/members/" + groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
public class BadParameterException extends EventException {
|
public class BadParameterException extends EventException {
|
||||||
|
|
||||||
public BadParameterException(String info) {
|
public BadParameterException(String info) {
|
||||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Fehlerhafter Parameter angegeben!", info);
|
super(HttpStatus.BAD_REQUEST, "Fehlerhafter Parameter angegeben!", info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
public class NoValueException extends EventException {
|
public class NoValueException extends EventException {
|
||||||
|
|
||||||
public NoValueException(String info) {
|
public NoValueException(String info) {
|
||||||
super(HttpStatus.NO_CONTENT, "Eine Information fehlt.", info);
|
super(HttpStatus.BAD_REQUEST, "Eine Information fehlt.", info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,14 @@ public class ControllerService {
|
|||||||
|
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final ValidationService validationService;
|
||||||
private final InviteService inviteService;
|
private final InviteService inviteService;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public ControllerService(EventService eventService, UserService userService, InviteService inviteService) {
|
public ControllerService(EventService eventService, UserService userService, ValidationService validationService, InviteService inviteService) {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.validationService = validationService;
|
||||||
this.inviteService = inviteService;
|
this.inviteService = inviteService;
|
||||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||||
}
|
}
|
||||||
@ -68,10 +70,12 @@ public class ControllerService {
|
|||||||
|
|
||||||
inviteService.createLink(groupId);
|
inviteService.createLink(groupId);
|
||||||
|
|
||||||
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
|
||||||
addUser(account, groupId);
|
addUser(account, groupId);
|
||||||
updateTitle(account, groupId, title);
|
updateTitle(account, groupId, title);
|
||||||
updateDescription(account, groupId, description);
|
updateDescription(account, groupId, description);
|
||||||
updateRole(account.getName(), groupId);
|
updateRole(user, groupId);
|
||||||
|
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
@ -107,6 +111,40 @@ public class ControllerService {
|
|||||||
addUserList(newUsers, groupId);
|
addUserList(newUsers, groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addUsersFromCsv(Account account, MultipartFile file, String groupId) throws IOException{
|
||||||
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
|
|
||||||
|
List<User> newUserList = readCsvFile(file);
|
||||||
|
removeOldUsersFromNewUsers(group.getMembers(), newUserList);
|
||||||
|
|
||||||
|
UUID groupUUID = getUUID(groupId);
|
||||||
|
|
||||||
|
Long newUserMaximum = adjustUserMaximum((long) newUserList.size(), (long) group.getMembers().size(), group.getUserMaximum());
|
||||||
|
if (newUserMaximum > group.getUserMaximum()){
|
||||||
|
updateMaxUser(account, groupUUID, newUserMaximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
addUserList(newUserList, groupUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeMetaData(Account account, Group group, String title, String description) {
|
||||||
|
if (!title.equals(group.getTitle())){
|
||||||
|
updateTitle(account, group.getId(), title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!description.equals(group.getDescription())) {
|
||||||
|
updateDescription(account, group.getId(), description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group getParent(UUID parentId) {
|
||||||
|
Group parent = new Group();
|
||||||
|
if (!idIsEmpty(parentId)) {
|
||||||
|
parent = userService.getGroupById(parentId);
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
private void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
|
private void removeOldUsersFromNewUsers(List<User> oldUsers, List<User> newUsers) {
|
||||||
for (User oldUser : oldUsers) {
|
for (User oldUser : oldUsers) {
|
||||||
newUsers.remove(oldUser);
|
newUsers.remove(oldUser);
|
||||||
@ -175,8 +213,8 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(addUserEvent);
|
eventService.saveEvent(addUserEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUserList(List<User> users, UUID groupId) {
|
public void addUserList(List<User> newUsers, UUID groupId) {
|
||||||
for (User user : users) {
|
for (User user : newUsers) {
|
||||||
Group group = userService.getGroupById(groupId);
|
Group group = userService.getGroupById(groupId);
|
||||||
if (group.getMembers().contains(user)) {
|
if (group.getMembers().contains(user)) {
|
||||||
logger.info("Benutzer " + user.getId() + " ist bereits in Gruppe");
|
logger.info("Benutzer " + user.getId() + " ist bereits in Gruppe");
|
||||||
@ -202,41 +240,32 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(updateUserMaxEvent);
|
eventService.saveEvent(updateUserMaxEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRole(String userId, UUID groupId) throws EventException {
|
public void updateRole(User user, UUID groupId) throws EventException {
|
||||||
UpdateRoleEvent updateRoleEvent;
|
UpdateRoleEvent updateRoleEvent;
|
||||||
Group group = userService.getGroupById(groupId);
|
Group group = userService.getGroupById(groupId);
|
||||||
User user = null;
|
validationService.throwIfNotInGroup(group, user);
|
||||||
for (User member : group.getMembers()) {
|
|
||||||
if (member.getId().equals(userId)) {
|
|
||||||
user = member;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
throw new UserNotFoundException(this.getClass().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group.getRoles().get(user.getId()) == ADMIN) {
|
if (group.getRoles().get(user.getId()) == ADMIN) {
|
||||||
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.MEMBER);
|
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), Role.MEMBER);
|
||||||
} else {
|
} else {
|
||||||
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), ADMIN);
|
updateRoleEvent = new UpdateRoleEvent(group.getId(), user.getId(), ADMIN);
|
||||||
}
|
}
|
||||||
eventService.saveEvent(updateRoleEvent);
|
eventService.saveEvent(updateRoleEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteUser(String userId, UUID groupId) throws EventException {
|
public void deleteUser(Account account, User user, Group group) throws EventException {
|
||||||
Group group = userService.getGroupById(groupId);
|
changeRoleIfLastAdmin(account, group);
|
||||||
User user = null;
|
|
||||||
for (User member : group.getMembers()) {
|
|
||||||
if (member.getId().equals(userId)) {
|
|
||||||
user = member;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user == null) {
|
validationService.throwIfNotInGroup(group, user);
|
||||||
throw new UserNotFoundException(this.getClass().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
deleteUserEvent(user, group.getId());
|
||||||
|
|
||||||
|
if (validationService.checkIfGroupEmpty(group.getId())) {
|
||||||
|
deleteGroupEvent(user.getId(), group.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteUserEvent(User user, UUID groupId) {
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
|
||||||
eventService.saveEvent(deleteUserEvent);
|
eventService.saveEvent(deleteUserEvent);
|
||||||
}
|
}
|
||||||
@ -247,36 +276,39 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(deleteGroupEvent);
|
eventService.saveEvent(deleteGroupEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean passIfLastAdmin(Account account, UUID groupId) {
|
public void changeRoleIfLastAdmin(Account account, Group group) {
|
||||||
Group group = userService.getGroupById(groupId);
|
|
||||||
if (group.getMembers().size() <= 1) {
|
if (group.getMembers().size() <= 1) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
promoteVeteranMember(account, group);
|
||||||
if (isLastAdmin(account, group)) {
|
|
||||||
String newAdminId = getVeteranMember(account, group);
|
|
||||||
updateRole(newAdminId, groupId);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLastAdmin(Account account, Group group) {
|
private void promoteVeteranMember(Account account, Group group) {
|
||||||
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
if (validationService.checkIfLastAdmin(account, group)) {
|
||||||
if (entry.getValue() == ADMIN) {
|
User newAdmin = getVeteranMember(account, group);
|
||||||
if (!(entry.getKey().equals(account.getName()))) {
|
updateRole(newAdmin, group.getId());
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeRole(Account account, User user, Group group) {
|
||||||
|
if (user.getId().equals(account.getName())) {
|
||||||
|
if (group.getMembers().size() <= 1) {
|
||||||
|
validationService.throwIfLastAdmin(account, group);
|
||||||
}
|
}
|
||||||
|
promoteVeteranMember(account, group);
|
||||||
}
|
}
|
||||||
return true;
|
updateRole(user, group.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getVeteranMember(Account account, Group group) {
|
private User getVeteranMember(Account account, Group group) {
|
||||||
List<User> mitglieder = group.getMembers();
|
List<User> members = group.getMembers();
|
||||||
if (mitglieder.get(0).getId().equals(account.getName())) {
|
String newAdminId;
|
||||||
return mitglieder.get(1).getId();
|
if (members.get(0).getId().equals(account.getName())) {
|
||||||
|
newAdminId = members.get(1).getId();
|
||||||
|
} else {
|
||||||
|
newAdminId = members.get(0).getId();
|
||||||
}
|
}
|
||||||
return mitglieder.get(0).getId();
|
return new User(newAdminId, "", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID(String id) {
|
public UUID getUUID(String id) {
|
||||||
|
@ -4,43 +4,27 @@ import mops.gruppen2.domain.Group;
|
|||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.exception.BadParameterException;
|
import mops.gruppen2.domain.exception.*;
|
||||||
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.NoValueException;
|
|
||||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
|
||||||
import mops.gruppen2.domain.exception.WrongFileException;
|
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static mops.gruppen2.domain.Role.ADMIN;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ValidationService {
|
public class ValidationService {
|
||||||
|
|
||||||
private final ControllerService controllerService;
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final GroupService groupService;
|
private final GroupService groupService;
|
||||||
|
|
||||||
public ValidationService(ControllerService controllerService, UserService userService, GroupService groupService) {
|
public ValidationService(UserService userService, GroupService groupService) {
|
||||||
this.controllerService = controllerService;
|
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTitleAndDescription(String title, String description, Account account, String groupId) {
|
|
||||||
if (title == null || description == null) {
|
|
||||||
throw new NoValueException("Titel und Beschreibung müssen ausgefüllt werden");
|
|
||||||
}
|
|
||||||
controllerService.updateTitle(account, UUID.fromString(groupId), title);
|
|
||||||
controllerService.updateDescription(account, UUID.fromString(groupId), description);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Group> checkSearch(String search, List<Group> groups, Account account) {
|
public List<Group> checkSearch(String search, List<Group> groups, Account account) {
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
groups = groupService.findGroupWith(search, account);
|
groups = groupService.findGroupWith(search, account);
|
||||||
@ -48,83 +32,73 @@ public class ValidationService {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkGroup(String title) {
|
public void throwIfGroupNotExisting(String title) {
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
throw new GroupNotFoundException("@details");
|
throw new GroupNotFoundException("@details");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkIfUserInGroup(Group group, User user) {
|
public void throwIfNoAccessToPrivate(Group group, User user) {
|
||||||
if (!group.getMembers().contains(user) && group.getVisibility() == Visibility.PRIVATE) {
|
if (!checkIfUserInGroup(group, user) && group.getVisibility() == Visibility.PRIVATE) {
|
||||||
throw new NoAccessException("");
|
throw new NoAccessException("");
|
||||||
} else {
|
|
||||||
return group.getMembers().contains(user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Warum ist das überhaupt nötig smh
|
public boolean checkIfUserInGroup(Group group, User user) {
|
||||||
public boolean checkIfUserInGroupWithoutNoAccessAcception(Group group, User user) {
|
|
||||||
return group.getMembers().contains(user);
|
return group.getMembers().contains(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group checkParent(UUID parentId) {
|
public void throwIfUserAlreadyInGroup(Group group, User user) {
|
||||||
Group parent = new Group();
|
if (checkIfUserInGroup(group, user)) {
|
||||||
if (!controllerService.idIsEmpty(parentId)) {
|
|
||||||
parent = userService.getGroupById(parentId);
|
|
||||||
}
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkIfUserInGroupJoin(Group group, User user) {
|
|
||||||
if (group.getMembers().contains(user)) {
|
|
||||||
throw new UserAlreadyExistsException("@details");
|
throw new UserAlreadyExistsException("@details");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfGroupFull(Group group) {
|
public void throwIfNotInGroup(Group group, User user) {
|
||||||
|
if (!checkIfUserInGroup(group, user)) {
|
||||||
|
throw new UserNotFoundException(this.getClass().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void throwIfGroupFull(Group group) {
|
||||||
if (group.getUserMaximum() < group.getMembers().size() + 1) {
|
if (group.getUserMaximum() < group.getMembers().size() + 1) {
|
||||||
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
|
throw new GroupFullException("Du kannst der Gruppe daher leider nicht beitreten.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkIfGroupEmpty(UUID groupId) {
|
||||||
public void checkIfGroupEmpty(String groupId, User user) {
|
return userService.getGroupById(groupId).getMembers().isEmpty();
|
||||||
if (userService.getGroupById(UUID.fromString(groupId)).getMembers().isEmpty()) {
|
|
||||||
controllerService.deleteGroupEvent(user.getId(), UUID.fromString(groupId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfAdmin(Group group, User user) {
|
public void throwIfNoAdmin(Group group, User user) {
|
||||||
checkIfUserInGroup(group, user);
|
throwIfNoAccessToPrivate(group, user);
|
||||||
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
|
if (group.getRoles().get(user.getId()) != Role.ADMIN) {
|
||||||
throw new NoAccessException("");
|
throw new NoAccessException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkIfDemotingSelf(String userId, String groupId, Account account) {
|
public boolean checkIfAdmin(Group group, User user) {
|
||||||
if (userId.equals(account.getName())) {
|
if (checkIfUserInGroup(group, user)) {
|
||||||
if (controllerService.passIfLastAdmin(account, UUID.fromString(groupId))) {
|
return group.getRoles().get(user.getId()) == Role.ADMIN;
|
||||||
throw new NoAdminAfterActionException("Du Otto bist letzter Admin");
|
|
||||||
}
|
|
||||||
controllerService.updateRole(userId, UUID.fromString(groupId));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
controllerService.updateRole(userId, UUID.fromString(groupId));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> checkFile(MultipartFile file, List<User> userList, String groupId, Group group, Account account) {
|
public boolean checkIfLastAdmin(Account account, Group group) {
|
||||||
if (!file.isEmpty()) {
|
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
||||||
try {
|
if (entry.getValue() == ADMIN) {
|
||||||
userList = CsvService.read(file.getInputStream());
|
if (!(entry.getKey().equals(account.getName()))) {
|
||||||
if (userList.size() + group.getMembers().size() > group.getUserMaximum()) {
|
return false;
|
||||||
controllerService.updateMaxUser(account, UUID.fromString(groupId), (long) userList.size() + group.getMembers().size());
|
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new WrongFileException(file.getOriginalFilename());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userList;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void throwIfLastAdmin(Account account, Group group) {
|
||||||
|
if (checkIfLastAdmin(account, group)) {
|
||||||
|
throw new NoAdminAfterActionException("Du Otto bist letzter Admin!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,7 +108,7 @@ public class ValidationService {
|
|||||||
* @param title Der Titel der Gruppe
|
* @param title Der Titel der Gruppe
|
||||||
* @param userMaximum Das user Limit der Gruppe
|
* @param userMaximum Das user Limit der Gruppe
|
||||||
*/
|
*/
|
||||||
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
|
public void checkFields(String title, String description, Long userMaximum, Boolean maxInfiniteUsers) {
|
||||||
if (description == null || description.trim().length() == 0) {
|
if (description == null || description.trim().length() == 0) {
|
||||||
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||||
}
|
}
|
||||||
@ -154,8 +128,17 @@ public class ValidationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfNewMaximumIsValid(Long newUserMaximum, String groupId) {
|
public void checkFields(String title, String description) {
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
if (description == null || description.trim().length() == 0) {
|
||||||
|
throw new BadParameterException("Die Beschreibung wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title == null || title.trim().length() == 0) {
|
||||||
|
throw new BadParameterException("Der Titel wurde nicht korrekt angegeben");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void throwIfNewMaximumIsValid(Long newUserMaximum, Group group) {
|
||||||
if (newUserMaximum == null) {
|
if (newUserMaximum == null) {
|
||||||
throw new BadParameterException("Es wurde keine neue maximale Teilnehmeranzahl angegeben!");
|
throw new BadParameterException("Es wurde keine neue maximale Teilnehmeranzahl angegeben!");
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,23 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Gruppen2Application.class)
|
@SpringBootTest(classes = Gruppen2Application.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Rollback
|
@Rollback
|
||||||
class ControllerServiceTest {
|
class ControllerServiceTest {
|
||||||
Account account, account2, account3;
|
Account account;
|
||||||
|
Account account2;
|
||||||
|
Account account3;
|
||||||
ControllerService controllerService;
|
ControllerService controllerService;
|
||||||
EventService eventService;
|
EventService eventService;
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
ValidationService validationService;
|
||||||
@Autowired
|
@Autowired
|
||||||
EventRepository eventRepository;
|
EventRepository eventRepository;
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
@ -47,7 +53,8 @@ class ControllerServiceTest {
|
|||||||
eventService = new EventService(jsonService, eventRepository);
|
eventService = new EventService(jsonService, eventRepository);
|
||||||
groupService = new GroupService(eventService, eventRepository);
|
groupService = new GroupService(eventService, eventRepository);
|
||||||
userService = new UserService(groupService, eventService);
|
userService = new UserService(groupService, eventService);
|
||||||
controllerService = new ControllerService(eventService, userService, inviteService);
|
validationService = new ValidationService(userService, groupService);
|
||||||
|
controllerService = new ControllerService(eventService, userService, validationService, inviteService);
|
||||||
Set<String> roles = new HashSet<>();
|
Set<String> roles = new HashSet<>();
|
||||||
roles.add("l");
|
roles.add("l");
|
||||||
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
||||||
@ -220,7 +227,8 @@ class ControllerServiceTest {
|
|||||||
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
controllerService.createGroup(account, "test", "hi", true, true, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
controllerService.deleteUser(account, user, groups.get(0));
|
||||||
assertTrue(userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
assertTrue(userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +237,8 @@ class ControllerServiceTest {
|
|||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.updateRole(account.getName(), groups.get(0).getId());
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
controllerService.updateRole(user, groups.get(0).getId());
|
||||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
||||||
}
|
}
|
||||||
@ -239,7 +248,8 @@ class ControllerServiceTest {
|
|||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
User user = new User(account2.getName(), "", "", "");
|
||||||
|
controllerService.updateRole(user, groups.get(0).getId());
|
||||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
}
|
}
|
||||||
@ -248,16 +258,18 @@ class ControllerServiceTest {
|
|||||||
public void updateRoleNonUserTest() {
|
public void updateRoleNonUserTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.updateRole(account2.getName(), groups.get(0).getId()));
|
User user = new User(account2.getName(), "", "", "");
|
||||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.updateRole(user, groups.get(0).getId()));
|
||||||
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteNonUserTest() {
|
public void deleteNonUserTest() {
|
||||||
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.deleteUser(account2.getName(), groups.get(0).getId()));
|
User user = new User(account2.getName(), "", "", "");
|
||||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.deleteUser(account, user, groups.get(0)));
|
||||||
|
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ValidationService)\"", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testTitleAndDescription(String title, String description) {
|
void testTitleAndDescription(String title, String description) {
|
||||||
@ -270,8 +282,9 @@ class ControllerServiceTest {
|
|||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
User user = new User(account.getName(), "", "", "");
|
||||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
controllerService.deleteUser(account, user, groups.get(0));
|
||||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
}
|
}
|
||||||
@ -281,10 +294,12 @@ class ControllerServiceTest {
|
|||||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
User user2 = new User(account2.getName(), "", "", "");
|
||||||
|
controllerService.updateRole(user2, groups.get(0).getId());
|
||||||
controllerService.addUser(account3, groups.get(0).getId());
|
controllerService.addUser(account3, groups.get(0).getId());
|
||||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
controllerService.changeRoleIfLastAdmin(account, groups.get(0));
|
||||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
User user = new User(account.getName(), "", "", "");
|
||||||
|
controllerService.deleteUser(account, user, groups.get(0));
|
||||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
}
|
}
|
||||||
@ -295,8 +310,9 @@ class ControllerServiceTest {
|
|||||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||||
controllerService.addUser(account2, groups.get(0).getId());
|
controllerService.addUser(account2, groups.get(0).getId());
|
||||||
controllerService.addUser(account3, groups.get(0).getId());
|
controllerService.addUser(account3, groups.get(0).getId());
|
||||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
User user = new User(account.getName(), "", "", "");
|
||||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
|
controllerService.deleteUser(account, user, groups.get(0));
|
||||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||||
|
@ -77,38 +77,6 @@ class EventServiceTest {
|
|||||||
assertThat(dto.getEvent_type()).isEqualTo("CreateGroupEvent");
|
assertThat(dto.getEvent_type()).isEqualTo("CreateGroupEvent");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void getNewEvents_createGroupEvents() {
|
|
||||||
eventService.saveAll(createPrivateGroupEvents(10));
|
|
||||||
|
|
||||||
assertThat(eventService.getNewEvents(0L)).hasSize(10);
|
|
||||||
assertThat(eventService.getNewEvents(5L)).hasSize(5);
|
|
||||||
assertThat(eventService.getNewEvents(10L)).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void getNewEvents_mixedEvents() {
|
|
||||||
eventService.saveAll(createPrivateGroupEvent(uuidFromInt(0)),
|
|
||||||
updateGroupDescriptionEvent(uuidFromInt(0)),
|
|
||||||
createPrivateGroupEvent(uuidFromInt(1)),
|
|
||||||
updateGroupDescriptionEvent(uuidFromInt(1)));
|
|
||||||
|
|
||||||
assertThat(eventService.getNewEvents(0L)).hasSize(4);
|
|
||||||
assertThat(eventService.getNewEvents(1L)).hasSize(4);
|
|
||||||
assertThat(eventService.getNewEvents(2L)).hasSize(2);
|
|
||||||
assertThat(eventService.getNewEvents(3L)).hasSize(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
|
||||||
void getMaxEvent_id() {
|
|
||||||
eventService.saveAll(createPrivateGroupEvents(10));
|
|
||||||
|
|
||||||
assertThat(eventService.getMaxEvent_id()).isEqualTo(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getEventsOfGroup() {
|
void getEventsOfGroup() {
|
||||||
eventService.saveAll(addUserEvents(10, uuidFromInt(0)),
|
eventService.saveAll(addUserEvents(10, uuidFromInt(0)),
|
||||||
|
Reference in New Issue
Block a user