Skip to content

Commit

Permalink
Merge pull request #295 from SELab-2/frontend
Browse files Browse the repository at this point in the history
Frontend
  • Loading branch information
Aqua-sc authored May 23, 2024
2 parents 7d193fe + ce6dd2c commit 7549026
Show file tree
Hide file tree
Showing 78 changed files with 1,746 additions and 1,026 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private Map<Long, Optional<SubmissionEntity>> getLatestSubmissionsForProject(lon
@GetMapping(ApiRoutes.PROJECT_BASE_PATH + "/{projectid}/submissions") //Route to get all submissions for a project
@Roles({UserRole.teacher, UserRole.student})
public ResponseEntity<?> getSubmissions(@PathVariable("projectid") long projectid, Auth auth) {
try {
CheckResult<Void> checkResult = projectUtil.isProjectAdmin(projectid, auth.getUserEntity());
if (!checkResult.getStatus().equals(HttpStatus.OK)) {
return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage());
Expand Down Expand Up @@ -170,9 +169,6 @@ public ResponseEntity<?> getSubmissions(@PathVariable("projectid") long projecti
}

return ResponseEntity.ok(res);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class GroupFeedbackJson {

private float score;
private Float score;
private String feedback;

private long groupId;
Expand All @@ -11,15 +11,15 @@ public class GroupFeedbackJson {
public GroupFeedbackJson() {
}

public GroupFeedbackJson(float score, String feedback, long groupId, long projectId) {
public GroupFeedbackJson(Float score, String feedback, long groupId, long projectId) {
this.score = score;
this.feedback = feedback;
this.groupId = groupId;
this.projectId = projectId;
}


public float getScore() {
public Float getScore() {
return score;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public class GroupFeedbackJsonWithProject {
private String projectUrl;
private GroupFeedbackJson groupFeedback;

private float maxScore;
private Integer maxScore;
private Long projectId;


public GroupFeedbackJsonWithProject(String projectName, String projectUrl, Long projectId,
GroupFeedbackJson groupFeedback, float maxScore) {
GroupFeedbackJson groupFeedback, Integer maxScore) {
this.projectName = projectName;
this.projectUrl = projectUrl;
this.groupFeedback = groupFeedback;
Expand Down Expand Up @@ -43,11 +43,11 @@ public void setGroupFeedback(GroupFeedbackJson groupFeedback) {
this.groupFeedback = groupFeedback;
}

public float getMaxScore() {
public Integer getMaxScore() {
return maxScore;
}

public void setMaxScore(float maxScore) {
public void setMaxScore(Integer maxScore) {
this.maxScore = maxScore;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ugent.pidgeon.model.submissionTesting;

import java.util.List;
import java.util.logging.Logger;
import org.hibernate.usertype.LoggableUserType;

public class DockerTemplateTestOutput implements DockerOutput{
private final List<DockerSubtestResult> subtestResults;
Expand All @@ -24,9 +26,12 @@ public String getFeedbackAsString(){
//json representation of the tests
StringBuilder feedback = new StringBuilder("{\"subtests\": [");
for (DockerSubtestResult subtestResult : subtestResults) {
feedback.append(subtestResult.getFeedbackAsString()).append(",");
feedback.append(subtestResult.getFeedbackAsString())
.append(",");
}
feedback.append("]");
feedback.deleteCharAt(feedback.length() - 1); // remove last comma ,
feedback.append("]}");
Logger.getGlobal().info(feedback.toString());
return feedback.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,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 @@ -56,11 +56,11 @@ public String getFeedback() {
}


public float getScore() {
public Float getScore() {
return grade;
}

public void setScore(float score) {
public void setScore(Float score) {
this.grade = score;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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 @@ -6,6 +6,7 @@
import com.ugent.pidgeon.postgre.models.TestEntity;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -40,8 +41,12 @@ public DockerOutput runDockerTest(ZipFile file, TestEntity testEntity, Path outp
// Init container and add input files
try {


model.addZipInputFiles(file);
model.addUtilFiles(Filehandler.getTestExtraFilesPath(projectId).resolve(Filehandler.EXTRA_TESTFILES_FILENAME));
Path path = Filehandler.getTestExtraFilesPath(projectId).resolve(Filehandler.EXTRA_TESTFILES_FILENAME);
if (Files.exists(path)) {
model.addUtilFiles(path);
}
DockerOutput output;

if (testTemplate == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,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 @@ -288,7 +288,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 @@ -154,6 +154,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 @@ -168,6 +173,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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public void testRunDockerTest() throws IOException {

verify(dockerModel, times(1)).addZipInputFiles(file);
verify(dockerModel, times(1)).cleanUp();
verify(dockerModel, times(1)).addUtilFiles(extraFilesPathResolved);
assertEquals(1, filehandlerCalled.get());

/* artifacts are empty */
Expand All @@ -128,7 +127,6 @@ public void testRunDockerTest() throws IOException {
assertEquals(dockerTemplateTestOutput, result);
verify(dockerModel, times(2)).addZipInputFiles(file);
verify(dockerModel, times(2)).cleanUp();
verify(dockerModel, times(2)).addUtilFiles(extraFilesPathResolved);
assertEquals(1, filehandlerCalled.get());

/* aritifacts are null */
Expand All @@ -137,7 +135,6 @@ public void testRunDockerTest() throws IOException {
assertEquals(dockerTemplateTestOutput, result);
verify(dockerModel, times(3)).addZipInputFiles(file);
verify(dockerModel, times(3)).cleanUp();
verify(dockerModel, times(3)).addUtilFiles(extraFilesPathResolved);
assertEquals(1, filehandlerCalled.get());

/* No template */
Expand All @@ -147,7 +144,6 @@ public void testRunDockerTest() throws IOException {
assertEquals(dockerTestOutput, result);
verify(dockerModel, times(4)).addZipInputFiles(file);
verify(dockerModel, times(4)).cleanUp();
verify(dockerModel, times(4)).addUtilFiles(extraFilesPathResolved);

/* Error gets thrown */
when(dockerModel.runSubmission(testEntity.getDockerTestScript())).thenThrow(new RuntimeException("Error"));
Expand Down
Binary file not shown.
44 changes: 0 additions & 44 deletions frontend/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="Official UGent submission platform. Effortlessly manage courses and projects, automatically test and assess code."
/>
<link rel="apple-touch-icon" href="/logo192.png" />

Expand Down
1 change: 1 addition & 0 deletions frontend/public/docker_langauges/bash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/docker_langauges/custom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/docker_langauges/haskell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/docker_langauges/node-js.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/public/docker_langauges/python.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7549026

Please sign in to comment.