Merge remote-tracking branch 'origin/master' into refactor-controllerService
# Conflicts: # src/main/java/mops/gruppen2/service/ControllerService.java
This commit is contained in:
@ -57,11 +57,6 @@
|
|||||||
<property name="message"
|
<property name="message"
|
||||||
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
|
||||||
</module>
|
</module>
|
||||||
<module name="AvoidEscapedUnicodeCharacters">
|
|
||||||
<property name="allowEscapesForControlCharacters" value="true"/>
|
|
||||||
<property name="allowByTailComment" value="true"/>
|
|
||||||
<property name="allowNonPrintableEscapes" value="true"/>
|
|
||||||
</module>
|
|
||||||
<module name="AvoidStarImport"/>
|
<module name="AvoidStarImport"/>
|
||||||
<module name="OneTopLevelClass"/>
|
<module name="OneTopLevelClass"/>
|
||||||
<module name="NoLineWrap">
|
<module name="NoLineWrap">
|
||||||
@ -173,7 +168,7 @@
|
|||||||
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
value="Type name ''{0}'' must match pattern ''{1}''."/>
|
||||||
</module>
|
</module>
|
||||||
<module name="MemberName">
|
<module name="MemberName">
|
||||||
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
|
<property name="format" value="^[a-z][a-zA-Z0-9].*$"/>
|
||||||
<message key="name.invalidPattern"
|
<message key="name.invalidPattern"
|
||||||
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
value="Member name ''{0}'' must match pattern ''{1}''."/>
|
||||||
</module>
|
</module>
|
||||||
@ -193,7 +188,7 @@
|
|||||||
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
|
||||||
</module>
|
</module>
|
||||||
<module name="LocalVariableName">
|
<module name="LocalVariableName">
|
||||||
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
|
<property name="format" value="^[a-z]([a-zA-Z0-9]*)?$"/>
|
||||||
<message key="name.invalidPattern"
|
<message key="name.invalidPattern"
|
||||||
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
|
||||||
</module>
|
</module>
|
||||||
|
|||||||
@ -6,13 +6,22 @@ import mops.gruppen2.domain.User;
|
|||||||
import mops.gruppen2.domain.exception.EventException;
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
import mops.gruppen2.domain.exception.PageNotFoundException;
|
import mops.gruppen2.domain.exception.PageNotFoundException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import mops.gruppen2.service.*;
|
import mops.gruppen2.service.ControllerService;
|
||||||
|
import mops.gruppen2.service.GroupService;
|
||||||
|
import mops.gruppen2.service.KeyCloakService;
|
||||||
|
import mops.gruppen2.service.UserService;
|
||||||
|
import mops.gruppen2.service.ValidationService;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.context.annotation.SessionScope;
|
import org.springframework.web.context.annotation.SessionScope;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -207,8 +216,8 @@ public class WebController {
|
|||||||
model.addAttribute("user", user);
|
model.addAttribute("user", user);
|
||||||
model.addAttribute("admin", Role.ADMIN);
|
model.addAttribute("admin", Role.ADMIN);
|
||||||
|
|
||||||
String URL = request.getRequestURL().toString();
|
String actualURL = request.getRequestURL().toString();
|
||||||
String serverURL = URL.substring(0, URL.indexOf("gruppen2/"));
|
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
|
||||||
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
model.addAttribute("link", serverURL + "gruppen2/acceptinvite/" + groupId);
|
||||||
|
|
||||||
return "detailsMember";
|
return "detailsMember";
|
||||||
@ -235,10 +244,11 @@ public class WebController {
|
|||||||
@RequestParam("id") String groupId) throws EventException {
|
@RequestParam("id") String groupId) throws EventException {
|
||||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||||
Group group = userService.getGroupById(UUID.fromString(groupId));
|
Group group = userService.getGroupById(UUID.fromString(groupId));
|
||||||
|
validationService.checkIfGroupFull(group);
|
||||||
|
|
||||||
UUID parentId = group.getParent();
|
UUID parentId = group.getParent();
|
||||||
Group parent = validationService.checkParent(parentId);
|
Group parent = validationService.checkParent(parentId);
|
||||||
|
|
||||||
validationService.checkIfGroupFull(group);
|
|
||||||
model.addAttribute("group", group);
|
model.addAttribute("group", group);
|
||||||
model.addAttribute("parentId", parentId);
|
model.addAttribute("parentId", parentId);
|
||||||
model.addAttribute("parent", parent);
|
model.addAttribute("parent", parent);
|
||||||
|
|||||||
@ -15,8 +15,8 @@ public class UpdateUserMaxEvent extends Event {
|
|||||||
|
|
||||||
private Long userMaximum;
|
private Long userMaximum;
|
||||||
|
|
||||||
public UpdateUserMaxEvent(UUID group_id, String user_id, Long userMaximum) {
|
public UpdateUserMaxEvent(UUID groupId, String userId, Long userMaximum) {
|
||||||
super(group_id, user_id);
|
super(groupId, userId);
|
||||||
this.userMaximum = userMaximum;
|
this.userMaximum = userMaximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,11 @@ import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticatio
|
|||||||
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
|
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
|
||||||
import org.keycloak.representations.AccessToken;
|
import org.keycloak.representations.AccessToken;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.*;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.context.annotation.ScopedProxyMode;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
|
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
@ -15,15 +14,11 @@ import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
|
|||||||
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
import mops.gruppen2.domain.event.UpdateUserMaxEvent;
|
||||||
import mops.gruppen2.domain.exception.EventException;
|
import mops.gruppen2.domain.exception.EventException;
|
||||||
import mops.gruppen2.domain.exception.BadParameterException;
|
|
||||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.exception.WrongFileException;
|
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import java.io.CharConversionException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -206,8 +201,8 @@ public class ControllerService {
|
|||||||
eventService.saveEvent(deleteUserEvent);
|
eventService.saveEvent(deleteUserEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteGroupEvent(String user_id, UUID groupId) {
|
public void deleteGroupEvent(String userId, UUID groupId) {
|
||||||
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
|
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, userId);
|
||||||
eventService.saveEvent(deleteGroupEvent);
|
eventService.saveEvent(deleteGroupEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,8 +219,8 @@ public class ControllerService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLastAdmin(Account account, Group group){
|
private boolean isLastAdmin(Account account, Group group) {
|
||||||
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()){
|
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
|
||||||
if (entry.getValue() == ADMIN) {
|
if (entry.getValue() == ADMIN) {
|
||||||
if (!(entry.getKey().equals(account.getName()))) {
|
if (!(entry.getKey().equals(account.getName()))) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -98,10 +98,9 @@ public class GroupService {
|
|||||||
/**
|
/**
|
||||||
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
* Wird verwendet beim Gruppe erstellen bei der Parent-Auswahl: nur Titel benötigt.
|
||||||
*
|
*
|
||||||
* @return
|
* @return List of groups
|
||||||
* @throws EventException
|
|
||||||
*/
|
*/
|
||||||
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
|
public List<Group> getAllLecturesWithVisibilityPublic() {
|
||||||
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("DeleteGroupEvent")));
|
||||||
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
import mops.gruppen2.domain.Role;
|
import mops.gruppen2.domain.Role;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.exception.*;
|
import mops.gruppen2.domain.exception.BadParameterException;
|
||||||
|
import mops.gruppen2.domain.exception.GroupFullException;
|
||||||
|
import mops.gruppen2.domain.exception.GroupNotFoundException;
|
||||||
|
import mops.gruppen2.domain.exception.NoAccessException;
|
||||||
|
import mops.gruppen2.domain.exception.NoAdminAfterActionException;
|
||||||
|
import mops.gruppen2.domain.exception.NoValueException;
|
||||||
|
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||||
|
import mops.gruppen2.domain.exception.WrongFileException;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.swing.text.StyledEditorKit;
|
|
||||||
import javax.validation.ValidationException;
|
|
||||||
import java.io.CharConversionException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -47,13 +49,17 @@ public class ValidationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkGroup(String title) {
|
public void checkGroup(String title) {
|
||||||
if (title == null) throw new GroupNotFoundException("@details");
|
if (title == null) {
|
||||||
|
throw new GroupNotFoundException("@details");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkIfUserInGroup(Group group, User user) {
|
public boolean checkIfUserInGroup(Group group, User user) {
|
||||||
if (!group.getMembers().contains(user) && group.getVisibility() == Visibility.PRIVATE) {
|
if (!group.getMembers().contains(user) && group.getVisibility() == Visibility.PRIVATE) {
|
||||||
throw new NoAccessException("");
|
throw new NoAccessException("");
|
||||||
} else return group.getMembers().contains(user);
|
} else {
|
||||||
|
return group.getMembers().contains(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group checkParent(UUID parentId) {
|
public Group checkParent(UUID parentId) {
|
||||||
@ -118,9 +124,10 @@ public class ValidationService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Überprüft ob alle Felder richtig gesetzt sind.
|
* Überprüft ob alle Felder richtig gesetzt sind.
|
||||||
* @param description
|
*
|
||||||
* @param title
|
* @param description Die Beschreibung der Gruppe
|
||||||
* @param userMaximum
|
* @param title Der Titel der Gruppe
|
||||||
|
* @param userMaximum Das user Limit der Gruppe
|
||||||
*/
|
*/
|
||||||
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
|
public void checkFields(String description, String title, Long userMaximum, Boolean maxInfiniteUsers) {
|
||||||
if (description == null) {
|
if (description == null) {
|
||||||
|
|||||||
@ -61,13 +61,13 @@
|
|||||||
<input class="form-control" th:name="userMaximum"
|
<input class="form-control" th:name="userMaximum"
|
||||||
type="number" min="1" max="10000">
|
type="number" min="1" max="10000">
|
||||||
</div>
|
</div>
|
||||||
<div class="custom-control custom-checkbox">
|
<div class="custom-control custom-checkbox" id="privateCheckbox">
|
||||||
<input class="custom-control-input" id="visibility" th:name="visibility"
|
<input class="custom-control-input" id="visibility" th:name="visibility"
|
||||||
type="checkbox">
|
type="checkbox">
|
||||||
<label class="custom-control-label" for="visibility">Private
|
<label class="custom-control-label" for="visibility">Private
|
||||||
Gruppe</label>
|
Gruppe</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="custom-control custom-checkbox">
|
<div class="custom-control custom-checkbox" id="lectureCheckbox">
|
||||||
<input class="custom-control-input" id="lecture" th:name="lecture"
|
<input class="custom-control-input" id="lecture" th:name="lecture"
|
||||||
type="checkbox">
|
type="checkbox">
|
||||||
<label class="custom-control-label" for="lecture">Veranstaltung</label>
|
<label class="custom-control-label" for="lecture">Veranstaltung</label>
|
||||||
@ -117,6 +117,18 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#lecture').change(function () {
|
||||||
|
$('#privateCheckbox').fadeToggle();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#visibility').change(function () {
|
||||||
|
$('#lectureCheckbox').fadeToggle();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#maxInfiniteUsers').change(function () {
|
$('#maxInfiniteUsers').change(function () {
|
||||||
$('#userMaximum').fadeToggle();
|
$('#userMaximum').fadeToggle();
|
||||||
|
|||||||
@ -49,7 +49,7 @@
|
|||||||
style="border: none; border-radius: 5px; background: aliceblue">
|
style="border: none; border-radius: 5px; background: aliceblue">
|
||||||
<h3 style="color: dodgerblue; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word">
|
<h3 style="color: dodgerblue; font-weight: bold; font-optical-sizing: auto; overflow-wrap: break-word">
|
||||||
<span class="badge badge-pill badge-success"
|
<span class="badge badge-pill badge-success"
|
||||||
style="background: lightseagreen; margin-right: 25px;"
|
style="background: lightseagreen; margin-right: 25px; float: right"
|
||||||
th:if='${gruppe.getType() == gruppe.getType().LECTURE}'>Veranstaltung</span>
|
th:if='${gruppe.getType() == gruppe.getType().LECTURE}'>Veranstaltung</span>
|
||||||
<a th:href="@{/gruppen2/details/{id}(id=${gruppe.getId()})}"
|
<a th:href="@{/gruppen2/details/{id}(id=${gruppe.getId()})}"
|
||||||
th:text="${gruppe.getTitle()}"></a>
|
th:text="${gruppe.getTitle()}"></a>
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import mops.gruppen2.domain.Visibility;
|
|||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -155,9 +154,8 @@ class GroupServiceTest {
|
|||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
@Test
|
||||||
void getAllGroupWithVisibilityPublicTestIsUserInGroup() {
|
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
||||||
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||||
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user