Search in sources :

Example 1 with CourseWideContext

use of de.tum.in.www1.artemis.domain.metis.CourseWideContext in project ArTEMiS by ls1intum.

the class PostService method getAllPostsByCourseWideContext.

/**
 * Checks course, user and post validity,
 * retrieves all posts with a certain course-wide context by course id
 * and ensures that sensitive information is filtered out
 *
 * @param courseId          id of the course the post belongs to
 * @param courseWideContext specific course-wide context to filter course get posts for
 * @return list of posts for a certain course-wide context
 */
public List<Post> getAllPostsByCourseWideContext(Long courseId, CourseWideContext courseWideContext) {
    final User user = userRepository.getUserWithGroupsAndAuthorities();
    // checks
    final Course course = preCheckUserAndCourse(user, courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
    // retrieve posts
    List<Post> coursePosts = postRepository.findPostsForCourseWideContext(courseId, courseWideContext);
    // protect sample solution, grading instructions, etc.
    coursePosts.stream().map(Post::getExercise).filter(Objects::nonNull).forEach(Exercise::filterSensitiveInformation);
    return coursePosts;
}
Also used : User(de.tum.in.www1.artemis.domain.User) Exercise(de.tum.in.www1.artemis.domain.Exercise) Post(de.tum.in.www1.artemis.domain.metis.Post) Course(de.tum.in.www1.artemis.domain.Course)

Example 2 with CourseWideContext

use of de.tum.in.www1.artemis.domain.metis.CourseWideContext in project ArTEMiS by ls1intum.

the class DatabaseUtilService method createBasicPosts.

private List<Post> createBasicPosts(Course courseContext, CourseWideContext[] courseWideContexts) {
    List<Post> posts = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        Post postToAdd = createBasicPost(i);
        postToAdd.setCourse(courseContext);
        postToAdd.setCourseWideContext(courseWideContexts[i]);
        postRepository.save(postToAdd);
        posts.add(postToAdd);
    }
    return posts;
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Example 3 with CourseWideContext

use of de.tum.in.www1.artemis.domain.metis.CourseWideContext in project Artemis by ls1intum.

the class DatabaseUtilService method createBasicPosts.

private List<Post> createBasicPosts(Course courseContext, CourseWideContext[] courseWideContexts) {
    List<Post> posts = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        Post postToAdd = createBasicPost(i);
        postToAdd.setCourse(courseContext);
        postToAdd.setCourseWideContext(courseWideContexts[i]);
        postRepository.save(postToAdd);
        posts.add(postToAdd);
    }
    return posts;
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Aggregations

Post (de.tum.in.www1.artemis.domain.metis.Post)3 ExerciseHint (de.tum.in.www1.artemis.domain.hestia.ExerciseHint)2 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)2 Course (de.tum.in.www1.artemis.domain.Course)1 Exercise (de.tum.in.www1.artemis.domain.Exercise)1 User (de.tum.in.www1.artemis.domain.User)1