1

Merge remote-tracking branch 'origin/master' into fixSomeErrors

# Conflicts:
#	src/main/java/mops/gruppen2/controller/Gruppen2Controller.java
This commit is contained in:
Lukas Ettel
2020-03-23 13:05:32 +01:00
9 changed files with 55 additions and 13 deletions

View File

@ -8,8 +8,11 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class Gruppen2Config { public class Gruppen2Config {
@Autowired final GroupService groupService;
GroupService groupService; final EventService eventService;
@Autowired
EventService eventService; public Gruppen2Config(GroupService groupService, EventService eventService) {
this.groupService = groupService;
this.eventService = eventService;
}
} }

View File

@ -5,7 +5,6 @@ import mops.gruppen2.config.Gruppen2Config;
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.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.GroupNotFoundException; import mops.gruppen2.domain.exception.GroupNotFoundException;
import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.domain.exception.WrongFileException;
@ -45,17 +44,19 @@ public class Gruppen2Controller {
private final UserService userService; private final UserService userService;
private final ControllerService controllerService; private final ControllerService controllerService;
private final InviteLinkRepositoryService inviteLinkRepositoryService; private final InviteLinkRepositoryService inviteLinkRepositoryService;
private final Gruppen2Config gruppen2Config;
private final Logger logger; private final Logger logger;
@Autowired @Autowired
Gruppen2Config gruppen2Config; Gruppen2Config gruppen2Config;
public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService) { public Gruppen2Controller(KeyCloakService keyCloakService, GroupService groupService, UserService userService, ControllerService controllerService, InviteLinkRepositoryService inviteLinkRepositoryService, Gruppen2Config gruppen2Config) {
this.keyCloakService = keyCloakService; this.keyCloakService = keyCloakService;
this.groupService = groupService; this.groupService = groupService;
this.userService = userService; this.userService = userService;
this.controllerService = controllerService; this.controllerService = controllerService;
this.inviteLinkRepositoryService = inviteLinkRepositoryService; this.inviteLinkRepositoryService = inviteLinkRepositoryService;
logger = Logger.getLogger("Gruppen2ControllerLogger"); logger = Logger.getLogger("Gruppen2ControllerLogger");
this.gruppen2Config = gruppen2Config;
} }
/** /**
@ -101,6 +102,9 @@ public class Gruppen2Controller {
if (!file.isEmpty()) { if (!file.isEmpty()) {
try { try {
userList = CsvService.read(file.getInputStream()); userList = CsvService.read(file.getInputStream());
if(userList.size() > userMaximum){
userMaximum = Long.valueOf(userList.size()) + userMaximum;
}
} catch (UnrecognizedPropertyException | CharConversionException ex) { } catch (UnrecognizedPropertyException | CharConversionException ex) {
logger.warning("File konnte nicht gelesen werden"); logger.warning("File konnte nicht gelesen werden");
throw new WrongFileException(file.getOriginalFilename()); throw new WrongFileException(file.getOriginalFilename());
@ -179,6 +183,9 @@ public class Gruppen2Controller {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Long parentId = group.getParent(); Long parentId = group.getParent();
Group parent = new Group(); Group parent = new Group();
if(group.getTitle() == null){
throw new GroupNotFoundException(this.getClass().toString());
}
if (!group.getMembers().contains(user)){ if (!group.getMembers().contains(user)){
if (group.getVisibility() == Visibility.PRIVATE){ if (group.getVisibility() == Visibility.PRIVATE){
return "privateGroupNoMember"; return "privateGroupNoMember";
@ -261,6 +268,22 @@ public class Gruppen2Controller {
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail()); User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.passIfLastAdmin(account, groupId); controllerService.passIfLastAdmin(account, groupId);
controllerService.deleteUser(user.getId(), groupId); controllerService.deleteUser(user.getId(), groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(user.getId(), groupId);
}
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/deleteGroup")
public String pDeleteGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId){
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(groupId);
if(group.getRoles().get(user.getId()) != Role.ADMIN ){
return "error";
}
controllerService.deleteGroupEvent(user.getId(), groupId);
return "redirect:/gruppen2/"; return "redirect:/gruppen2/";
} }
@ -305,9 +328,12 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"}) @RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser") @PostMapping("/details/members/deleteUser")
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId, public String deleteUser(@RequestParam("group_id") Long groupId,
@RequestParam("user_id") String userId) throws EventException { @RequestParam("user_id") String userId) throws EventException {
controllerService.deleteUser(userId, groupId); controllerService.deleteUser(userId, groupId);
if(userService.getGroupById(groupId).getMembers().size() == 0){
controllerService.deleteGroupEvent(userId ,groupId);
}
return "redirect:/gruppen2/details/members/" + groupId; return "redirect:/gruppen2/details/members/" + groupId;
} }
} }

View File

@ -36,7 +36,7 @@ public class AddUserEvent extends Event {
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
throw new UserAlreadyExistsException(this.getClass().toString()); throw new UserAlreadyExistsException(this.getClass().toString());
} }
//andere exception
if (group.getMembers().size() == group.getUserMaximum()){ if (group.getMembers().size() == group.getUserMaximum()){
throw new GroupFullException(this.getClass().toString()); throw new GroupFullException(this.getClass().toString());
} }

View File

@ -21,6 +21,7 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
@JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"), @JsonSubTypes.Type(value = UpdateGroupDescriptionEvent.class, name = "UpdateGroupDescriptionEvent"),
@JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"), @JsonSubTypes.Type(value = UpdateGroupTitleEvent.class, name = "UpdateGroupTitleEvent"),
@JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"), @JsonSubTypes.Type(value = UpdateRoleEvent.class, name = "UpdateRoleEvent"),
@JsonSubTypes.Type(value = DeleteGroupEvent.class, name = "DeleteGroupEvent")
}) })
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor

View File

@ -167,8 +167,8 @@ public class ControllerService {
eventService.saveEvent(deleteUserEvent); eventService.saveEvent(deleteUserEvent);
} }
public void deleteGroupEvent(User user, Long groupId) { public void deleteGroupEvent(String user_id, Long groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user.getId()); DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user_id);
eventService.saveEvent(deleteGroupEvent); eventService.saveEvent(deleteGroupEvent);
} }

View File

@ -89,7 +89,7 @@ public class GroupService {
List<Event> eventsUser = getGroupEvents(eventRepository.findGroup_idsWhereUser_id(userId)); List<Event> eventsUser = getGroupEvents(eventRepository.findGroup_idsWhereUser_id(userId));
List<Group> groups = projectEventList(eventsUser); List<Group> groups = projectEventList(eventsUser);
List<Group> newGroups = new ArrayList<>(); List<Group> newGroups = new ArrayList<>();
for (Group group : groups) { for (Group group : visibleGroups) {
if (group.getMembers().contains(user)) { if (group.getMembers().contains(user)) {
newGroups.add(group); newGroups.add(group);
} }
@ -102,6 +102,9 @@ public class GroupService {
List<Group> visibleGroups = projectEventList(eventsVisible); List<Group> visibleGroups = projectEventList(eventsVisible);
List<Group> visibleLectures = new ArrayList<>(); List<Group> visibleLectures = new ArrayList<>();
for (Group group : visibleGroups) { for (Group group : visibleGroups) {
if(group.getType() == null){
continue;
}
if (group.getType().equals(GroupType.LECTURE)) { if (group.getType().equals(GroupType.LECTURE)) {
visibleLectures.add(group); visibleLectures.add(group);
} }
@ -121,6 +124,9 @@ public class GroupService {
public List<Group> findGroupWith(String search, Account account) throws EventException { public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
for (Group group : getAllGroupWithVisibilityPublic(account.getName())) { for (Group group : getAllGroupWithVisibilityPublic(account.getName())) {
if(group.getType() == null){
continue;
}
if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) { if (group.getTitle().toLowerCase().contains(search.toLowerCase()) || group.getDescription().toLowerCase().contains(search.toLowerCase())) {
groups.add(group); groups.add(group);
} }

View File

@ -54,7 +54,7 @@
<div class="form-group mt-3"> <div class="form-group mt-3">
<label for="userMaximum">Teilnehmeranzahl</label> <label for="userMaximum">Teilnehmeranzahl</label>
<input class="form-control" id="userMaximum" required th:name="userMaximum" <input class="form-control" id="userMaximum" required th:name="userMaximum"
type="number" min="1"> type="number" min="1" max="10000">
</div> </div>
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input class="custom-control-input" id="visibility" th:name="visibility" <input class="custom-control-input" id="visibility" th:name="visibility"

View File

@ -59,6 +59,12 @@
type="submit">Gruppe verlassen type="submit">Gruppe verlassen
</button> </button>
</form> </form>
<form action="/gruppen2/deleteGroup" method="post">
<button class="btn btn-danger" style="border-style: none; margin: 5px"
th:name="group_id" th:value="${group.getId()}" th:if="${group.getRoles().get(user.getId()) == admin}"
type="submit">Gruppe löschen
</button>
</form>
</div> </div>
</div> </div>
<div class="col-3" style="white-space: nowrap"> <div class="col-3" style="white-space: nowrap">

View File

@ -99,7 +99,7 @@
type="hidden"> type="hidden">
<input th:name="user_id" th:value="${member.getId()}" <input th:name="user_id" th:value="${member.getId()}"
type="hidden"> type="hidden">
<button class="btn btn-danger btn-sm" style="margin: 5px">Mitglied entfernen</button> <button class="btn btn-danger btn-sm" style="margin: 5px" th:if='!${account.getName().equals(member.getId())}'>Mitglied entfernen</button>
</form> </form>
</div> </div>
</td> </td>