1

Merge pull request #112 from hhu-propra2/delete-group-event

Delete group event
This commit is contained in:
Talha Caliskan
2020-03-20 14:05:29 +01:00
committed by GitHub
6 changed files with 35 additions and 4 deletions

View File

@ -174,6 +174,9 @@ public class Gruppen2Controller {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Long parentId = group.getParent(); Long parentId = group.getParent();
Group parent = new Group(); Group parent = new Group();
if(group.getTitle() == null){
throw new GroupNotFoundException(this.getClass().toString());
}
if (parentId != null) { if (parentId != null) {
parent = userService.getGroupById(parentId); parent = userService.getGroupById(parentId);
} }
@ -244,6 +247,18 @@ public class Gruppen2Controller {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.passIfLastAdmin(account, groupId); controllerService.passIfLastAdmin(account, groupId);
controllerService.deleteUser(user.getId(), groupId); controllerService.deleteUser(user.getId(), groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(user.getId(), groupId);
}
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/deleteGroup")
public String pDeleteGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId){
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.deleteGroupEvent(user.getId(), groupId);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -283,9 +298,12 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser") @PostMapping("/details/members/deleteUser")
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId, public String deleteUser(@RequestParam("group_id") Long groupId,
@RequestParam("user_id") String userId) throws EventException { @RequestParam("user_id") String userId) throws EventException {
controllerService.deleteUser(userId, groupId); controllerService.deleteUser(userId, groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(userId ,groupId);
}
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
} }

View File

@ -21,6 +21,7 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"), @JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"), @JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"), @JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
@JsonSubTypes.Type(value = DeleteGroupEvent.class, name = "DeleteGroupEvent")
}) })
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor

View File

@ -159,8 +159,8 @@ public class ControllerService {
eventService.saveEvent(deleteUserEvent); eventService.saveEvent(deleteUserEvent);
} }
public void deleteGroupEvent(User user, Long groupId) { public void deleteGroupEvent(String user_id, Long groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user.getId()); DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
eventService.saveEvent(deleteGroupEvent); eventService.saveEvent(deleteGroupEvent);
} }

View File

@ -102,6 +102,9 @@ public class GroupService {
List<Group> visibleGroups = projectEventList(eventsVisible); List<Group> visibleGroups = projectEventList(eventsVisible);
List<Group> visibleLectures = new ArrayList<>(); List<Group> visibleLectures = new ArrayList<>();
for (Group group : visibleGroups) { for (Group group : visibleGroups) {
if(group.getType() == null){
continue;
}
if (group.getType().equals(GroupType.LECTURE)) { if (group.getType().equals(GroupType.LECTURE)) {
visibleLectures.add(group); visibleLectures.add(group);
} }
@ -121,6 +124,9 @@ public class GroupService {
public List<Group> findGroupWith(String search, Account account) throws EventException { public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
for (Group group : getAllGroupWithVisibilityPublic(account.getName())) { for (Group group : getAllGroupWithVisibilityPublic(account.getName())) {
if(group.getType() == null){
continue;
}
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) { if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) {
groups.add(group); groups.add(group);
} }

View File

@ -59,6 +59,12 @@
type="submit">Gruppe verlassen type="submit">Gruppe verlassen
</button> </button>
</form> </form>
<form action="/gruppen2/deleteGroup" method="post">
<button class="btn btn-danger" style="border-style: none; margin: 5px"
th:name="group_id" th:value="${group.getId()}"
type="submit">Gruppe löschen
</button>
</form>
</div> </div>
</div> </div>
<div class="col-3" style="white-space: nowrap"> <div class="col-3" style="white-space: nowrap">

View File

@ -99,7 +99,7 @@
type="hidden"> type="hidden">
<input th:name="user_id" th:value="${member.getId()}" <input th:name="user_id" th:value="${member.getId()}"
type="hidden"> type="hidden">
<button class="btn btn-danger btn-sm" style="margin: 5px">Mitglied entfernen</button> <button class="btn btn-danger btn-sm" style="margin: 5px" th:if='!${account.getName().equals(member.getId())}'>Mitglied entfernen</button>
</form> </form>
</div> </div>
</td> </td>