Skip to content

Commit

Permalink
Fix for sturcturefeedback + admin submit after deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
Aqua-sc committed May 22, 2024
1 parent bf2be71 commit 1ae569a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ docker.env
startBackend.sh

/.env
backend/web-bff/App/.env
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public SubmissionResult checkSubmission(ZipFile file) throws IOException {
boolean passed = (filesMissing.size() + filesUnrequested.size() + filesDenied.size()) == 0;
String feedback = passed ? "File structure is correct" : "File structure failed to pass the template, because: \n ";
if (!filesMissing.isEmpty()) {
feedback += " -The following files are required from the template and are not found in the project: \n -";
feedback += String.join("\n -", filesMissing);
feedback += "- The following files are required from the template and are not found in the project: \n - ";
feedback += String.join("\n - ", filesMissing);
}
if (!filesUnrequested.isEmpty()) {
feedback += "\n -The following files are not requested in the template: \n -";
feedback += String.join("\n -", filesUnrequested);
feedback += "\n - The following files are not requested in the template: \n - ";
feedback += String.join("\n - ", filesUnrequested);
}
if (!filesDenied.isEmpty()) {
feedback += "\n -The following files are not allowed in the project: \n -";
feedback += String.join("\n -", filesDenied);
feedback += "\n - The following files are not allowed in the project: \n - ";
feedback += String.join("\n - ", filesDenied);
}

return new SubmissionResult(passed, feedback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public CheckResult<Long> checkOnSubmit(long projectId, UserEntity user) {

OffsetDateTime time = OffsetDateTime.now();
Logger.getGlobal().info("Time: " + time + " Deadline: " + project.getDeadline());
if (time.isAfter(project.getDeadline())) {
if (time.isAfter(project.getDeadline()) && groupId != null) {
return new CheckResult<>(HttpStatus.FORBIDDEN, "Project deadline has passed", null);
}
return new CheckResult<>(HttpStatus.OK, "", groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void testAddGroupScore() throws Exception {
when(groupFeedbackUtil.checkGroupFeedbackUpdate(groupFeedbackEntity.getGroupId(), groupFeedbackEntity.getProjectId(), getMockUser(), HttpMethod.POST))
.thenReturn(new CheckResult<>(HttpStatus.OK, "", null));
when(groupFeedbackUtil.checkGroupFeedbackUpdateJson(argThat(
json -> json.getScore() == groupFeedbackEntity.getScore() && json.getFeedback().equals(groupFeedbackEntity.getFeedback())), eq(groupFeedbackEntity.getProjectId())))
json -> Objects.equals(json.getScore(), groupFeedbackEntity.getScore()) && json.getFeedback().equals(groupFeedbackEntity.getFeedback())), eq(groupFeedbackEntity.getProjectId())))
.thenReturn(new CheckResult<>(HttpStatus.OK, "", null));
when(groupFeedbackRepository.save(any())).thenReturn(groupFeedbackEntity);
when(entityToJsonConverter.groupFeedbackEntityToJson(groupFeedbackEntity)).thenReturn(groupFeedbackJson);
Expand All @@ -292,7 +292,7 @@ public void testAddGroupScore() throws Exception {
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().json(objectMapper.writeValueAsString(groupFeedbackJson)));
verify(groupFeedbackRepository, times(1)).save(argThat(
groupFeedback -> groupFeedback.getScore() == groupFeedbackEntity.getScore() &&
groupFeedback -> Objects.equals(groupFeedback.getScore(), groupFeedbackEntity.getScore()) &&
groupFeedback.getFeedback().equals(groupFeedbackEntity.getFeedback()) &&
groupFeedback.getGroupId() == groupFeedbackEntity.getGroupId() &&
groupFeedback.getProjectId() == groupFeedbackEntity.getProjectId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public void testCheckOnSubmit() {
result = submissionUtil.checkOnSubmit(projectEntity.getId(), userEntity);
assertEquals(HttpStatus.OK, result.getStatus());
assertNull(result.getData());

/* Deadline passed when user is admin, should still be allowed */
projectEntity.setDeadline(OffsetDateTime.now().minusDays(1));
result = submissionUtil.checkOnSubmit(projectEntity.getId(), userEntity);
assertEquals(HttpStatus.OK, result.getStatus());

/* User not part of group and not admin */
when(projectUtil.isProjectAdmin(projectEntity.getId(), userEntity))
Expand All @@ -171,6 +176,7 @@ public void testCheckOnSubmit() {
result = submissionUtil.checkOnSubmit(projectEntity.getId(), userEntity);
assertEquals(HttpStatus.FORBIDDEN, result.getStatus());


/* GroupCluster in archived course */
when(groupClusterRepository.inArchivedCourse(groupEntity.getClusterId())).thenReturn(true);
result = submissionUtil.checkOnSubmit(projectEntity.getId(), userEntity);
Expand Down
Binary file not shown.

0 comments on commit 1ae569a

Please sign in to comment.