Merge branch 'master' into edit-User
This commit is contained in:
@ -3,9 +3,9 @@ package mops.gruppen2.controller;
|
||||
import mops.gruppen2.config.Gruppen2Config;
|
||||
import mops.gruppen2.domain.Exceptions.EventException;
|
||||
import mops.gruppen2.domain.Group;
|
||||
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||
import mops.gruppen2.security.Account;
|
||||
@ -18,14 +18,15 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Controller
|
||||
@SessionScope
|
||||
@RequestMapping("/gruppen2")
|
||||
@ -39,13 +40,15 @@ public class Gruppen2Controller {
|
||||
private final GroupService groupService;
|
||||
private final UserService userService;
|
||||
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.eventService = eventService;
|
||||
this.groupService = groupService;
|
||||
this.userService = userService;
|
||||
this.controllerService = controllerService;
|
||||
this.inviteLinkRepositoryService = inviteLinkRepositoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,18 +58,40 @@ public class Gruppen2Controller {
|
||||
* @param model tolles model
|
||||
* @return index.html
|
||||
*/
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("gruppen", userService.getUserGroups(user));
|
||||
model.addAttribute("user",user);
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@GetMapping("/createLecture")
|
||||
public String createLecture(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
return "createLecture";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
|
||||
@PostMapping("/createLecture")
|
||||
public String pCreateLecture(KeycloakAuthenticationToken token,
|
||||
@RequestParam(value = "title") String title,
|
||||
@RequestParam(value = "beschreibung") String beschreibung,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("file") MultipartFile file) throws IOException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<User> userList = CsvService.read(file.getInputStream());
|
||||
visibility = visibility == null;
|
||||
controllerService.createLecture(account, title, beschreibung, visibility, userList);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/createGroup")
|
||||
public String createGroup(KeycloakAuthenticationToken token, Model model) {
|
||||
@ -74,18 +99,21 @@ public class Gruppen2Controller {
|
||||
return "create";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@GetMapping("/findGroup")
|
||||
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
List<Group> groupse = new ArrayList<>();
|
||||
if(suchbegriff!=null) {
|
||||
groupse = groupService.findGroupWith(suchbegriff);
|
||||
if (suchbegriff != null) {
|
||||
groupse = groupService.findGroupWith(suchbegriff,account);
|
||||
}
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("gruppen",groupse);
|
||||
model.addAttribute("gruppen", groupse);
|
||||
return "search";
|
||||
}
|
||||
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/createGroup")
|
||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam(value = "title") String title,
|
||||
@ -93,11 +121,7 @@ public class Gruppen2Controller {
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
if (visibility == null) {
|
||||
visibility = true;
|
||||
} else {
|
||||
visibility = false;
|
||||
}
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
@ -106,11 +130,12 @@ public class Gruppen2Controller {
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("/details/{id}")
|
||||
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable (value="id") Long id) throws EventException, ResponseStatusException {
|
||||
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
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());
|
||||
if(group!= null) {
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
model.addAttribute("roles", group.getRoles());
|
||||
model.addAttribute("user", user);
|
||||
@ -120,7 +145,7 @@ public class Gruppen2Controller {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@PostMapping("/detailsBeitreten")
|
||||
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "id") Long id) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
@ -132,19 +157,31 @@ public class Gruppen2Controller {
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
|
||||
@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));
|
||||
Group group = userService.getGroupById(id);
|
||||
if (group!=null) {
|
||||
if (group != null) {
|
||||
model.addAttribute("group", group);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
|
||||
}
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@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"})
|
||||
@PostMapping("/leaveGroup")
|
||||
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam (value="group_id") Long id) throws EventException {
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
@ -182,5 +219,10 @@ public class Gruppen2Controller {
|
||||
@RequestParam (value = "user_id") String user_id) throws EventException {
|
||||
controllerService.deleteUser(user_id, group_id);
|
||||
return "redirect:/gruppen2/details/members/" + group_id;
|
||||
|
||||
@GetMapping("*")
|
||||
public String defaultLink() {
|
||||
return "errorRenameLater";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user