1

Merge pull request #68 from hhu-propra2/group-details

Group details
This commit is contained in:
kasch309
2020-03-13 16:50:47 +01:00
committed by GitHub
10 changed files with 123 additions and 14 deletions

View File

@ -2,22 +2,21 @@ package mops.gruppen2.controller;
import mops.gruppen2.config.Gruppen2Config;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.GroupType;
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.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.*;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import javax.annotation.security.RolesAllowed;
import java.util.Set;
@Controller
@RequestMapping("/gruppen2")
@ -83,4 +82,20 @@ public class Gruppen2Controller {
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @RequestParam (value="id") Long id) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
Account account = keyCloakService.createAccountFromPrincipal (token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Role role = group.getRoles().get(user);
if(group!= null) {
model.addAttribute("group", group);
model.addAttribute("role",role);
return "detailsMember";
}
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
}
}

View File

@ -13,4 +13,4 @@ import java.util.List;
public class UpdatedGroupRequestMapper {
private Long status;
private List<Group> groupList;
}
}

View File

@ -17,9 +17,10 @@ public class UpdateRoleEvent extends Event {
super(event_id, group_id, user_id);
this.newRole = newRole;
}
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
super(group_id, user_id);
this.newRole = newRole;
}
}

View File

@ -33,7 +33,8 @@ public class ControllerService {
new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()),
new UpdateRoleEvent(eventService.checkGroup(), account.getName(), Role.ADMIN),
new UpdateGroupTitleEvent(eventService.checkGroup(), account.getName(), title),
new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), description));
new UpdateGroupDescriptionEvent(eventService.checkGroup(), account.getName(), description),
new UpdateRoleEvent(eventService.checkGroup(),account.getName(), Role.ADMIN));
eventService.saveEventList(eventList);
}

View File

@ -6,6 +6,7 @@ import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
@ -26,4 +27,11 @@ public class UserService {
List<Event> events = groupService.getGroupEvents(group_ids);
return groupService.projectEventList(events);
}
public Group getGroupById(Long group_id) throws EventException {
List<Long> group_ids = new ArrayList<>();
group_ids.add(group_id);
List<Event> events = groupService.getGroupEvents(group_ids);
return groupService.projectEventList(events).get(0);
}
}