Skip to content

Commit

Permalink
Fix bug where visible but non-editable files were missing in run/grading
Browse files Browse the repository at this point in the history
  • Loading branch information
sealexan committed Dec 13, 2023
1 parent 4d63ee1 commit bd750df
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Mock-Course-Re
Submodule Mock-Course-Re updated 59 files
+6 −20 01_intro/hello_world/config.toml
+21 −8 01_intro/hello_world/grading/tests.py
+135 −1 01_intro/hello_world/instructions_en.md
+9 −1 01_intro/hello_world/solution/script.py
+3 −1 01_intro/hello_world/task/script.py
+32 −0 02_basics/arithmetic_expression/config.toml
+4 −15 02_basics/arithmetic_expression/grading/tests.py
+0 −0 02_basics/arithmetic_expression/instructions_en.md
+5 −0 02_basics/arithmetic_expression/solution/script.py
+5 −14 02_basics/arithmetic_expression/task/script.py
+11 −0 02_basics/arithmetic_expression/task/tests.py
+2 −1 02_basics/config.toml
+0 −9 02_basics/formula/solution/script.py
+0 −12 02_basics/formula/task/tests.py
+0 −23 02_basics/formula/temp
+31 −0 02_basics/friendly_pairs/config.toml
+133 −0 02_basics/friendly_pairs/grading/tests.py
+21 −0 02_basics/friendly_pairs/instructions_en.md
+21 −0 02_basics/friendly_pairs/solution/script.py
+9 −0 02_basics/friendly_pairs/task/script.py
+19 −0 02_basics/friendly_pairs/task/tests.py
+3 −19 02_basics/variable_assignment/config.toml
+4 −5 02_basics/variable_assignment/grading/tests.py
+10 −5 02_basics/variable_assignment2/config.toml
+30 −0 02_basics/variable_assignment2/grading/tests.py
+2 −0 02_basics/variable_assignment2/instructions_de.md
+2 −0 02_basics/variable_assignment2/instructions_en.md
+5 −0 02_basics/variable_assignment2/solution/script.py
+9 −0 02_basics/variable_assignment2/task/script.py
+10 −0 02_basics/variable_assignment2/task/tests.py
+ 03_classes/carpark_multiple_inheritance/-hidden/cars.graffle
+15 −18 03_classes/carpark_multiple_inheritance/config.toml
+27 −0 03_classes/carpark_multiple_inheritance/grading/tests.py
+96 −0 03_classes/carpark_multiple_inheritance/grading/tests_1_inheritance.py
+79 −59 03_classes/carpark_multiple_inheritance/grading/tests_2a_combustion_car.py
+80 −61 03_classes/carpark_multiple_inheritance/grading/tests_2b_electric_car.py
+143 −114 03_classes/carpark_multiple_inheritance/grading/tests_2c_hybrid_car.py
+3 −3 03_classes/carpark_multiple_inheritance/instructions_en.md
+ 03_classes/carpark_multiple_inheritance/resource/cars.png
+0 −0 03_classes/carpark_multiple_inheritance/solution/car.py
+0 −0 03_classes/carpark_multiple_inheritance/solution/combustion_car.py
+0 −0 03_classes/carpark_multiple_inheritance/solution/electric_car.py
+0 −0 03_classes/carpark_multiple_inheritance/solution/hybrid_car.py
+0 −0 03_classes/carpark_multiple_inheritance/task/car.py
+0 −0 03_classes/carpark_multiple_inheritance/task/combustion_car.py
+0 −0 03_classes/carpark_multiple_inheritance/task/electric_car.py
+0 −0 03_classes/carpark_multiple_inheritance/task/hybrid_car.py
+2 −3 03_classes/carpark_multiple_inheritance/task/script.py
+25 −0 03_classes/carpark_multiple_inheritance/task/tests.py
+0 −70 03_classes/cars/grading/basic.py
+0 −126 03_classes/cars/grading/info_hiding.py
+0 −89 03_classes/cars/grading/inheritance.py
+0 −27 03_classes/cars/grading/tests.py
+0 −23 03_classes/cars/task/test_cars.py
+1 −1 03_classes/config.toml
+1 −1 README.md
+1 −0 config.toml
+92 −58 universal/harness.py
+351 −0 universal/testing_task_harness.py
13 changes: 13 additions & 0 deletions src/main/kotlin/ch/uzh/ifi/access/service/CourseLifecycle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ class CourseLifecycle(
task.files.forEach { file ->
file.enabled = false
}
// TODO: maybe do this in a less convoluted fashion
// reset all file attributes to false
taskDTO.files?.let {
(it.instruction + it.visible + it.grading + it.editable + it.solution).forEach { filePath ->
val file = createOrUpdateTaskFile(task, taskPath, filePath)
file.instruction = false
file.visible = false
file.grading = false
file.editable = false
file.solution = false
}
}
// set desired file attributes
taskDTO.files?.instruction?.forEach { filePath ->
createOrUpdateTaskFile(task, taskPath, filePath).instruction = true
}
Expand Down
49 changes: 37 additions & 12 deletions src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ class CourseService(
.toList()
}

fun getVisibleNonEditableFiles(taskId: Long?): List<TaskFile> {
return taskFileRepository.findByTask_IdAndEnabledTrue(taskId)
.filter { file: TaskFile -> file.visible && !file.editable }
.toList()
}

private fun readLogsFile(path: Path): String {
val logsFile = path.resolve("logs.txt").toFile()

Expand Down Expand Up @@ -362,6 +368,31 @@ class CourseService(
}
dockerClient.createContainerCmd(it).use { containerCmd ->
val submissionDir = workingDir.resolve("submissions").resolve(submission.id.toString())
// add submission files (supplied by the frontend)
submission.files.forEach { file ->
file.taskFile?.path?.let { it1 -> // TODO: cleanup
file.content?.let { it2 ->
createLocalFile(
submissionDir,
it1,
it2
)
}
}
}
// add visible but not editable files (because these are not part of the submission files)
getVisibleNonEditableFiles(task.id)
.forEach(Consumer { file: TaskFile ->
file.path?.let { it1 -> // TODO: cleanup
file.template?.let { it2 ->
createLocalFile(
submissionDir,
it1, it2
)
}
}
})
// add grading files if submission is graded
if (submission.isGraded) {
getGradingFiles(task.id)
.forEach(Consumer { file: TaskFile ->
Expand All @@ -383,18 +414,6 @@ class CourseService(
}
}
}
submission.files.forEach { file ->
file.taskFile?.path?.let { it1 -> // TODO: cleanup
file.content?.let { it2 ->
createLocalFile(
submissionDir,
it1,
it2
)
}
}
}

// The student code is run on the tmpfs.
// Main reason for this is that we have no other way of enforcing a disk quota.
// TODO: make this size configurable in task config.toml?
Expand Down Expand Up @@ -543,6 +562,12 @@ fi
return courseLifecycle.updateFromRepository(existingCourse)
}

@Transactional
fun updateCourseFromDirectory(courseSlug: String, directory: Path): Course {
val existingCourse = getCourseBySlug(courseSlug)
return courseLifecycle.updateFromDirectory(existingCourse, directory )
}

@Transactional
fun deleteCourse(courseSlug: String): Course {
val existingCourse = getCourseBySlug(courseSlug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class CourseLifecycleTests(
courseService.getCourseBySlug("access-mock-course")
}

@Test
@WithMockUser(username="[email protected]", authorities = ["supervisor"])
@Order(0)
fun `Course update succeeds`() {
val absolutePath = Paths.get(File("Mock-Course-Re").absolutePath)
courseService.updateCourseFromDirectory("access-mock-course", absolutePath)
}

fun getCourse(): CourseWorkspace {
return courseService.getCourseWorkspaceBySlug("access-mock-course")
}
Expand Down

0 comments on commit bd750df

Please sign in to comment.