Merge pull request #105 from hhu-propra2/max_userNumber
Max user number
This commit is contained in:
@ -131,12 +131,13 @@ public class Gruppen2Controller {
|
||||
@PostMapping("/createGroup")
|
||||
public String pCreateGroup(KeycloakAuthenticationToken token,
|
||||
@RequestParam("title") String title,
|
||||
@RequestParam("beschreibung") String beschreibung,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility) throws EventException {
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam(value = "visibility", required = false) Boolean visibility,
|
||||
@RequestParam("userMaximum") Long userMaximum) throws EventException {
|
||||
|
||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
||||
visibility = visibility == null;
|
||||
controllerService.createGroup(account, title, beschreibung, visibility);
|
||||
controllerService.createGroup(account, title, description, visibility, userMaximum);
|
||||
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -170,6 +171,7 @@ public class Gruppen2Controller {
|
||||
if (group.getMembers().contains(user)) {
|
||||
return "error"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
|
||||
}
|
||||
if (group.getUserMaximum() < group.getMembers().size()) return "error";
|
||||
controllerService.addUser(account, groupId);
|
||||
return "redirect:/gruppen2/";
|
||||
}
|
||||
@ -179,7 +181,7 @@ public class Gruppen2Controller {
|
||||
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
Group group = userService.getGroupById(groupId);
|
||||
if (group != null) {
|
||||
if (group != null && group.getUserMaximum() > group.getMembers().size()) {
|
||||
model.addAttribute("group", group);
|
||||
return "detailsNoMember";
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ public class Group {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String description;
|
||||
private Long userMaximum;
|
||||
private GroupType type;
|
||||
private Visibility visibility;
|
||||
private Long parent;
|
||||
|
||||
@ -7,6 +7,7 @@ import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.exception.GroupFullException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
|
||||
/**
|
||||
@ -35,6 +36,10 @@ public class AddUserEvent extends Event {
|
||||
if (group.getMembers().contains(user)) {
|
||||
throw new UserAlreadyExistsException(this.getClass().toString());
|
||||
}
|
||||
//andere exception
|
||||
if (group.getMembers().size() == group.getUserMaximum()){
|
||||
throw new GroupFullException(this.getClass().toString());
|
||||
}
|
||||
|
||||
group.getMembers().add(user);
|
||||
group.getRoles().put(userId, Role.MEMBER);
|
||||
|
||||
@ -15,12 +15,14 @@ public class CreateGroupEvent extends Event {
|
||||
private Visibility groupVisibility;
|
||||
private Long groupParent;
|
||||
private GroupType groupType;
|
||||
private Long groupUserMaximum;
|
||||
|
||||
public CreateGroupEvent(Long groupId, String userId, Long parent, GroupType type, Visibility visibility) {
|
||||
public CreateGroupEvent(Long groupId, String userId, Long parent, GroupType type, Visibility visibility, Long userMaximum) {
|
||||
super(groupId, userId);
|
||||
this.groupParent = parent;
|
||||
this.groupType = type;
|
||||
this.groupVisibility = visibility;
|
||||
this.groupUserMaximum = userMaximum;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,5 +31,6 @@ public class CreateGroupEvent extends Event {
|
||||
group.setParent(this.groupParent);
|
||||
group.setType(this.groupType);
|
||||
group.setVisibility(this.groupVisibility);
|
||||
group.setUserMaximum(this.groupUserMaximum);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class GroupFullException extends EventException {
|
||||
|
||||
public GroupFullException(String info) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, "Der User existiert bereits.", info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class ControllerService {
|
||||
* @param title Gruppentitel
|
||||
* @param description Gruppenbeschreibung
|
||||
*/
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException {
|
||||
public void createGroup(Account account, String title, String description, Boolean visibility, Long userMaximum) throws EventException {
|
||||
Visibility visibility1;
|
||||
Long groupId = eventService.checkGroup();
|
||||
|
||||
@ -54,7 +54,7 @@ public class ControllerService {
|
||||
createInviteLink(groupId);
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1, userMaximum);
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
@ -144,7 +144,7 @@ public class ControllerService {
|
||||
visibility1 = Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1, 1000L); //this has to be changed also Usermaximum
|
||||
eventService.saveEvent(createGroupEvent);
|
||||
|
||||
addUser(account, groupId);
|
||||
|
||||
6
src/main/resources/data.sql
Normal file
6
src/main/resources/data.sql
Normal file
@ -0,0 +1,6 @@
|
||||
insert into event values
|
||||
(1,1,'orga','{"type":"CreateGroupEvent","groupId":1,"userId":"orga","groupVisibility":"PUBLIC","groupParent":null,"groupType":"SIMPLE","groupUserMaximum":2}', TRUE),
|
||||
(2,1,'orga','{"type":"AddUserEvent","groupId":1,"userId":"orga","givenname":"orga","familyname":"orga","email":"blorga@orga.org"}', FALSE),
|
||||
(3,1,'orga','{"type":"UpdateGroupTitleEvent","groupId":1,"userId":"orga","newGroupTitle":"sdsad"}', FALSE),
|
||||
(4,1,'orga','{"type":"UpdateGroupDescriptionEvent","groupId":1,"userId":"orga","newGroupDescription":"sadsad"}', FALSE),
|
||||
(5,1,'orga','{"type":"UpdateRoleEvent","groupId":1,"userId":"orga","newRole":"ADMIN"}', FALSE);
|
||||
@ -42,9 +42,14 @@
|
||||
type="text">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="beschreibung">Beschreibung</label>
|
||||
<textarea class="form-control" id="beschreibung" required
|
||||
rows="3" th:name="beschreibung"></textarea>
|
||||
<label for="description">Beschreibung</label>
|
||||
<textarea class="form-control" id="description" required
|
||||
rows="3" th:name="description"></textarea>
|
||||
</div>
|
||||
<div class="form-group mt-3">
|
||||
<label for="userMaximum">Teilnehmeranzahl</label>
|
||||
<input class="form-control" id="userMaximum" required th:name="userMaximum"
|
||||
type="number" min="1">
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input class="custom-control-input" id="visibility" th:name="visibility"
|
||||
|
||||
@ -62,13 +62,18 @@
|
||||
<div class="col-3" style="white-space: nowrap">
|
||||
<div style="display: inline-block; margin: 0">
|
||||
<h2>Mitglieder</h2>
|
||||
<div>
|
||||
<h4>
|
||||
<a th:text="${group.getMembers().size()}"></a>
|
||||
<a>von maximal</a>
|
||||
<a th:text="${group.getUserMaximum()}"></a>
|
||||
<a>Benutzern.</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div th:if="${group.getRoles().get(user.getId()) == admin}">
|
||||
<form method="get"
|
||||
th:action="@{/gruppen2/details/members/{id}(id=${group.getId()})}">
|
||||
<button class="btn btn-secondary"
|
||||
style="background: slategrey; float: right">
|
||||
Mitglieder bearbeiten
|
||||
</button>
|
||||
<button class="btn btn-secondary" style="background: slategrey; float: left">Mitglieder bearbeiten</button>
|
||||
</form>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-9">
|
||||
<div class="shadow p-2" style="border: 10px solid aliceblue; border-radius: 5px; background: aliceblue">
|
||||
<div class="shadow p-2" style="border: 10px solid aliceblue; background: aliceblue">
|
||||
<!-- absichern im controller nicht vergessen -->
|
||||
<div class="form-group pt-4" th:if="${account.getRoles().contains('orga')}">
|
||||
<form action="/gruppen2/details/members/addUsersFromCsv"
|
||||
@ -99,12 +99,9 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="btn btn-primary" style="background: #52a1eb; border-style: none"
|
||||
type="button">
|
||||
<a th:href="@{/gruppen2/details(id=${group.getId()})}" style="color: white">Fertig</a>
|
||||
</button>
|
||||
<br>
|
||||
<br>
|
||||
<form method="get" th:action="@{/gruppen2/details/{id}(id=${group.getId()})}">
|
||||
<button class="btn btn-primary" style="background: #52a1eb; border-style: none" type="submit">Fertig</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -56,7 +56,8 @@ public class EventBuilder {
|
||||
faker.random().hex(),
|
||||
null,
|
||||
GroupType.SIMPLE,
|
||||
Visibility.PRIVATE
|
||||
Visibility.PRIVATE,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ class AddUserEventTest {
|
||||
Group group = new Group();
|
||||
User user = new User("user1", "Stein", "Speck", "@sdasd");
|
||||
group.getMembers().add(user);
|
||||
group.setUserMaximum(10L);
|
||||
Event event1 = new AddUserEvent(4L, "user2", "Rock", "Roll", "and");
|
||||
event1.apply(group);
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ class EventServiceTest {
|
||||
|
||||
@Test
|
||||
void getDTOOffentlichTest() {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "test", null, GroupType.LECTURE, Visibility.PUBLIC);
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "test", null, GroupType.LECTURE, Visibility.PUBLIC, null);
|
||||
EventDTO eventDTO = eventService.getDTO(createGroupEvent);
|
||||
assertTrue(eventDTO.isVisibility());
|
||||
}
|
||||
|
||||
@ -27,9 +27,9 @@ class GroupServiceTest {
|
||||
|
||||
|
||||
@Test
|
||||
void rightClassForSuccessfulGroup() throws Exception {
|
||||
void rightClassForSuccessfulGroup() {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE,1000L));
|
||||
eventList.add(new AddUserEvent(1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
|
||||
Reference in New Issue
Block a user