Fix InviteLink DB Schema + Implement Frontend InviteLink Handling
Co-authored-by: [Mahgs] <maxoerter@gmx.de> Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
@ -11,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.http.HttpStatus;
|
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.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
@ -33,13 +30,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +56,7 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
|
model.addAttribute("gruppen", userService.getUserGroups(user.getUser_id()));
|
||||||
model.addAttribute("user",user);
|
model.addAttribute("user", user);
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +71,11 @@ public class Gruppen2Controller {
|
|||||||
@GetMapping("/findGroup")
|
@GetMapping("/findGroup")
|
||||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
||||||
List<Group> groupse = new ArrayList<>();
|
List<Group> groupse = new ArrayList<>();
|
||||||
if(suchbegriff!=null) {
|
if (suchbegriff != null) {
|
||||||
groupse = groupService.findGroupWith(suchbegriff);
|
groupse = groupService.findGroupWith(suchbegriff);
|
||||||
}
|
}
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
model.addAttribute("gruppen",groupse);
|
model.addAttribute("gruppen", groupse);
|
||||||
return "search";
|
return "search";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,12 +94,12 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("/details")
|
@GetMapping("/details")
|
||||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @RequestParam (value="id") Long id) throws EventException, ResponseStatusException {
|
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException, ResponseStatusException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
Group group = userService.getGroupById(id);
|
Group group = userService.getGroupById(id);
|
||||||
Account account = keyCloakService.createAccountFromPrincipal (token);
|
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
if(group!= null) {
|
if (group != null) {
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("role", group.getRoles().get(user.getUser_id()));
|
model.addAttribute("role", group.getRoles().get(user.getUser_id()));
|
||||||
return "detailsMember";
|
return "detailsMember";
|
||||||
@ -110,14 +109,25 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||||
@GetMapping("/detailsSearch")
|
@GetMapping("/detailsSearch")
|
||||||
public String showGroupDetailsNoMember (KeycloakAuthenticationToken token, Model model, @RequestParam (value="id") Long id) throws EventException {
|
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
Group group = userService.getGroupById(id);
|
Group group = userService.getGroupById(id);
|
||||||
if (group!=null) {
|
if (group != null) {
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
return "detailsNoMember";
|
return "detailsNoMember";
|
||||||
}
|
}
|
||||||
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,16 @@
|
|||||||
package mops.gruppen2.domain.dto;
|
package mops.gruppen2.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.relational.core.mapping.Table;
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
@Table("invite")
|
@Table("invite")
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
public class InviteLinkDTO {
|
public class InviteLinkDTO {
|
||||||
@Id
|
@Id
|
||||||
private Long group_id;
|
Long link_id;
|
||||||
private String invite_link;
|
Long group_id;
|
||||||
|
String invite_link;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,11 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface InviteLinkRepository extends CrudRepository<InviteLinkDTO, String> {
|
public interface InviteLinkRepository extends CrudRepository<InviteLinkDTO, Long> {
|
||||||
@Query("select invite_link from inviteLink where group_id =:id")
|
|
||||||
String findLinkByGroupID(@Param("id") Long GroupID);
|
//@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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,14 +11,17 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,25 +34,31 @@ 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) {
|
||||||
|
Long groupID = eventService.checkGroup();
|
||||||
Visibility visibility1;
|
Visibility visibility1;
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
visibility1 = Visibility.PUBLIC;
|
visibility1 = Visibility.PUBLIC;
|
||||||
} else {
|
} else {
|
||||||
visibility1 = Visibility.PRIVATE;
|
visibility1 = Visibility.PRIVATE;
|
||||||
|
createInviteLink(groupID);
|
||||||
}
|
}
|
||||||
List<Event> eventList = new ArrayList<>();
|
List<Event> eventList = new ArrayList<>();
|
||||||
Collections.addAll(eventList, new CreateGroupEvent(eventService.checkGroup(), account.getName(), null , GroupType.LECTURE, visibility1),
|
Collections.addAll(eventList, new CreateGroupEvent(groupID, account.getName(), null, GroupType.LECTURE, visibility1),
|
||||||
new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()),
|
new AddUserEvent(groupID, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()),
|
||||||
new UpdateRoleEvent(eventService.checkGroup(), account.getName(), Role.ADMIN),
|
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN),
|
||||||
new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title),
|
new UpdateGroupTitleEvent(groupID, account.getName(), title),
|
||||||
new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), description),
|
new UpdateGroupDescriptionEvent(groupID, account.getName(), description),
|
||||||
new UpdateRoleEvent(eventService.checkGroup(),account.getName(), Role.ADMIN));
|
new UpdateRoleEvent(groupID, account.getName(), Role.ADMIN));
|
||||||
|
|
||||||
eventService.saveEventList(eventList);
|
eventService.saveEventList(eventList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(Account account, Group group){
|
private void createInviteLink(Long group_id) {
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(),group.getId(),account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUser(Account account, Group group) {
|
||||||
|
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), group.getId(), account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||||
eventService.saveEvent(addUserEvent);
|
eventService.saveEvent(addUserEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,19 @@
|
|||||||
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
|
||||||
keycloak.verify-token-audience=true
|
keycloak.verify-token-audience=true
|
||||||
keycloak.use-resource-role-mappings=true
|
keycloak.use-resource-role-mappings=true
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ DROP TABLE IF EXISTS invite;
|
|||||||
|
|
||||||
CREATE TABLE invite
|
CREATE TABLE invite
|
||||||
(
|
(
|
||||||
group_id INT FOREIGN KEY REFERENCES event(group_id),
|
link_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
invite_link varchar(255)
|
group_id INT NOT NULL,
|
||||||
)
|
invite_link varchar(255) NOT NULL
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user