Skip to content

Commit

Permalink
allow instructors to open all assessments
Browse files Browse the repository at this point in the history
  • Loading branch information
Feuermagier committed Oct 25, 2024
1 parent 4574311 commit a7e937c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Annotation(AnnotationDTO dto, MistakeType mistakeType) {
this.source = dto.source() != null ? dto.source() : AnnotationSource.UNKNOWN;
this.customMessage = dto.customMessageForJSON();
this.customScore = dto.customPenaltyForJSON();
this.classifiers = dto.classifiers();
this.classifiers = dto.classifiers() != null ? dto.classifiers() : List.of();
this.annotationLimit = dto.annotationLimit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.kit.kastel.sdq.artemis4j.client.AssessmentStatsDTO;
import edu.kit.kastel.sdq.artemis4j.client.ProgrammingExerciseDTO;
import edu.kit.kastel.sdq.artemis4j.client.ProgrammingSubmissionDTO;
import edu.kit.kastel.sdq.artemis4j.client.ResultDTO;
import edu.kit.kastel.sdq.artemis4j.grading.metajson.AnnotationMappingException;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.GradingConfig;

Expand Down Expand Up @@ -100,7 +101,6 @@ public List<ProgrammingSubmission> fetchSubmissions(int correctionRound) throws

/**
* Fetches all submissions from correction round 1 and 2 (if enabled).
*
*/
public List<ProgrammingSubmission> fetchSubmissions() throws ArtemisNetworkException {
List<ProgrammingSubmission> submissions = new ArrayList<>(this.fetchSubmissions(0));
Expand All @@ -116,7 +116,7 @@ public List<ProgrammingSubmission> fetchSubmissions() throws ArtemisNetworkExcep
* the assessment.
*
* @return An empty optional if no submission was available to lock, otherwise
* the assessment
* the assessment
*/
public Optional<Assessment> tryLockNextSubmission(int correctionRound, GradingConfig gradingConfig)
throws AnnotationMappingException, ArtemisNetworkException {
Expand Down Expand Up @@ -146,7 +146,7 @@ public Optional<Assessment> tryLockNextSubmission(int correctionRound, GradingCo
* i.e. a single user may lock the same submission multiple times.
*
* @return An empty optional if a *different* user has already locked the
* submission, otherwise the assessment
* submission, otherwise the assessment
* @throws AnnotationMappingException If the annotations that were already
* present could not be mapped given the
* gradingConfig
Expand Down Expand Up @@ -180,10 +180,7 @@ public Optional<Assessment> tryLockSubmission(long submissionId, int correctionR
}
var result = locked.results().get(0);

// Locking was successful if we are the assessor
// The webui of Artemis does the same check
if (result.assessor() == null
|| result.assessor().id() != this.getConnection().getAssessor().getId()) {
if (!this.canAssess(result)) {
return Optional.empty();
}

Expand Down Expand Up @@ -211,4 +208,13 @@ private void assertGradingConfigValid(GradingConfig gradingConfig) {
throw new IllegalArgumentException("Grading config is not valid for this exercise");
}
}

private boolean canAssess(ResultDTO result) throws ArtemisNetworkException {
// We can assess if either no assessor is set, we are the assessor,
// or if we are an instructor (who can overwrite any assessment)
var assessor = this.getConnection().getAssessor();
return result.assessor() == null
|| result.assessor().id() != assessor.getId()
|| this.getCourse().isInstructor(assessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import edu.kit.kastel.sdq.artemis4j.ArtemisNetworkException;
import edu.kit.kastel.sdq.artemis4j.client.AssessmentStatsDTO;
import edu.kit.kastel.sdq.artemis4j.client.ResultDTO;
import edu.kit.kastel.sdq.artemis4j.client.TextExerciseDTO;
import edu.kit.kastel.sdq.artemis4j.client.TextSubmissionDTO;

Expand Down Expand Up @@ -152,14 +153,20 @@ public Optional<TextAssessment> tryLockNextSubmission(int correctionRound) throw
}
var result = locked.results().get(0);

// Locking was successful if we are the assessor
// The webui of Artemis does the same check
if (result.assessor() == null
|| result.assessor().id() != this.getConnection().getAssessor().getId()) {
if (this.canAssess(result)) {
return Optional.empty();
}

var submission = new TextSubmission(locked, this, correctionRound);
return Optional.of(new TextAssessment(result, submission, correctionRound));
}

private boolean canAssess(ResultDTO result) throws ArtemisNetworkException {
// We can assess if either no assessor is set, we are the assessor,
// or if we are an instructor (who can overwrite any assessment)
var assessor = this.getConnection().getAssessor();
return result.assessor() == null
|| result.assessor().id() != assessor.getId()
|| this.getCourse().isInstructor(assessor);
}
}

0 comments on commit a7e937c

Please sign in to comment.