Skip to content
Snippets Groups Projects

Resolve "Add verification to not put person in two groups at once"

Files

@@ -30,6 +30,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import nl.tudelft.labracore.api.dto.*;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
@@ -41,6 +42,7 @@ import nl.tudelft.submit.dto.create.note.GroupNoteCreateDTO;
import nl.tudelft.submit.dto.create.note.SubmissionNoteCreateDTO;
import nl.tudelft.submit.dto.id.SubmissionId;
import nl.tudelft.submit.dto.view.labracore.SubmitGroupDetailsDTO;
import nl.tudelft.submit.exception.GroupSwitchingException;
import nl.tudelft.submit.model.Signature;
import nl.tudelft.submit.security.AuthorizationService;
import nl.tudelft.submit.service.*;
@@ -182,10 +184,16 @@ public class StudentGroupController {
@PostMapping
@PreAuthorize("@authorizationService.canCreateGroup(#create.getModule().getId())")
public String createGroup(@AuthenticatedPerson Person person,
@ModelAttribute("groupCreate") StudentGroupCreateDTO create) {
Long id = groupService.createGroup(create);
return "redirect:/group/" + id;
@ModelAttribute("groupCreate") StudentGroupCreateDTO create,
RedirectAttributes redirectAttributes) {
try {
Long id = groupService.createGroup(create);
return "redirect:/group/" + id;
} catch (GroupSwitchingException e) {
redirectAttributes.addFlashAttribute("error", e.getMessage());
return "redirect:/module/" + create.getModule().getId() + "/groups";
}
}
/**
@@ -246,10 +254,18 @@ public class StudentGroupController {
*/
@PostMapping("/{id}/join")
@PreAuthorize("@authorizationService.canJoinGroup(#id)")
public String joinGroup(@AuthenticatedPerson Person person, @PathVariable Long id) {
groupService.addPeopleToGroup(id, List.of(person.getUsername()));
public String joinGroup(@AuthenticatedPerson Person person, @PathVariable Long id,
RedirectAttributes redirectAttributes) {
ModuleDetailsDTO module = moduleService.getModuleById(groupService.getModuleIdFromGroup(id));
try {
groupService.addPeopleToGroup(id, List.of(person.getUsername()));
} catch (GroupSwitchingException e) {
redirectAttributes.addFlashAttribute("error", e.getMessage());
return "redirect:/module/" + module.getId() + "/groups";
}
return "redirect:/edition/" + module.getEdition().getId() + "/student?module=" + module.getId();
}
@@ -262,8 +278,13 @@ public class StudentGroupController {
*/
@PostMapping("/{id}/members")
@PreAuthorize("@authorizationService.canAddMembersToGroup(#id)")
public String addMembersToGroup(@PathVariable Long id, @RequestParam List<String> usernames) {
groupService.addPeopleToGroup(id, usernames);
public String addMembersToGroup(@PathVariable Long id, @RequestParam List<String> usernames,
RedirectAttributes redirectAttributes) {
try {
groupService.addPeopleToGroup(id, usernames);
} catch (GroupSwitchingException e) {
redirectAttributes.addFlashAttribute("error", e.getMessage());
}
return "redirect:/group/" + id;
}
Loading