1

fix-search after leaving group

This commit is contained in:
killerber4t
2020-03-19 14:14:54 +01:00
parent 8291b5c41e
commit 22bfcf3a05
4 changed files with 27 additions and 14 deletions

View File

@ -226,7 +226,9 @@ public class Gruppen2Controller {
@PostMapping("/details/members/changeRole")
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
@RequestParam("user_id") String userId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
controllerService.updateRole(userId, groupId);
if(userId.equals(account.getName())) return "redirect:/gruppen2/details/" + groupId;
return "redirect:/gruppen2/details/members/" + groupId;
}

View File

@ -3,14 +3,16 @@ package mops.gruppen2.domain;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User {
private final String id;
private final String givenname;
private final String familyname;
private final String email;
private String id;
private String givenname;
private String familyname;
private String email;
}

View File

@ -1,6 +1,7 @@
package mops.gruppen2.service;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException;
@ -66,11 +67,11 @@ public class GroupService {
return groups.get(groupId);
}
private List<Long> removeUserGroups(List<Long> groupIds, List<Long> userGroups) {
for (Long groupId : userGroups) {
groupIds.remove(groupId);
private List<Group> removeUserGroups(List<Group> visibleGroups, List<Group> userGroups) {
for (Group group : userGroups) {
visibleGroups.remove(group);
}
return groupIds;
return visibleGroups;
}
/**
@ -81,10 +82,18 @@ public class GroupService {
* @throws EventException Projektionsfehler
*/
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Long> groupIds = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(userId));
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(groupIds);
List<Event> events = eventService.translateEventDTOs(eventDTOS);
return projectEventList(events);
User user = new User(userId,null, null, null);
List<Event> eventsVisible = eventService.translateEventDTOs(eventRepository.findAllEventsOfGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE)));
List<Group> visibleGroups = projectEventList(eventsVisible);
List<Event> eventsUser = getGroupEvents(eventRepository.findGroup_idsWhereUser_id(userId));
List<Group> groups = projectEventList(eventsUser);
List<Group> newGroups = new ArrayList<>();
for (Group group : groups) {
if (group.getMembers().contains(user)) {
newGroups.add(group);
}
}
return removeUserGroups(visibleGroups, newGroups);
}