Skip to content
Snippets Groups Projects
Commit 8948b7a5 authored by Otto Visser's avatar Otto Visser
Browse files

Merge branch '273-unenroll-enroll-buttons-in-lab-view-incorrect' into 'development'

Replace net id with user id in unenque request.

Closes #273

See merge request !220
parents 9b2d08ea 05e04174
No related branches found
No related tags found
2 merge requests!222Development,!220Replace net id with user id in unenque request.
......@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- More TA feedback
- Allow users with manager and higher access to a course to unequeue students from the queue [@cedricwilleken](https://gitlab.ewi.tudelft.nl/cedricwilleken)
### Changed
- Unauthorized students for labs/courses now redirects to enroll pages by [@cedricwilleken](https://gitlab.ewi.tudelft.nl/cedricwilleken)
......
......@@ -238,13 +238,13 @@ public class LabController {
return "redirect:/lab/" + id;
}
@RequestMapping(value = "/lab/{id}/unenqueue/{netid}", method = RequestMethod.POST)
@RequestMapping(value = "/lab/{id}/unenqueue/{userId}", method = RequestMethod.POST)
@PreAuthorize("@permissionService.canUnenqueuOthersFromLab(principal, #id)")
public String unenqueueOther(@PathVariable("id") Long id,
@PathVariable("netid") String netid) {
@PathVariable("userId") Long userId) {
Lab lab = labService.getLab(id);
User user = userRepository.findByUsername(netid);
User user = userRepository.findOne(userId);
Optional<Request> request = lab.getPendingRequest(user);
if (lab.getCourse().getHasGroups()) {
......
......@@ -225,7 +225,7 @@
<td th:with="entity=${request.getRequestEntity()}, cond=${entity} != null"
style="white-space:nowrap;">
<form th:if="${cond}"
th:action="@{/lab/{id}/unenqueue/{netid}(id=${lab.id},netid=${request.getRequestEntity().getDisplayName()})}"
th:action="@{/lab/{id}/unenqueue/{userid}(id=${lab.id},userid=${request.getRequestEntity().getId()})}"
class="form-horizontal" method="post">
<span class="p-1">
[[${request.getRequestEntity().getDisplayName()}]]
......
......@@ -15,10 +15,18 @@
*/
package nl.tudelft.ewi.queue.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import nl.tudelft.ewi.queue.QueueApplication;
import nl.tudelft.ewi.queue.model.Lab;
import nl.tudelft.ewi.queue.model.User;
import nl.tudelft.ewi.queue.repository.LabRepository;
import nl.tudelft.ewi.queue.repository.UserRepository;
import nl.tudelft.ewi.queue.service.LabService;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -30,6 +38,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = QueueApplication.class)
......@@ -40,6 +49,15 @@ public class LabControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private LabService labService;
@Autowired
private LabRepository labRepository;
@Autowired
private UserRepository userRepository;
@Test
@WithUserDetails("student1@tudelft.nl")
public void testCorrectRedirectIfNotinCourse() throws Exception {
......@@ -55,4 +73,17 @@ public class LabControllerTest {
.andExpect(status().is2xxSuccessful()).andExpect(view().name("error/thouShaltNotPass"));
}
@Test
@WithUserDetails("manager2@tudelft.nl")
@Transactional
public void testCorrectUnenqueue() throws Exception {
// Get a student which is already enrolled in lab 3.
User student = userRepository.findOne(1L);
// Get a lab with timeslots enabled
Lab lab = labRepository.findOne(3L);
this.mockMvc.perform(post("/lab/" + lab.getId() + "/unenqueue/" + student.getId())
.with(csrf()))
.andExpect(status().is3xxRedirection());
assertThat(lab.isEnqueued(student)).isFalse();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment