File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
main/kotlin/org/dropProject/controllers
test/kotlin/org/dropProject/controllers Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class TeacherAPIController(
6666 val reportService : ReportService ,
6767 val projectGroupRepository : ProjectGroupRepository ,
6868 val assignmentACLRepository : AssignmentACLRepository ,
69- val studentService : StudentService
69+ val studentService : StudentService ,
7070) {
7171
7272 val LOG = LoggerFactory .getLogger(this .javaClass.name)
@@ -303,4 +303,25 @@ class TeacherAPIController(
303303
304304 return ResponseEntity (result, HttpStatus .OK )
305305 }
306+
307+ @GetMapping(value = [" /assignments/{assignmentId}/toggleState" ], produces = [MediaType .APPLICATION_JSON_VALUE ])
308+ @JsonView(JSONViews .TeacherAPI ::class )
309+ @ApiOperation(value = " Deactivate the assignment" )
310+ fun toggleAssignmentState (
311+ @PathVariable(" assignmentId" ) assignmentId : String ,
312+ principal : Principal
313+ ): Boolean {
314+
315+ val assignment = assignmentRepository.findById(assignmentId).orElse(null ) ? : return false
316+ val acl = assignmentACLRepository.findByAssignmentId(assignmentId)
317+
318+ if (principal.realName() != assignment.ownerUserId && acl.find { it.userId == principal.realName() } == null ) {
319+ return false
320+ }
321+
322+ assignment.active = ! assignment.active
323+ assignmentRepository.save(assignment)
324+
325+ return true
326+ }
306327}
Original file line number Diff line number Diff line change @@ -665,4 +665,24 @@ class TeacherAPIControllerTests: APIControllerTests {
665665 assertFalse { submissions[1 ]?.first()?.markedAsFinal == true } // first submission gets unmarked since 1 and 2 are made by the same student
666666 assertTrue { submissions[2 ]?.first()?.markedAsFinal == true }
667667 }
668+
669+ @Test
670+ @DirtiesContext
671+ fun `try to deactivate an assignment` () {
672+ assigneeRepository.deleteAll()
673+ assignmentRepository.deleteAll()
674+ authorRepository.deleteAll()
675+
676+ setup()
677+
678+ val token = generateToken(" teacher1" , mutableListOf (SimpleGrantedAuthority (" ROLE_TEACHER" )), mvc)
679+
680+ this .mvc.perform(
681+ get(" /api/teacher/assignments/testJavaProj/toggleState" )
682+ .contentType(MediaType .APPLICATION_JSON )
683+ .header(" authorization" , testsHelper.header(" teacher1" , token)))
684+ .andExpect(status().isOk()).andExpect(content().string(" true" ))
685+
686+ assertFalse { assignmentRepository.getReferenceById(" testJavaProj" ).active }
687+ }
668688}
You can’t perform that action at this time.
0 commit comments