Merge pull request #112 from hhu-propra2/delete-group-event
Delete group event
This commit is contained in:
@ -174,6 +174,9 @@ public class Gruppen2Controller {
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
Long parentId = group.getParent();
|
||||
Group parent = new Group();
|
||||
if(group.getTitle() == null){
|
||||
throw new GroupNotFoundException(this.getClass().toString());
|
||||
}
|
||||
if (parentId != null) {
|
||||
parent = userService.getGroupById(parentId);
|
||||
}
|
||||
@ -244,6 +247,18 @@ public class Gruppen2Controller {
|
||||
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
|
||||
controllerService.passIfLastAdmin(account, 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/";
|
||||
}
|
||||
|
||||
@ -283,9 +298,12 @@ public class Gruppen2Controller {
|
||||
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@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 {
|
||||
controllerService.deleteUser(userId, groupId);
|
||||
if(userService.getGroupById(groupId).getMembers().size() == 0){
|
||||
controllerService.deleteGroupEvent(userId ,groupId);
|
||||
}
|
||||
return "redirect:/gruppen2/details/members/" + groupId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
|
||||
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
|
||||
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
|
||||
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
|
||||
@JsonSubTypes.Type(value = DeleteGroupEvent.class, name = "DeleteGroupEvent")
|
||||
})
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
|
||||
@ -159,8 +159,8 @@ public class ControllerService {
|
||||
eventService.saveEvent(deleteUserEvent);
|
||||
}
|
||||
|
||||
public void deleteGroupEvent(User user, Long groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user.getId());
|
||||
public void deleteGroupEvent(String user_id, Long groupId) {
|
||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
|
||||
eventService.saveEvent(deleteGroupEvent);
|
||||
}
|
||||
|
||||
|
||||
@ -102,6 +102,9 @@ public class GroupService {
|
||||
List<Group> visibleGroups = projectEventList(eventsVisible);
|
||||
List<Group> visibleLectures = new ArrayList<>();
|
||||
for (Group group : visibleGroups) {
|
||||
if(group.getType() == null){
|
||||
continue;
|
||||
}
|
||||
if (group.getType().equals(GroupType.LECTURE)) {
|
||||
visibleLectures.add(group);
|
||||
}
|
||||
@ -121,6 +124,9 @@ public class GroupService {
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
List<Group> groups = new ArrayList<>();
|
||||
for (Group group : getAllGroupWithVisibilityPublic(account.getName())) {
|
||||
if(group.getType() == null){
|
||||
continue;
|
||||
}
|
||||
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) {
|
||||
groups.add(group);
|
||||
}
|
||||
|
||||
@ -59,6 +59,12 @@
|
||||
type="submit">Gruppe verlassen
|
||||
</button>
|
||||
</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 class="col-3" style="white-space: nowrap">
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
type="hidden">
|
||||
<input th:name="user_id" th:value="${member.getId()}"
|
||||
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>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user