Skip to content
Snippets Groups Projects

Resolve "[Queue-2.0] CSV Import for TAs"

Files

@@ -33,6 +33,8 @@ import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.librador.dto.view.View;
import nl.tudelft.queue.cache.*;
import nl.tudelft.queue.csv.EmptyCsvException;
import nl.tudelft.queue.csv.InvalidCsvException;
import nl.tudelft.queue.dto.create.CourseRequestCreateDTO;
import nl.tudelft.queue.dto.create.QueueEditionCreateDTO;
import nl.tudelft.queue.dto.create.QueueRoleCreateDTO;
@@ -54,6 +56,8 @@ 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.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
public class EditionController {
@@ -336,6 +340,31 @@ public class EditionController {
return "redirect:/edition/" + editionId + "/participants";
}
/**
* Adds new participants to the course based on a CSV file that was uploaded by the user.
*
* @param editionId The id of the edition to which the users must be added.
* @param csv A CSV file containing both the netId and their role in the course.
* @param attributes Used to pass information when redirecting to Thymeleaf.
* @return A redirect to either the participants page when successfull, otherwise redirect ot
* create participants page
*/
@PostMapping("/edition/{editionId}/participants/import")
@PreAuthorize("@permissionService.canManageTeachers(#editionId)")
public String importParticipants(@PathVariable Long editionId,
@RequestParam("file") MultipartFile csv,
RedirectAttributes attributes) {
EditionDetailsDTO edition = eCache.getOrThrow(editionId);
try {
es.addCourseParticipants(csv, edition);
return "redirect:/edition/" + editionId + "/participants";
} catch (EmptyCsvException | InvalidCsvException e) {
attributes.addFlashAttribute("csvError", true);
}
return "redirect:/edition/" + editionId + "/participants/create";
}
/**
* Gets the participant remove page. This page is used to remove a specific participant from the given
* edition.
Loading