Skip to content
Snippets Groups Projects
Commit 3e2b7f50 authored by Henry Page's avatar Henry Page :speech_balloon:
Browse files

temp save

parent 4123f29f
Branches
Tags
2 merge requests!630New release,!628Resolve "Course filter approved requests broken"
......@@ -146,14 +146,15 @@ public class RequestController {
.collect(Collectors.toList());
List<LabRequest> filteredRequests = rs
.filterRequestsSharedEditionCheck(lrr.findAllByFilter(labs, filter), assistant);
.filterRequestsSharedEditionCheck(lrr.findAllByFilter(labs, filter, pageable).getContent(),
assistant);
var requestPageView = rts.convertRequestsToView(
var requestsViews = rts.convertRequestsToView(
new PageImpl<>(filteredRequests, pageable, filteredRequests.size()), filteredRequests.size());
model.addAttribute("page", "requests");
model.addAttribute("filter", filter);
model.addAttribute("requests", requestPageView);
model.addAttribute("requests", requestsViews);
model.addAttribute("requestCounts", rts.labRequestCounts(
labs, assistant, filter));
......
......
......@@ -335,13 +335,15 @@ public interface LabRequestRepository
* @param pageable The pageable object representing the page.
* @return The filtered list of requests.
*/
default List<LabRequest> findAllByFilter(List<Lab> labs, RequestTableFilterDTO filter) {
default Page<LabRequest> findAllByFilter(List<Lab> labs, RequestTableFilterDTO filter,
Pageable pageable) {
return findAll(qlr.in(select(qlr).from(qlr)
.leftJoin(qlr.timeSlot, QTimeSlot.timeSlot).on(qlr.timeSlot.id.eq(QTimeSlot.timeSlot.id))
.where(createFilterBooleanExpression(filter, qlr.session.in(labs).and(
qlr.session.type.eq(QueueSessionType.REGULAR)
.or(qlr.session.type.in(QueueSessionType.SLOTTED, QueueSessionType.EXAM)
.and(qlr.timeSlot.slot.opensAt.before(now().plusMinutes(10)))))))));
.and(qlr.timeSlot.slot.opensAt.before(now().plusMinutes(10)))))))),
pageable);
}
/**
......@@ -358,8 +360,6 @@ public interface LabRequestRepository
BooleanExpression e) {
e = and(e, filter.getAssigned(), qlr.eventInfo.assignedTo::in);
e = and(e, filter.getLabs(), qlr.session.id::in);
e = and(e, filter.getRooms(), qlr.room::in);
e = and(e, filter.getOnlineModes(), qlr.onlineMode::in);
e = and(e, filter.getAssignments(), qlr.assignment::in);
e = and(e, filter.getRequestStatuses(), qlr.eventInfo.status::in);
e = and(e, filter.getRequestTypes(), qlr.requestType::in);
......
......
......@@ -52,6 +52,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.ListUtils;
import reactor.core.publisher.Mono;
......@@ -513,15 +514,22 @@ public class RequestService {
}
/**
* This is meant to act as a filter for a list of lab requests that originates from a shared session.
* This is meant to act as a filter for a list of lab requests that originates from a shared session. This
* is so that assistants from other editions don't see requests from other editions they are not an
* assistant of.
*
* @param request A list of requests to filter
* @param requests A list of requests to filter
* @param person The assistant that will see the lab requests
* @return A new list of lab requests that the assistant will see only if they are an assistant of
* the edition the request belongs.
* @return A new list of lab requests that the assistant will see only if they are an assistant
* of the edition the request belongs.
*/
public List<LabRequest> filterRequestsSharedEditionCheck(List<LabRequest> request, Person person) {
var assignmentIds = request.stream().map(LabRequest::getAssignment).toList();
public List<LabRequest> filterRequestsSharedEditionCheck(List<LabRequest> requests, Person person) {
// Check to make sure requests are not empty, otherwise API call fails.
if (ListUtils.isEmpty(requests)) {
return requests;
}
var assignmentIds = requests.stream().map(LabRequest::getAssignment).toList();
var allowedAssignments = Objects
.requireNonNull(asApi.getAssignmentsWithModules(assignmentIds).collectList().block()).stream()
......@@ -530,7 +538,7 @@ public class RequestService {
.map(AssignmentModuleDetailsDTO::getId)
.collect(Collectors.toSet());
return request.stream().filter(r -> allowedAssignments.contains(r.getAssignment())).toList();
return requests.stream().filter(r -> allowedAssignments.contains(r.getAssignment())).toList();
}
/**
......
......
......@@ -29,8 +29,10 @@ import java.util.stream.Collectors;
import javax.transaction.Transactional;
import nl.tudelft.labracore.api.AssignmentControllerApi;
import nl.tudelft.labracore.api.StudentGroupControllerApi;
import nl.tudelft.labracore.api.dto.*;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.queue.cache.SessionCacheManager;
import nl.tudelft.queue.dto.create.requests.SelectionRequestCreateDTO;
import nl.tudelft.queue.model.QSelectionRequest;
......@@ -40,6 +42,7 @@ import nl.tudelft.queue.model.embeddables.LabRequestConstraints;
import nl.tudelft.queue.model.enums.RequestStatus;
import nl.tudelft.queue.model.enums.SelectionProcedure;
import nl.tudelft.queue.model.labs.CapacitySession;
import nl.tudelft.queue.model.labs.RegularLab;
import nl.tudelft.queue.repository.CapacitySessionRepository;
import nl.tudelft.queue.repository.SelectionRequestRepository;
......@@ -47,11 +50,13 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.test.annotation.DirtiesContext;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import test.TestDatabaseLoader;
import test.labracore.*;
import test.test.TestQueueApplication;
......@@ -89,9 +94,13 @@ public class RequestServiceTest {
private CapacitySession session;
private RegularLab oopNowRegularLab1;
CapacitySessionConfig.CapacitySessionConfigBuilder sessionConfigBuilderSelectNow;
CapacitySession.CapacitySessionBuilder<?, ? extends CapacitySession.CapacitySessionBuilder<?, ?>> sessionBuilder;
@Autowired
private TestDatabaseLoader db;
@Autowired
private CapacitySessionRepository csr;
......@@ -119,6 +128,12 @@ public class RequestServiceTest {
@Autowired
private ModuleApiMocker mApiMocker;
@Autowired
private AssignmentApiMocker asApiMocker;
@SpyBean
private AssignmentControllerApi asApi;
@Autowired
private StudentGroupControllerApi sgApi;
......@@ -134,6 +149,8 @@ public class RequestServiceTest {
.enrolmentClosesAt(LocalDateTime.now().minusDays(1))
.selectionAt(LocalDateTime.now().minusMinutes(3));
oopNowRegularLab1 = db.getOopNowRegularLab1();
sApiMocker.save(lcSessionNow);
sApiMocker.save(lcSessionOld1);
sApiMocker.save(lcSessionOld2);
......@@ -145,6 +162,7 @@ public class RequestServiceTest {
rApiMocker.mock();
pApiMocker.mock();
mApiMocker.mock();
asApiMocker.mock();
}
private void mockStudentGroup(Long moduleId, List<Long> requesterIds, Long studentGroupId) {
......@@ -304,4 +322,13 @@ public class RequestServiceTest {
verify(sgApi).getStudentGroupsById(List.of(6L));
verify(sgApi).addGroup(any());
}
@Test
void sharedEditionFilterDoesNotCallApiWhenEmptyRequests() {
assertThat(rs.filterRequestsSharedEditionCheck(new ArrayList<>(), new Person())).isEmpty();
verify(asApi, never()).getAssignmentsWithModules(any());
}
}
......@@ -20,11 +20,15 @@ package test.labracore;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import nl.tudelft.labracore.api.AssignmentControllerApi;
import nl.tudelft.labracore.api.dto.AssignmentDetailsDTO;
import nl.tudelft.labracore.api.dto.AssignmentModuleDetailsDTO;
import nl.tudelft.labracore.api.dto.AssignmentSummaryDTO;
import org.modelmapper.ModelMapper;
......@@ -36,6 +40,8 @@ import reactor.core.publisher.Mono;
public class AssignmentApiMocker extends LabracoreApiMocker<AssignmentDetailsDTO, Long> {
private final AssignmentControllerApi aApi;
private final Map<Long, AssignmentModuleDetailsDTO> assignmentsWithModules = new HashMap<>();
@Override
public void mock() {
when(aApi.getAllAssignmentsById(any())).thenAnswer(getAllByIds);
......@@ -54,6 +60,17 @@ public class AssignmentApiMocker extends LabracoreApiMocker<AssignmentDetailsDTO
});
}
@Override
public AssignmentDetailsDTO save(AssignmentDetailsDTO dto) {
super.save(dto);
var assignmentWithModule = mapper.map(dto, AssignmentModuleDetailsDTO.class);
assignmentsWithModules.put(Objects.requireNonNull(dto.getId()), assignmentWithModule);
return dto;
}
@Override
public Long getId(AssignmentDetailsDTO dto) {
return dto.getId();
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment