Merge pull request #93 from hhu-propra2/group-invite-links
added Group invite links
This commit is contained in:
@ -3,7 +3,6 @@ package mops.gruppen2.controller;
|
|||||||
import mops.gruppen2.config.Gruppen2Config;
|
import mops.gruppen2.config.Gruppen2Config;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
|
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
@ -14,17 +13,13 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
import org.springframework.web.context.annotation.SessionScope;
|
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@SessionScope
|
|
||||||
@RequestMapping("/gruppen2")
|
@RequestMapping("/gruppen2")
|
||||||
public class Gruppen2Controller {
|
public class Gruppen2Controller {
|
||||||
|
|
||||||
@ -36,13 +31,15 @@ public class Gruppen2Controller {
|
|||||||
private final GroupService groupService;
|
private final GroupService groupService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final ControllerService controllerService;
|
private final ControllerService controllerService;
|
||||||
|
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||||
|
|
||||||
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService) {
|
public Gruppen2Controller(KeyCloakService keyCloakService, EventService eventService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
||||||
this.keyCloakService = keyCloakService;
|
this.keyCloakService = keyCloakService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.controllerService = controllerService;
|
this.controllerService = controllerService;
|
||||||
|
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +80,6 @@ public class Gruppen2Controller {
|
|||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/createGroup")
|
@PostMapping("/createGroup")
|
||||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||||
@RequestParam(value = "title") String title,
|
@RequestParam(value = "title") String title,
|
||||||
@ -91,11 +87,7 @@ public class Gruppen2Controller {
|
|||||||
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
@RequestParam(value = "visibility", required = false) Boolean visibility) {
|
||||||
|
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
if (visibility == null) {
|
visibility = visibility == null;
|
||||||
visibility = true;
|
|
||||||
}else{
|
|
||||||
visibility = false;
|
|
||||||
}
|
|
||||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||||
|
|
||||||
return "redirect:/gruppen2/";
|
return "redirect:/gruppen2/";
|
||||||
@ -137,6 +129,17 @@ public class Gruppen2Controller {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
|
@GetMapping("/acceptinvite/{link}")
|
||||||
|
public String acceptInvite(KeycloakAuthenticationToken token, Model model, @PathVariable String link) throws EventException {
|
||||||
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
|
Group group = userService.getGroupById(inviteLinkRepositoryService.findGroupIdByInvite(link));
|
||||||
|
if (group != null) {
|
||||||
|
model.addAttribute("group", group);
|
||||||
|
return "redirect:/gruppen2/detailsSearch?id=" + group.getId();
|
||||||
|
}
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||||
|
}
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@PostMapping("/leaveGroup")
|
@PostMapping("/leaveGroup")
|
||||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) {
|
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package mops.gruppen2.domain;
|
package mops.gruppen2.domain.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
16
src/main/java/mops/gruppen2/domain/dto/InviteLinkDTO.java
Normal file
16
src/main/java/mops/gruppen2/domain/dto/InviteLinkDTO.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package mops.gruppen2.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
@Table("invite")
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InviteLinkDTO {
|
||||||
|
@Id
|
||||||
|
Long link_id;
|
||||||
|
Long group_id;
|
||||||
|
String invite_link;
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package mops.gruppen2.repository;
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
import org.springframework.data.jdbc.repository.query.Query;
|
import org.springframework.data.jdbc.repository.query.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||||
|
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 InviteLinkRepository extends CrudRepository<InviteLinkDTO, Long> {
|
||||||
|
|
||||||
|
//@Query("SELECT invite_link FROM invite WHERE group_id = :id")
|
||||||
|
//String findLinkByGroupID(@Param("id") Long GroupID);
|
||||||
|
|
||||||
|
@Query("SELECT group_id FROM invite WHERE invite_link = :link")
|
||||||
|
Long findGroupIdByLink(@Param("link") String link);
|
||||||
|
}
|
||||||
@ -7,15 +7,21 @@ import mops.gruppen2.domain.Visibility;
|
|||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.util.*;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ControllerService {
|
public class ControllerService {
|
||||||
|
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final InviteLinkRepositoryService inviteLinkRepositoryService;
|
||||||
|
|
||||||
public ControllerService(EventService eventService) {
|
public ControllerService(EventService eventService, InviteLinkRepositoryService inviteLinkRepositoryService) {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
|
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,13 +34,13 @@ public class ControllerService {
|
|||||||
* @param description Gruppenbeschreibung
|
* @param description Gruppenbeschreibung
|
||||||
*/
|
*/
|
||||||
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
public void createGroup(Account account, String title, String description, Boolean visibility) {
|
||||||
Visibility visibility1;
|
|
||||||
Long group_id = eventService.checkGroup();
|
Long group_id = eventService.checkGroup();
|
||||||
|
Visibility visibility1;
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
visibility1 = Visibility.PUBLIC;
|
visibility1 = Visibility.PUBLIC;
|
||||||
} else {
|
} else {
|
||||||
visibility1 = Visibility.PRIVATE;
|
visibility1 = Visibility.PRIVATE;
|
||||||
|
createInviteLink(group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null , GroupType.LECTURE, visibility1);
|
||||||
@ -46,6 +52,11 @@ public class ControllerService {
|
|||||||
updateRole(account, group_id);
|
updateRole(account, group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createInviteLink(Long group_id) {
|
||||||
|
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addUser(Account account, Long group_id){
|
public void addUser(Account account, Long group_id){
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
AddUserEvent addUserEvent = new AddUserEvent(group_id,account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||||
eventService.saveEvent(addUserEvent);
|
eventService.saveEvent(addUserEvent);
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import mops.gruppen2.domain.EventDTO;
|
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
|
import mops.gruppen2.domain.dto.InviteLinkDTO;
|
||||||
|
import mops.gruppen2.repository.InviteLinkRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class InviteLinkRepositoryService {
|
||||||
|
|
||||||
|
private final InviteLinkRepository inviteLinkRepository;
|
||||||
|
|
||||||
|
public InviteLinkRepositoryService(InviteLinkRepository inviteLinkRepository) {
|
||||||
|
this.inviteLinkRepository = inviteLinkRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long findGroupIdByInvite(String link) {
|
||||||
|
return inviteLinkRepository.findGroupIdByLink(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveInvite(Long group_id, UUID link) {
|
||||||
|
inviteLinkRepository.save(new InviteLinkDTO(null, group_id, link.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,7 +2,6 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import mops.gruppen2.domain.EventDTO;
|
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|||||||
@ -1,18 +1,16 @@
|
|||||||
server.port=8080
|
server.port=8080
|
||||||
application.name=gruppen2
|
application.name=gruppen2
|
||||||
|
|
||||||
logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n
|
logging.pattern.console=[${application.name}],%magenta(%-5level), %d{dd-MM-yyyy HH:mm:ss.SSS}, %highlight(%msg),%thread,%logger.%M%n
|
||||||
|
|
||||||
spring.datasource.url=jdbc:h2:mem:blogdb
|
spring.datasource.url=jdbc:h2:mem:blogdb
|
||||||
spring.datasource.driverClassName=org.h2.Driver
|
spring.datasource.driverClassName=org.h2.Driver
|
||||||
spring.datasource.username=sa
|
spring.datasource.username=sa
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||||
|
spring.h2.console.enabled=true
|
||||||
|
logging.level.org.springframework.jdbc.core=DEBUG
|
||||||
keycloak.principal-attribute=preferred_username
|
keycloak.principal-attribute=preferred_username
|
||||||
keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
|
keycloak.auth-server-url=https://keycloak.cs.hhu.de/auth
|
||||||
keycloak.realm=MOPS
|
keycloak.realm=MOPS
|
||||||
|
|
||||||
hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token
|
hhu_keycloak.token-uri=https://keycloak.cs.hhu.de/auth/realms/MOPS/protocol/openid-connect/token
|
||||||
keycloak.resource=gruppenfindung
|
keycloak.resource=gruppenfindung
|
||||||
keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
|
keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
|
||||||
|
|||||||
@ -10,3 +10,12 @@ CREATE TABLE event
|
|||||||
event_payload VARCHAR(255),
|
event_payload VARCHAR(255),
|
||||||
visibility BOOLEAN
|
visibility BOOLEAN
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS invite;
|
||||||
|
|
||||||
|
CREATE TABLE invite
|
||||||
|
(
|
||||||
|
link_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
group_id INT NOT NULL,
|
||||||
|
invite_link varchar(255) NOT NULL
|
||||||
|
);
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
import mops.gruppen2.domain.event.AddUserEvent;
|
import mops.gruppen2.domain.event.AddUserEvent;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
@ -14,7 +14,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user