Skip to content

Commit

Permalink
improve handling of online courses and lti outcome urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Krusche committed Jun 14, 2019
1 parent b5dcf8e commit 3e43bbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public interface ExerciseRepository extends JpaRepository<Exercise, Long> {
List<Exercise> findByCourseId(@Param("courseId") Long courseId);

/**
* Select Exercise for Course ID WHERE there does not exist any LtiOutcomeUrl for this exercise (-> this is not an online exercise) OR there does exist an LtiOutcomeUrl for the
* current user (-> user has started exercise once using LTI)
* Select Exercise for Course ID WHERE there does exist an LtiOutcomeUrl for the current user (-> user has started exercise once using LTI)
*/
@Query("select e from Exercise e where e.course.id = :#{#courseId} and ((not exists(select l from LtiOutcomeUrl l where e = l.exercise)) or exists (select l2 from LtiOutcomeUrl l2 where e = l2.exercise and l2.user.login = :#{#principal.name})) ")
@Query("select e from Exercise e where e.course.id = :#{#courseId} and exists (select l from LtiOutcomeUrl l where e = l.exercise and l.user.login = :#{#principal.name})")
List<Exercise> findByCourseIdWhereLtiOutcomeUrlExists(@Param("courseId") Long courseId, @Param("principal") Principal principal);

@Query("select e from Exercise e where e.course.id = :#{#courseId}")
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/de/tum/in/www1/artemis/service/ExerciseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,17 @@ public List<Exercise> findAllForCourse(Course course, boolean withLtiOutcomeUrlE
exercises = exerciseRepository.findByCourseId(course.getId());
}
else if (authCheckService.isStudentInCourse(course, user)) {

if (course.isOnlineCourse() && withLtiOutcomeUrlExisting) {
// students in only courses can only see exercises where the lti outcome url exists, otherwise the result cannot be reported later on
exercises = exerciseRepository.findByCourseIdWhereLtiOutcomeUrlExists(course.getId(), principal);
}
else {
exercises = exerciseRepository.findByCourseId(course.getId());
}

// user is student for this course and might not have the right to see it so we have to filter
exercises = withLtiOutcomeUrlExisting ? exerciseRepository.findByCourseIdWhereLtiOutcomeUrlExists(course.getId(), principal)
: exerciseRepository.findByCourseId(course.getId());

// filter out exercises that are not released (or explicitly made visible to students) yet
exercises = exercises.stream().filter(Exercise::isVisibleToStudents).collect(Collectors.toList());
}
Expand Down

0 comments on commit 3e43bbb

Please sign in to comment.