Merge remote-tracking branch 'origin/master'
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -33,4 +33,4 @@ out/
|
||||
.floo
|
||||
.flooignore
|
||||
|
||||
/mysql/*
|
||||
/mysql/db/storage/
|
||||
|
@ -1,16 +1,12 @@
|
||||
FROM gradle:jdk11 AS build
|
||||
COPY --chown=gradle:gradle . /home/gradle/src
|
||||
WORKDIR /home/gradle/src
|
||||
|
||||
RUN chmod +x ./pull-wait-for-it.sh
|
||||
RUN ./pull-wait-for-it.sh
|
||||
RUN chmod +x ./wait-for-it.sh
|
||||
|
||||
RUN gradle bootJar --no-daemon
|
||||
|
||||
FROM openjdk:11-jre-slim
|
||||
RUN mkdir /app
|
||||
COPY --from=build /home/gradle/src/build/libs/*.jar /app/gruppen2.jar
|
||||
COPY --from=build /home/gradle/src/wait-for-it.sh /app/wait-for-it.sh
|
||||
RUN chmod +x /app/wait-for-it.sh
|
||||
#ENTRYPOINT ["java"]
|
||||
#CMD ["-Dspring.profiles.active=docker", "-jar", "/app/gruppen2.jar"]
|
||||
|
@ -226,7 +226,6 @@
|
||||
<property name="lineWrappingIndentation" value="8"/>
|
||||
<property name="arrayInitIndent" value="4"/>
|
||||
</module>
|
||||
<module name="OverloadMethodsDeclarationOrder"/>
|
||||
<module name="VariableDeclarationUsageDistance"/>
|
||||
<module name="MethodParamPad">
|
||||
<property name="tokens"
|
||||
|
@ -6,3 +6,10 @@ CREATE TABLE event
|
||||
event_type VARCHAR(36),
|
||||
event_payload JSON
|
||||
);
|
||||
|
||||
CREATE TABLE invite
|
||||
(
|
||||
invite_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
group_id VARCHAR(36) NOT NULL,
|
||||
invite_link VARCHAR(36) NOT NULL
|
||||
);
|
||||
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ ! -f wait-for-it.sh ]; then
|
||||
wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
|
||||
fi
|
@ -2,6 +2,7 @@ package mops.gruppen2;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
import java.util.Collections;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
@EnableSwagger2
|
||||
public class Gruppen2Application {
|
||||
|
||||
|
@ -10,6 +10,8 @@ import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.service.APIFormatterService;
|
||||
import mops.gruppen2.service.EventService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -28,14 +30,16 @@ public class APIController {
|
||||
|
||||
private final EventService eventService;
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
|
||||
public APIController(EventService eventService, GroupService groupService) {
|
||||
public APIController(EventService eventService, GroupService groupService, UserService userService) {
|
||||
this.eventService = eventService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich etwas geändert hat")
|
||||
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
@ -44,16 +48,16 @@ public class APIController {
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@Secured("ROLE_api_user")
|
||||
@ApiOperation("Gibt alle Gruppen zurück in denen sich ein Teilnehmer befindet")
|
||||
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) {
|
||||
return eventService.findGroupIdsByUser(teilnehmer).stream()
|
||||
.map(UUID::toString)
|
||||
.collect(Collectors.toList());
|
||||
return userService.getUserGroups(teilnehmer).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
//@Secured("ROLE_api_user")
|
||||
@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 String groupId) throws EventException {
|
||||
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));
|
||||
|
@ -3,15 +3,18 @@ package mops.gruppen2.controller;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||
import mops.gruppen2.security.Account;
|
||||
import mops.gruppen2.service.ControllerService;
|
||||
import mops.gruppen2.service.GroupService;
|
||||
import mops.gruppen2.service.InviteService;
|
||||
import mops.gruppen2.service.KeyCloakService;
|
||||
import mops.gruppen2.service.UserService;
|
||||
import mops.gruppen2.service.ValidationService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -39,13 +42,15 @@ public class WebController {
|
||||
private final UserService userService;
|
||||
private final ControllerService controllerService;
|
||||
private final ValidationService validationService;
|
||||
private final InviteService inviteService;
|
||||
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService) {
|
||||
public WebController(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, ValidationService validationService, InviteService inviteService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.validationService = validationService;
|
||||
this.inviteService = inviteService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +60,6 @@ public class WebController {
|
||||
* @param model tolles model
|
||||
* @return index.html
|
||||
*/
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
@ -78,6 +82,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createOrga")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -108,6 +113,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_studentin"})
|
||||
@PostMapping("/createStudent")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -125,6 +131,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/addUsersFromCsv")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String addUsersFromCsv(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
|
||||
@ -164,6 +171,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/details/changeMetadata")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pChangeMetadata(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("description") String description,
|
||||
@ -187,12 +195,16 @@ public class WebController {
|
||||
groups = validationService.checkSearch(search, groups, account);
|
||||
model.addAttribute("account", account);
|
||||
model.addAttribute("gruppen", groups);
|
||||
model.addAttribute("inviteService", inviteService);
|
||||
return "search";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, HttpServletRequest request, @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));
|
||||
@ -219,13 +231,14 @@ public class WebController {
|
||||
|
||||
String actualURL = request.getRequestURL().toString();
|
||||
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + inviteService.getLinkByGroupId(group.getId()));
|
||||
|
||||
return "detailsMember";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String joinGroup(KeycloakAuthenticationToken token,
|
||||
Model model, @RequestParam("id") String groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
@ -234,7 +247,7 @@ public class WebController {
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
validationService.checkIfUserInGroupJoin(group, user);
|
||||
validationService.checkIfGroupFull(group);
|
||||
controllerService.addUser(account, UUID.fromString(groupId));
|
||||
controllerService.addUser(account, group.getId());
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@ -257,19 +270,44 @@ public class WebController {
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
//TODO: Muss post-mapping sein
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/acceptinvite/{groupId}")
|
||||
@GetMapping("/acceptinvite/{link}")
|
||||
public String acceptInvite(KeycloakAuthenticationToken token,
|
||||
Model model, @PathVariable String groupId) throws EventException {
|
||||
Model model,
|
||||
@PathVariable("link") String link) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||
Group group = userService.getGroupById(inviteService.getGroupIdFromLink(link));
|
||||
validationService.checkGroup(group.getTitle());
|
||||
model.addAttribute("group", group);
|
||||
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
||||
|
||||
if (group.getVisibility() == Visibility.PUBLIC) {
|
||||
return "redirect:/gruppen2/details/" + group.getId();
|
||||
}
|
||||
|
||||
return "joinprivate";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/acceptinvite")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String postAcceptInvite(KeycloakAuthenticationToken token,
|
||||
@RequestParam("id") String groupId) {
|
||||
|
||||
Account acc = keyCloakService.createAccountFromPrincipal(token);
|
||||
|
||||
User user = new User(acc.getName(), acc.getGivenname(), acc.getFamilyname(), acc.getEmail());
|
||||
|
||||
if (!validationService.checkIfUserInGroupWithoutNoAccessAcception(userService.getGroupById(UUID.fromString(groupId)), user)) {
|
||||
controllerService.addUser(keyCloakService.createAccountFromPrincipal(token), UUID.fromString(groupId));
|
||||
}
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/leaveGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -282,6 +320,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/deleteGroup")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String pDeleteGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId) {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -310,6 +349,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/changeRole")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeRole(KeycloakAuthenticationToken token,
|
||||
@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
@ -322,6 +362,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/changeMaximum")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String changeMaxSize(@RequestParam("maximum") Long maximum,
|
||||
@RequestParam("group_id") String groupId,
|
||||
KeycloakAuthenticationToken token) {
|
||||
@ -333,6 +374,7 @@ public class WebController {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@PostMapping("/details/members/deleteUser")
|
||||
@CacheEvict(value = "groups", allEntries = true)
|
||||
public String deleteUser(@RequestParam("group_id") String groupId,
|
||||
@RequestParam("user_id") String userId) throws EventException {
|
||||
User user = new User(userId, "", "", "");
|
||||
|
@ -11,8 +11,8 @@ import lombok.NoArgsConstructor;
|
||||
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
|
||||
public class User {
|
||||
|
||||
private String id;
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
private String id;
|
||||
private String givenname;
|
||||
private String familyname;
|
||||
private String email;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.data.relational.core.mapping.Table;
|
||||
public class InviteLinkDTO {
|
||||
|
||||
@Id
|
||||
Long link_id;
|
||||
Long invite_id;
|
||||
String group_id;
|
||||
String invite_link;
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class InvalidInviteException extends EventException {
|
||||
|
||||
public InvalidInviteException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Der Einladungslink ist ungültig.", info);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NoInviteExistException extends EventException {
|
||||
|
||||
public NoInviteExistException(String info) {
|
||||
super(HttpStatus.NOT_FOUND, "Für diese Gruppe existiert kein Link.", info);
|
||||
}
|
||||
}
|
@ -12,15 +12,12 @@ import java.util.List;
|
||||
//TODO Rename Queries + Formatting
|
||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||
|
||||
@Query("select distinct group_id from event where user_id =:id")
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE user_id = :id")
|
||||
List<String> findGroup_idsWhereUser_id(@Param("id") String userId);
|
||||
|
||||
@Query("select * from event where group_id =:id")
|
||||
@Query("SELECT * FROM event WHERE group_id = :id")
|
||||
List<EventDTO> findEventDTOByGroup_id(@Param("id") String groupId);
|
||||
|
||||
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
|
||||
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
@Query("SELECT DISTINCT group_id FROM event WHERE event_id > :status")
|
||||
List<String> findNewEventSinceStatus(@Param("status") Long status);
|
||||
|
||||
|
22
src/main/java/mops/gruppen2/repository/InviteRepository.java
Normal file
22
src/main/java/mops/gruppen2/repository/InviteRepository.java
Normal file
@ -0,0 +1,22 @@
|
||||
package mops.gruppen2.repository;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import org.springframework.data.jdbc.repository.query.Modifying;
|
||||
import org.springframework.data.jdbc.repository.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface InviteRepository extends CrudRepository<InviteLinkDTO, Long> {
|
||||
|
||||
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
||||
String findGroupIdByLink(@Param("link") String link);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM invite WHERE group_id = :group")
|
||||
void deleteLinkOfGroup(@Param("group") String group);
|
||||
|
||||
@Query("SELECT invite_link FROM invite WHERE group_id = :group")
|
||||
String findLinkByGroupId(@Param("group") String group);
|
||||
}
|
@ -47,8 +47,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
|
||||
proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public AccessToken getAccessToken() {
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder
|
||||
@ -61,14 +60,10 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
super.configure(http);
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.anyRequest()
|
||||
.permitAll()
|
||||
.and()
|
||||
.csrf()
|
||||
.ignoringAntMatchers("/gruppen2/createOrga")
|
||||
.ignoringAntMatchers("/gruppen2/details/members/addUsersFromCsv");
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,11 +38,13 @@ public class ControllerService {
|
||||
|
||||
private final EventService eventService;
|
||||
private final UserService userService;
|
||||
private final InviteService inviteService;
|
||||
private final Logger logger;
|
||||
|
||||
public ControllerService(EventService eventService, UserService userService) {
|
||||
public ControllerService(EventService eventService, UserService userService, InviteService inviteService) {
|
||||
this.eventService = eventService;
|
||||
this.userService = userService;
|
||||
this.inviteService = inviteService;
|
||||
this.logger = Logger.getLogger("controllerServiceLogger");
|
||||
}
|
||||
|
||||
@ -66,6 +68,8 @@ public class ControllerService {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
inviteService.createLink(groupId);
|
||||
|
||||
addUser(account, groupId);
|
||||
updateTitle(account, groupId, title);
|
||||
updateDescription(account, groupId, description);
|
||||
@ -129,6 +133,7 @@ public class ControllerService {
|
||||
}
|
||||
|
||||
private List<User> readCsvFile(MultipartFile file) throws EventException, IOException {
|
||||
if(file == null) return new ArrayList<>();
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
@ -221,6 +226,7 @@ public class ControllerService {
|
||||
|
||||
public void deleteGroupEvent(String userId, UUID groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
|
||||
inviteService.destroyLink(groupId);
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,6 @@ public class EventService {
|
||||
return translateEventDTOs(eventDTOList);
|
||||
}
|
||||
|
||||
//TODO: Nur AddUserEvents betrachten
|
||||
public List<UUID> findGroupIdsByUser(String userId) {
|
||||
return eventStore.findGroup_idsWhereUser_id(userId).stream()
|
||||
.map(UUID::fromString)
|
||||
|
@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -77,6 +78,7 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
@ -100,6 +102,7 @@ public class GroupService {
|
||||
*
|
||||
* @return List of groups
|
||||
*/
|
||||
@Cacheable("groups")
|
||||
public List<Group> getAllLecturesWithVisibilityPublic() {
|
||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||
@ -124,6 +127,7 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//Todo Rename
|
||||
@Cacheable("groups")
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
if (search.isEmpty()) {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
|
47
src/main/java/mops/gruppen2/service/InviteService.java
Normal file
47
src/main/java/mops/gruppen2/service/InviteService.java
Normal file
@ -0,0 +1,47 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||
import mops.gruppen2.domain.exception.InvalidInviteException;
|
||||
import mops.gruppen2.domain.exception.NoInviteExistException;
|
||||
import mops.gruppen2.repository.InviteRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class InviteService {
|
||||
|
||||
private final InviteRepository inviteRepository;
|
||||
|
||||
public InviteService(InviteRepository inviteRepository) {
|
||||
this.inviteRepository = inviteRepository;
|
||||
}
|
||||
|
||||
public void createLink(UUID groupId) {
|
||||
inviteRepository.save(new InviteLinkDTO(null, groupId.toString(), UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
public void destroyLink(UUID groupId) {
|
||||
inviteRepository.deleteLinkOfGroup(groupId.toString());
|
||||
}
|
||||
|
||||
public UUID getGroupIdFromLink(String link) {
|
||||
try {
|
||||
return UUID.fromString(inviteRepository.findGroupIdByLink(link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new InvalidInviteException(link);
|
||||
}
|
||||
|
||||
public String getLinkByGroupId(UUID groupId) {
|
||||
try {
|
||||
return inviteRepository.findLinkByGroupId(groupId.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
throw new NoInviteExistException(groupId.toString());
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -25,6 +26,7 @@ public class UserService {
|
||||
|
||||
//Test nötig??
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(User user) throws EventException {
|
||||
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
|
||||
List<Event> events = groupService.getGroupEvents(groupIds);
|
||||
@ -41,6 +43,11 @@ public class UserService {
|
||||
return newGroups;
|
||||
}
|
||||
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(String userId) throws EventException {
|
||||
return getUserGroups(new User(userId, null, null, null));
|
||||
}
|
||||
|
||||
public Group getGroupById(UUID groupId) throws EventException {
|
||||
List<UUID> groupIds = new ArrayList<>();
|
||||
groupIds.add(groupId);
|
||||
|
@ -62,6 +62,11 @@ public class ValidationService {
|
||||
}
|
||||
}
|
||||
|
||||
//Warum ist das überhaupt nötig smh
|
||||
public boolean checkIfUserInGroupWithoutNoAccessAcception(Group group, User user) {
|
||||
return group.getMembers().contains(user);
|
||||
}
|
||||
|
||||
public Group checkParent(UUID parentId) {
|
||||
Group parent = new Group();
|
||||
if (!controllerService.idIsEmpty(parentId)) {
|
||||
|
@ -19,3 +19,5 @@ keycloak.use-resource-role-mappings=true
|
||||
keycloak.autodetect-bearer-only=true
|
||||
keycloak.confidential-port=443
|
||||
server.error.include-stacktrace=always
|
||||
management.endpoints.web.exposure.include=info,health
|
||||
spring.cache.type=NONE
|
||||
|
@ -15,4 +15,5 @@ keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
|
||||
keycloak.verify-token-audience=true
|
||||
keycloak.use-resource-role-mappings=true
|
||||
keycloak.autodetect-bearer-only=true
|
||||
keycloak.confidential-port= 443
|
||||
keycloak.confidential-port=443
|
||||
management.endpoints.web.exposure.include=info,health
|
||||
|
@ -8,3 +8,12 @@ CREATE TABLE event
|
||||
event_type VARCHAR(32),
|
||||
event_payload VARCHAR(2500)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS invite;
|
||||
|
||||
CREATE TABLE invite
|
||||
(
|
||||
invite_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
group_id VARCHAR(36) NOT NULL,
|
||||
invite_link VARCHAR(36) NOT NULL
|
||||
);
|
||||
|
@ -40,7 +40,7 @@
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Metadaten ändern</h1>
|
||||
<form action="/gruppen2/details/changeMetadata" method="post">
|
||||
<form method="post" th:action="@{/gruppen2/details/changeMetadata}">
|
||||
<div class="shadow-sm p-2"
|
||||
style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<div class="form-group">
|
||||
|
@ -38,7 +38,8 @@
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/gruppen2/createOrga" enctype="multipart/form-data">
|
||||
<form enctype="multipart/form-data" method="post"
|
||||
th:action="@{/gruppen2/createOrga}">
|
||||
<div class="shadow-sm p-2"
|
||||
style=" border: 10px solid aliceblue; background: aliceblue">
|
||||
<div class="form-group">
|
||||
|
@ -37,8 +37,9 @@
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/gruppen2/createStudent">
|
||||
<div class="shadow-sm p-2" style=" border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
<form method="post" th:action="@{/gruppen2/createStudent}">
|
||||
<div class="shadow-sm p-2"
|
||||
style=" border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="titel">Titel</label>
|
||||
|
@ -57,7 +57,7 @@
|
||||
th:text="${parent.getTitle()}">Parent</span>
|
||||
|
||||
<div class="input-group mb-3" style="margin-top: 10px"
|
||||
th:if="${group.getVisibility() == group.getVisibility().PRIVATE}">
|
||||
th:if="${roles.get(user.getId()) == admin}">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="inputGroup-sizing-default"
|
||||
style="background: #52a1eb">Einladungslink:</span>
|
||||
@ -83,15 +83,16 @@
|
||||
style="background: #52a1eb; border: none; margin: 5px">
|
||||
<a style="color: white" th:href="@{/gruppen2}">Zurück</a>
|
||||
</button>
|
||||
<form action="/gruppen2/leaveGroup" method="post">
|
||||
<form method="post" th:action="@{/gruppen2/leaveGroup}">
|
||||
<button class="btn btn-danger" style="border-style: none; margin: 5px"
|
||||
th:name="group_id" th:value="${group.getId()}"
|
||||
type="submit">Gruppe verlassen
|
||||
</button>
|
||||
</form>
|
||||
<form action="/gruppen2/deleteGroup" method="post">
|
||||
<form method="post" th:action="@{/gruppen2/deleteGroup}">
|
||||
<button class="btn btn-danger" style="border-style: none; margin: 5px"
|
||||
th:name="group_id" th:value="${group.getId()}" th:if="${group.getRoles().get(user.getId()) == admin}"
|
||||
th:name="group_id" th:value="${group.getId()}"
|
||||
th:if="${group.getRoles().get(user.getId()) == admin}"
|
||||
type="submit">Gruppe löschen
|
||||
</button>
|
||||
</form>
|
||||
@ -132,7 +133,7 @@
|
||||
</div>
|
||||
<script>
|
||||
function copyLink() {
|
||||
var copyText = document.getElementById("groupLink");
|
||||
const copyText = document.getElementById("groupLink");
|
||||
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 99999);
|
||||
|
@ -50,7 +50,7 @@
|
||||
</div>
|
||||
<div class="form-group mt-2">
|
||||
<div class="text-right">
|
||||
<form method="post" action="/gruppen2/detailsBeitreten">
|
||||
<form method="post" th:action="@{/gruppen2/detailsBeitreten}">
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none;"
|
||||
th:href="@{/gruppen2/detailsBeitreten}"
|
||||
|
@ -48,16 +48,19 @@
|
||||
</div>
|
||||
<div class="shadow p-2" style="border: 10px solid aliceblue; background: aliceblue">
|
||||
<div class="form-group pt-4" th:if="${account.getRoles().contains('orga')}">
|
||||
<form action="/gruppen2/details/members/addUsersFromCsv"
|
||||
<form th:action="@{/gruppen2/details/members/addUsersFromCsv}"
|
||||
enctype="multipart/form-data"
|
||||
method="post">
|
||||
<div class="input-group mb-3">
|
||||
<div class="custom-file">
|
||||
<input class="custom-file-input" id="file" th:name="file" type="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von Mitgliedern hochladen</label>
|
||||
<input class="custom-file-input" id="file" th:name="file"
|
||||
type="file">
|
||||
<label class="custom-file-label" for="file">CSV Datei von
|
||||
Mitgliedern hochladen</label>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" style="background: #52a1eb; border-style: none"
|
||||
<button class="btn btn-outline-secondary"
|
||||
style="background: #52a1eb; border-style: none"
|
||||
th:name="group_id" th:value="${group.getId()}"
|
||||
type="submit">
|
||||
<a style="color: white">Hinzufügen</a>
|
||||
@ -67,12 +70,16 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="form-group pt-4">
|
||||
<form action="/gruppen2/details/members/changeMaximum" method="post">
|
||||
<form method="post" th:action="@{/gruppen2/details/members/changeMaximum}">
|
||||
<div class="input-group mb-3" id="userMaximum">
|
||||
<input class="form-control" placeholder="Maximale Teilnehmerzahl ändern..." th:name="maximum"
|
||||
type="number" th:min="${group.getMembers().size()}" max="10000">
|
||||
<input class="form-control"
|
||||
placeholder="Maximale Teilnehmerzahl ändern..."
|
||||
th:name="maximum"
|
||||
type="number" th:min="${group.getMembers().size()}"
|
||||
max="10000">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" style="background: #52a1eb; border-style: none"
|
||||
<button class="btn btn-outline-secondary"
|
||||
style="background: #52a1eb; border-style: none"
|
||||
th:name="group_id" th:value="${group.getId()}"
|
||||
type="submit">
|
||||
<a style="color: white">Speichern</a>
|
||||
@ -99,21 +106,27 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="text-right btn-toolbar" style="float: right;" role="toolbar">
|
||||
<form action="/gruppen2/details/members/changeRole" method="post">
|
||||
<form method="post"
|
||||
th:action="@{/gruppen2/details/members/changeRole}">
|
||||
<input th:name="group_id" th:value="${group.getId()}"
|
||||
type="hidden">
|
||||
<input th:name="user_id" th:value="${member.getId()}"
|
||||
type="hidden">
|
||||
<button class="btn btn-warning btn-sm" type="submit" style="margin: 5px">Rolle
|
||||
<button class="btn btn-warning btn-sm" type="submit"
|
||||
style="margin: 5px">Rolle
|
||||
ändern
|
||||
</button>
|
||||
</form>
|
||||
<form action="/gruppen2/details/members/deleteUser" method="post">
|
||||
<form method="post"
|
||||
th:action="@{/gruppen2/details/members/deleteUser}">
|
||||
<input th:name="group_id" th:value="${group.getId()}"
|
||||
type="hidden">
|
||||
<input th:name="user_id" th:value="${member.getId()}"
|
||||
type="hidden">
|
||||
<button class="btn btn-danger btn-sm" style="margin: 5px" th:if='!${account.getName().equals(member.getId())}'>Mitglied entfernen</button>
|
||||
<button class="btn btn-danger btn-sm" style="margin: 5px"
|
||||
th:if='!${account.getName().equals(member.getId())}'>
|
||||
Mitglied entfernen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -33,7 +33,7 @@
|
||||
<div class="row">
|
||||
<div class="col-10">
|
||||
<h1>Meine Gruppen</h1>
|
||||
<form action="/" method="get">
|
||||
<form method="get" th:action="@{/}">
|
||||
<h3 style="color: dodgerblue; font-weight: bold; font-optical-sizing: auto">
|
||||
<small style="font-weight: normal; color: black">Mitglied in </small>
|
||||
<small style="font-weight: bold; color: black"
|
||||
|
81
src/main/resources/templates/joinprivate.html
Normal file
81
src/main/resources/templates/joinprivate.html
Normal file
@ -0,0 +1,81 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Gruppendetails</title>
|
||||
<th:block th:fragment="headcontent">
|
||||
<!-- Links, Skripts, Styles hier einfügen! -->
|
||||
</th:block>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation"
|
||||
th:switch="${account.getRoles().contains('orga')}">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
|
||||
</li>
|
||||
<li th:case="${true}">
|
||||
<a href="/createOrga" th:href="@{/gruppen2/createOrga}">Erstellen</a>
|
||||
</li>
|
||||
<li th:case="${false}">
|
||||
<a href="/createStudent" th:href="@{/gruppen2/createStudent}">Erstellen</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<a href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-9">
|
||||
<div class="shadow-sm p-4"
|
||||
style="border: 1px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
<h1 style="color: black; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word"
|
||||
th:text="${group.getTitle()}"></h1>
|
||||
<h3>Möchtest du dieser privaten Gruppe beitreten?</h3>
|
||||
<div class="shadow-sm p-4" style="background: white">
|
||||
<p style="overflow-wrap: break-word; font-optical-sizing: auto"
|
||||
th:text="${group.getDescription()}"></p>
|
||||
</div>
|
||||
<div class="form-group mt-2">
|
||||
<div class="text-right">
|
||||
<form method="post" th:action="@{/gruppen2/acceptinvite}">
|
||||
<input name="id" th:value="${group.getId()}" type="hidden"/>
|
||||
<button class="btn btn-primary"
|
||||
style="background: #52a1eb; border-style: none;"
|
||||
type="submit">Ja, Gruppe beitreten
|
||||
</button>
|
||||
<a class="btn btn-primary"
|
||||
href="/gruppen2"
|
||||
style="background: #52a1eb; border-style: none;"
|
||||
type="submit">Ich will das nicht.
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3" style="white-space: nowrap">
|
||||
<div style="display: inline-block; margin: 0">
|
||||
<h2>Mitglieder</h2>
|
||||
<div th:switch="${group.getUserMaximum() != 100000}">
|
||||
<h4 th:case="${true}">
|
||||
<a th:text="${group.getMembers().size()}"></a>
|
||||
<a>von maximal</a>
|
||||
<a th:text="${group.getUserMaximum()}"></a>
|
||||
<a>Benutzern.</a>
|
||||
</h4>
|
||||
<h4 th:case="false">unbegrenzte Teilnehmeranzahl</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -35,7 +35,7 @@
|
||||
<h1>Gruppensuche</h1>
|
||||
<div class="shadow-sm p-2"
|
||||
style="border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
<form action="/gruppen2/findGroup" method="get">
|
||||
<form method="get" th:action="@{/gruppen2/findGroup}">
|
||||
<div class="form-group">
|
||||
<label for="suchleiste">Suchbegriff:</label>
|
||||
<input class="form-control" id="suchleiste"
|
||||
|
@ -29,11 +29,11 @@ public class TestBuilder {
|
||||
|
||||
public static Account account(String name) {
|
||||
return new Account(name,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
null);
|
||||
}
|
||||
|
||||
public static Group apply(Group group, Event... events) {
|
||||
@ -56,8 +56,8 @@ public class TestBuilder {
|
||||
*/
|
||||
public static UUID uuidFromInt(int id) {
|
||||
return UUID.fromString("00000000-0000-0000-0000-"
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,18 +69,18 @@ public class TestBuilder {
|
||||
*/
|
||||
public static List<Event> completePublicGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePublicGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePrivateGroups(int count, int membercount) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> completePrivateGroup(membercount))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> completePublicGroup(int membercount) {
|
||||
@ -123,25 +123,25 @@ public class TestBuilder {
|
||||
*/
|
||||
public static List<Event> createPublicGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createPrivateGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> createPublicGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Event> createMixedGroupEvents(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
|
||||
? createPublicGroupEvent()
|
||||
: createPrivateGroupEvent())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event createPrivateGroupEvent(UUID groupId) {
|
||||
@ -195,9 +195,9 @@ public class TestBuilder {
|
||||
*/
|
||||
public static List<Event> addUserEvents(int count, UUID groupId) {
|
||||
return IntStream.range(0, count)
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
.parallel()
|
||||
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event addUserEvent(UUID groupId, String userId) {
|
||||
@ -221,8 +221,8 @@ public class TestBuilder {
|
||||
public static List<Event> deleteUserEvents(int count, List<Event> eventList) {
|
||||
List<Event> removeEvents = new ArrayList<>();
|
||||
List<Event> shuffle = eventList.parallelStream()
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
.filter(event -> event instanceof AddUserEvent)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Collections.shuffle(shuffle);
|
||||
|
||||
@ -245,8 +245,8 @@ public class TestBuilder {
|
||||
*/
|
||||
public static List<Event> deleteUserEvents(Group group) {
|
||||
return group.getMembers().parallelStream()
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
.map(user -> deleteUserEvent(group.getId(), user.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Event deleteUserEvent(UUID groupId, String userId) {
|
||||
|
@ -1,80 +1,304 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import mops.gruppen2.Gruppen2Application;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Gruppen2Application.class)
|
||||
@Transactional
|
||||
@Rollback
|
||||
class ControllerServiceTest {
|
||||
Faker faker;
|
||||
Account account;
|
||||
Account account, account2, account3;
|
||||
ControllerService controllerService;
|
||||
EventService eventService;
|
||||
UserService userService;
|
||||
@Autowired
|
||||
EventRepository eventRepository;
|
||||
GroupService groupService;
|
||||
@Autowired
|
||||
JsonService jsonService;
|
||||
|
||||
|
||||
@Autowired
|
||||
InviteService inviteService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
jsonService = new JsonService();
|
||||
eventRepository = mock(EventRepository.class);
|
||||
eventService = new EventService(jsonService, eventRepository);
|
||||
groupService = new GroupService(eventService, eventRepository);
|
||||
userService = new UserService(groupService, eventService);
|
||||
controllerService = new ControllerService(eventService, userService);
|
||||
controllerService = new ControllerService(eventService, userService, inviteService);
|
||||
Set<String> roles = new HashSet<>();
|
||||
roles.add("l");
|
||||
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);
|
||||
account2 = new Account("ich2", "ich2@hhu.de", "l", "ichdude2", "jap2", roles);
|
||||
account3 = new Account("ich3", "ich3@hhu.de", "l", "ichdude3", "jap3", roles);
|
||||
eventRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupTest() {
|
||||
|
||||
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrga() {
|
||||
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", null, null, true, null, null);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
List<Group> groups = userService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addUser() {
|
||||
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", true, null, true, null, null);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
List<Group> groups = userService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addUserList() {
|
||||
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
|
||||
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, null);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
List<Group> groups = userService.getUserGroups(user);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTitle() {
|
||||
void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, true, true, null, null, null);
|
||||
User user = new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail());
|
||||
List<Group> groups1 = userService.getUserGroups(user);
|
||||
controllerService.createGroup(account, "test", "hi", true, null, null, 20L, groups1.get(0).getId());
|
||||
User user2 = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
List<Group> groups = userService.getUserGroups(user2);
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateDescription() {
|
||||
void createPublicGroupWithParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.createGroup(account, "test", "hi", null, null, null, 20L, groups1.get(0).getId());
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRoleTest() {
|
||||
|
||||
void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.createGroup(account, "test", "hi", null, true, true, null,groups1.get(0).getId());
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteUser() {
|
||||
void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account2, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups1 = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
controllerService.createGroup(account, "test", "hi", true, true, true, null, groups1.get(0).getId());
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertEquals(groups1.get(0).getId(), groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteGroupEvent() {
|
||||
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void passIfLastAdmin() {
|
||||
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, null, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", true, null, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrgaLectureGroupAndLimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, null, 20L, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
||||
controllerService.createGroupAsOrga(account, "test", "hi", null, true, true, null, null, null);
|
||||
List<Group> groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteUserTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||
assertTrue(userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail())).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRoleAdminTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.updateRole(account.getName(), groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRoleMemberTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()));
|
||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRoleNonUserTest() {
|
||||
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()));
|
||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.updateRole(account2.getName(), groups.get(0).getId()));
|
||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteNonUserTest() {
|
||||
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()));
|
||||
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.deleteUser(account2.getName(), groups.get(0).getId()));
|
||||
assertEquals("404 NOT_FOUND \"Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)\"", exception.getMessage());
|
||||
}
|
||||
|
||||
void testTitleAndDescription(String title, String description) {
|
||||
assertEquals("test", title);
|
||||
assertEquals("hi", description);
|
||||
}
|
||||
|
||||
@Test
|
||||
void passIfLastAdminTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
assertEquals(Role.ADMIN, groups.get(0).getRoles().get(account2.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dontPassIfNotLastAdminTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.updateRole(account2.getName(), groups.get(0).getId());
|
||||
controllerService.addUser(account3, groups.get(0).getId());
|
||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||
groups = userService.getUserGroups(new User(account2.getName(), account2.getGivenname(), account2.getFamilyname(), account2.getEmail()));
|
||||
assertEquals(Role.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getVeteranMemberTest() {
|
||||
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()));
|
||||
controllerService.addUser(account2, groups.get(0).getId());
|
||||
controllerService.addUser(account3, groups.get(0).getId());
|
||||
controllerService.passIfLastAdmin(account, groups.get(0).getId());
|
||||
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||
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.MEMBER, groups.get(0).getRoles().get(account3.getName()));
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +88,12 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getGroupEvents() {
|
||||
// CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
|
||||
// CreateGroupEvent test2 = new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.SIMPLE, Visibility.PUBLIC, 10L);
|
||||
//CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
|
||||
//CreateGroupEvent test2 = new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.SIMPLE, Visibility.PUBLIC, 10L);
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
createPrivateGroupEvent(uuidFromInt(2)));
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
createPrivateGroupEvent(uuidFromInt(2)));
|
||||
|
||||
List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1));
|
||||
|
||||
@ -117,52 +117,52 @@ class GroupServiceTest {
|
||||
Group group = TestBuilder.apply(test1, test2);
|
||||
|
||||
assertThat(group.getType()).isEqualTo(null);
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1")).isEmpty();
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestGroupPublic() {
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); //Wofür ist das
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); //Wofür ist das
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent());
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Wofür?
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Wofür?
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPrivateGroupEvent());
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPrivateGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "kobold"),
|
||||
createPrivateGroupEvent(),
|
||||
createPublicGroupEvent());
|
||||
addUserEvent(uuidFromInt(0), "kobold"),
|
||||
createPrivateGroupEvent(),
|
||||
createPublicGroupEvent());
|
||||
|
||||
//Das kommt glaube ich eher in einen Test für die Projektion
|
||||
//assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1);
|
||||
@ -173,34 +173,34 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllLecturesWithVisibilityPublic() {
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Hä
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Hä
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
|
||||
eventService.saveAll(createLectureEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent());
|
||||
createPublicGroupEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent());
|
||||
|
||||
assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findGroupWith_UserMember_AllGroups() {
|
||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
// eventService.saveEvent(new UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
|
||||
// eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
|
||||
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
//eventService.saveEvent(new UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
|
||||
//eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "jens"),
|
||||
updateGroupTitleEvent(uuidFromInt(0)),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0)));
|
||||
addUserEvent(uuidFromInt(0), "jens"),
|
||||
updateGroupTitleEvent(uuidFromInt(0)),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0)));
|
||||
|
||||
//assertThat(groupService.findGroupWith("T", new Account("jens", "a@A", "test", "peter", "mueller", null)).size()).isEqualTo(1);
|
||||
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
|
||||
@ -209,7 +209,7 @@ class GroupServiceTest {
|
||||
@Test
|
||||
void findGroupWith_UserNoMember_AllGroups() {
|
||||
eventService.saveAll(completePublicGroups(10, 0),
|
||||
completePrivateGroups(10, 0));
|
||||
completePrivateGroups(10, 0));
|
||||
|
||||
assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10);
|
||||
}
|
||||
@ -217,12 +217,12 @@ class GroupServiceTest {
|
||||
@Test
|
||||
void findGroupWith_FilterGroups() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
updateGroupTitleEvent(uuidFromInt(0), "KK"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
|
||||
createPrivateGroupEvent());
|
||||
updateGroupTitleEvent(uuidFromInt(0), "KK"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
|
||||
createPrivateGroupEvent());
|
||||
|
||||
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
|
||||
assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1);
|
||||
|
182
wait-for-it.sh
Normal file
182
wait-for-it.sh
Normal file
@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env bash
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << USAGE >&2
|
||||
Usage:
|
||||
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||
-h HOST | --host=HOST Host or IP under test
|
||||
-p PORT | --port=PORT TCP port under test
|
||||
Alternatively, you specify the host and port as host:port
|
||||
-s | --strict Only execute subcommand if the test succeeds
|
||||
-q | --quiet Don't output any status messages
|
||||
-t TIMEOUT | --timeout=TIMEOUT
|
||||
Timeout in seconds, zero for no timeout
|
||||
-- COMMAND ARGS Execute command with args after the test finishes
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_for()
|
||||
{
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
else
|
||||
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||
fi
|
||||
WAITFORIT_start_ts=$(date +%s)
|
||||
while :
|
||||
do
|
||||
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||
WAITFORIT_result=$?
|
||||
else
|
||||
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
WAITFORIT_result=$?
|
||||
fi
|
||||
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||
WAITFORIT_end_ts=$(date +%s)
|
||||
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return $WAITFORIT_result
|
||||
}
|
||||
|
||||
wait_for_wrapper()
|
||||
{
|
||||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
else
|
||||
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||
fi
|
||||
WAITFORIT_PID=$!
|
||||
trap "kill -INT -$WAITFORIT_PID" INT
|
||||
wait $WAITFORIT_PID
|
||||
WAITFORIT_RESULT=$?
|
||||
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
fi
|
||||
return $WAITFORIT_RESULT
|
||||
}
|
||||
|
||||
# process arguments
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
*:* )
|
||||
WAITFORIT_hostport=(${1//:/ })
|
||||
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||
shift 1
|
||||
;;
|
||||
--child)
|
||||
WAITFORIT_CHILD=1
|
||||
shift 1
|
||||
;;
|
||||
-q | --quiet)
|
||||
WAITFORIT_QUIET=1
|
||||
shift 1
|
||||
;;
|
||||
-s | --strict)
|
||||
WAITFORIT_STRICT=1
|
||||
shift 1
|
||||
;;
|
||||
-h)
|
||||
WAITFORIT_HOST="$2"
|
||||
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--host=*)
|
||||
WAITFORIT_HOST="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-p)
|
||||
WAITFORIT_PORT="$2"
|
||||
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--port=*)
|
||||
WAITFORIT_PORT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
-t)
|
||||
WAITFORIT_TIMEOUT="$2"
|
||||
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||
shift 2
|
||||
;;
|
||||
--timeout=*)
|
||||
WAITFORIT_TIMEOUT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
WAITFORIT_CLI=("$@")
|
||||
break
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown argument: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||
echoerr "Error: you need to provide a host and port to test."
|
||||
usage
|
||||
fi
|
||||
|
||||
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||
|
||||
# Check to see if timeout is from busybox?
|
||||
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
# Check if busybox timeout uses -t flag
|
||||
# (recent Alpine versions don't support -t anymore)
|
||||
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
fi
|
||||
else
|
||||
WAITFORIT_ISBUSY=0
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
exit $WAITFORIT_RESULT
|
||||
else
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
wait_for_wrapper
|
||||
WAITFORIT_RESULT=$?
|
||||
else
|
||||
wait_for
|
||||
WAITFORIT_RESULT=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
||||
exec "${WAITFORIT_CLI[@]}"
|
||||
else
|
||||
exit $WAITFORIT_RESULT
|
||||
fi
|
Reference in New Issue
Block a user