1
Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-27 12:57:47 +01:00
parent cc64943663
commit 56a81ce66f
7 changed files with 26 additions and 25 deletions

View File

@ -2,6 +2,7 @@ package mops.gruppen2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
@SpringBootApplication
@EnableCaching
@EnableSwagger2
public class Gruppen2Application {

View File

@ -13,6 +13,7 @@ import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService;
import mops.gruppen2.service.ValidationService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@ -80,6 +81,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/createOrga")
@CacheEvict(value = "groups", allEntries = true)
public String postCrateGroupAsOrga(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@ -110,6 +112,7 @@ public class WebController {
@RolesAllowed({"ROLE_studentin"})
@PostMapping("/createStudent")
@CacheEvict(value = "groups", allEntries = true)
public String postCreateGroupAsStudent(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@ -127,6 +130,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv")
@CacheEvict(value = "groups", allEntries = true)
public String addUsersFromCsv(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
@ -166,6 +170,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/details/changeMetadata")
@CacheEvict(value = "groups", allEntries = true)
public String pChangeMetadata(KeycloakAuthenticationToken token,
@RequestParam("title") String title,
@RequestParam("description") String description,
@ -232,6 +237,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten")
@CacheEvict(value = "groups", allEntries = true)
public String joinGroup(KeycloakAuthenticationToken token,
Model model, @RequestParam("id") String groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
@ -263,8 +269,10 @@ public class WebController {
return "detailsNoMember";
}
//TODO: Muss post-mapping sein
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/acceptinvite/{link}")
@PostMapping("/acceptinvite/{link}")
@CacheEvict(value = "groups", allEntries = true)
public String acceptInvite(KeycloakAuthenticationToken token,
Model model,
@PathVariable("link") String link) throws EventException {
@ -280,6 +288,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup")
@CacheEvict(value = "groups", allEntries = true)
public String pLeaveGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
@ -292,6 +301,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/deleteGroup")
@CacheEvict(value = "groups", allEntries = true)
public String pDeleteGroup(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId) {
Account account = keyCloakService.createAccountFromPrincipal(token);
@ -320,6 +330,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole")
@CacheEvict(value = "groups", allEntries = true)
public String changeRole(KeycloakAuthenticationToken token,
@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException {
@ -332,6 +343,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeMaximum")
@CacheEvict(value = "groups", allEntries = true)
public String changeMaxSize(@RequestParam("maximum") Long maximum,
@RequestParam("group_id") String groupId,
KeycloakAuthenticationToken token) {
@ -343,6 +355,7 @@ public class WebController {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser")
@CacheEvict(value = "groups", allEntries = true)
public String deleteUser(@RequestParam("group_id") String groupId,
@RequestParam("user_id") String userId) throws EventException {
User user = new User(userId, "", "", "");

View File

@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -77,6 +78,7 @@ public class GroupService {
* @throws EventException Projektionsfehler
*/
//TODO Rename
@Cacheable("groups")
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
@ -100,6 +102,7 @@ public class GroupService {
*
* @return List of groups
*/
@Cacheable("groups")
public List<Group> getAllLecturesWithVisibilityPublic() {
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
@ -124,6 +127,7 @@ public class GroupService {
* @throws EventException Projektionsfehler
*/
//Todo Rename
@Cacheable("groups")
public List<Group> findGroupWith(String search, Account account) throws EventException {
if (search.isEmpty()) {
return getAllGroupWithVisibilityPublic(account.getName());

View File

@ -5,6 +5,7 @@ import mops.gruppen2.domain.User;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -25,6 +26,7 @@ public class UserService {
//Test nötig??
@Cacheable("groups")
public List<Group> getUserGroups(User user) throws EventException {
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
List<Event> events = groupService.getGroupEvents(groupIds);
@ -41,6 +43,7 @@ public class UserService {
return newGroups;
}
@Cacheable("groups")
public List<Group> getUserGroups(String userId) throws EventException {
return getUserGroups(new User(userId, null, null, null));
}

View File

@ -19,3 +19,4 @@ keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true
keycloak.confidential-port=443
server.error.include-stacktrace=always
management.endpoints.web.exposure.include=info,health

View File

@ -15,4 +15,5 @@ keycloak.credentials.secret=fc6ebf10-8c63-4e71-a667-4eae4e8209a1
keycloak.verify-token-audience=true
keycloak.use-resource-role-mappings=true
keycloak.autodetect-bearer-only=true
keycloak.confidential-port= 443
keycloak.confidential-port=443
management.endpoints.web.exposure.include=info,health

View File

@ -1,23 +0,0 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
DROP TABLE IF EXISTS event;
CREATE TABLE event
(
event_id INT PRIMARY KEY AUTO_INCREMENT,
group_id VARCHAR(36) NOT NULL,
user_id VARCHAR(50),
event_type VARCHAR(32),
event_payload VARCHAR(2500)
);
DROP TABLE IF EXISTS invite;
CREATE TABLE invite
(
invite_id INT PRIMARY KEY AUTO_INCREMENT,
group_id VARCHAR(36) NOT NULL,
invite_link VARCHAR(36) NOT NULL
);