From 59bea22d8e09412c9f5bffe69631b3f42fecde2f Mon Sep 17 00:00:00 2001 From: XXNitram Date: Tue, 24 Mar 2020 14:34:52 +0100 Subject: [PATCH] Add changeMetadata feature Co-Authored-By: andibuls Co-Authored-By: Max Oerter Co-Authored-By: Christoph --- .../controller/Gruppen2Controller.java | 42 +++++++++++ .../resources/templates/changeMetadata.html | 71 +++++++++++++++++++ .../resources/templates/detailsMember.html | 7 +- 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/templates/changeMetadata.html diff --git a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java index 88abfd9..c58ec42 100644 --- a/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java +++ b/src/main/java/mops/gruppen2/controller/Gruppen2Controller.java @@ -6,6 +6,7 @@ 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.UpdateGroupTitleEvent; import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.WrongFileException; @@ -173,6 +174,47 @@ public class Gruppen2Controller { return "redirect:/gruppen2/details/members/" + groupId; } + @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) + @GetMapping("/details/changeMetadata/{id}") + public String changeMetadata(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) { + Account account = keyCloakService.createAccountFromPrincipal(token); + User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); + Group group = userService.getGroupById(groupId); + model.addAttribute("account", account); + Long parentId = group.getParent(); + Group parent = new Group(); + if (!group.getMembers().contains(user)) { + if (group.getVisibility() == Visibility.PRIVATE) { + return "privateGroupNoMember"; + } + model.addAttribute("group", group); + model.addAttribute("parentId", parentId); + model.addAttribute("parent", parent); + return "detailsNoMember"; + } + model.addAttribute("title", group.getTitle()); + model.addAttribute("description", group.getDescription()); + model.addAttribute("admin", Role.ADMIN); + model.addAttribute("roles", group.getRoles()); + model.addAttribute("groupId", group.getId()); + model.addAttribute("user", user); + return "changeMetadata"; + } + + @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) + @PostMapping("/details/changeMetadata") + public String pChangeMetadata(KeycloakAuthenticationToken token, + @RequestParam("title") String title, + @RequestParam("description") String description, + @RequestParam("groupId") Long groupId) throws EventException { + + Account account = keyCloakService.createAccountFromPrincipal(token); + controllerService.updateTitle(account, groupId, title); + controllerService.updateDescription(account, groupId, description); + + return "redirect:/gruppen2/details/" + groupId; + } + @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"}) @GetMapping("/findGroup") public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException { diff --git a/src/main/resources/templates/changeMetadata.html b/src/main/resources/templates/changeMetadata.html new file mode 100644 index 0000000..dd02353 --- /dev/null +++ b/src/main/resources/templates/changeMetadata.html @@ -0,0 +1,71 @@ + + + + + Gruppenerstellung + + + + + + + + + +
+ +
+
+
+
+
+

Metadaten ändern

+
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/detailsMember.html b/src/main/resources/templates/detailsMember.html index b8f0ae4..15d1490 100644 --- a/src/main/resources/templates/detailsMember.html +++ b/src/main/resources/templates/detailsMember.html @@ -32,7 +32,12 @@
-

+
+

+ Ändern + +

Private Gruppe