use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class AnswerPostService method preparePostAndBroadcast.
/**
* Helper method to prepare the post included in the websocket message and initiate the broadcasting
*
* @param updatedAnswerPost answer post that was updated
* @param course course the answer post belongs to
*/
private void preparePostAndBroadcast(AnswerPost updatedAnswerPost, Course course) {
// we need to explicitly (and newly) add the updated answer post to the answers of the broadcast post to share up-to-date information
Post updatedPost = updatedAnswerPost.getPost();
// remove and add operations on sets identify an AnswerPost by its id; to update a certain property of an existing answer post,
// we need to remove the existing AnswerPost (based on unchanged id in updatedAnswerPost) and add the updatedAnswerPost afterwards
updatedPost.removeAnswerPost(updatedAnswerPost);
updatedPost.addAnswerPost(updatedAnswerPost);
broadcastForPost(new MetisPostDTO(updatedPost, MetisPostAction.UPDATE_POST), course);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostService method deletePostById.
/**
* Checks course, user and post validity,
* determines authority to delete post and deletes the post
*
* @param courseId id of the course the post belongs to
* @param postId id of the post to delete
*/
public void deletePostById(Long courseId, Long postId) {
final User user = userRepository.getUserWithGroupsAndAuthorities();
// checks
final Course course = preCheckUserAndCourse(user, courseId);
Post post = postRepository.findByIdElseThrow(postId);
mayInteractWithPostElseThrow(post, user, course);
preCheckPostValidity(post);
mayUpdateOrDeletePostingElseThrow(post, user, course);
// delete
postRepository.deleteById(postId);
broadcastForPost(new MetisPostDTO(post, MetisPostAction.DELETE_POST), course);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostService method getAllPostsByCourseWideContext.
/**
* Checks course, user and post validity,
* retrieves and filters posts with a certain course-wide context by course id
* and ensures that sensitive information is filtered out
*
* @param postContextFilter filter object
* @return page of posts for a certain course-wide context
*/
public List<Post> getAllPostsByCourseWideContext(PostContextFilter postContextFilter) {
final User user = userRepository.getUserWithGroupsAndAuthorities();
// checks
final Course course = preCheckUserAndCourse(user, postContextFilter.getCourseId());
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
// retrieve posts
List<Post> coursePosts;
// retrieve posts
coursePosts = postRepository.findPostsForCourse(postContextFilter.getCourseId(), postContextFilter.getCourseWideContext(), postContextFilter.getFilterToUnresolved(), postContextFilter.getFilterToOwn(), postContextFilter.getFilterToAnsweredOrReacted(), user.getId());
// protect sample solution, grading instructions, etc.
coursePosts.stream().map(Post::getExercise).filter(Objects::nonNull).forEach(Exercise::filterSensitiveInformation);
return coursePosts;
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostService method getAllExercisePosts.
/**
* Checks course, user, exercise and post validity,
* retrieves and filters posts for an exercise by its id
* and ensures that sensitive information is filtered out
*
* @param postContextFilter filter object
* @return page of posts that belong to the exercise
*/
public List<Post> getAllExercisePosts(PostContextFilter postContextFilter) {
final User user = userRepository.getUserWithGroupsAndAuthorities();
// checks
preCheckUserAndCourse(user, postContextFilter.getCourseId());
preCheckExercise(user, postContextFilter.getCourseId(), postContextFilter.getExerciseId());
// retrieve posts
List<Post> exercisePosts;
exercisePosts = postRepository.findPostsByExerciseId(postContextFilter.getExerciseId(), postContextFilter.getFilterToUnresolved(), postContextFilter.getFilterToOwn(), postContextFilter.getFilterToAnsweredOrReacted(), user.getId());
// protect sample solution, grading instructions, etc.
exercisePosts.forEach(post -> post.getExercise().filterSensitiveInformation());
return exercisePosts;
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostService method createPost.
/**
* Checks course, user and post validity,
* determines the post's author, persists the post,
* and sends a notification to affected user groups
*
* @param courseId id of the course the post belongs to
* @param post post to create
* @return created post that was persisted
*/
public Post createPost(Long courseId, Post post) {
final User user = this.userRepository.getUserWithGroupsAndAuthorities();
// checks
if (post.getId() != null) {
throw new BadRequestAlertException("A new post cannot already have an ID", METIS_POST_ENTITY_NAME, "idexists");
}
final Course course = preCheckUserAndCourse(user, courseId);
mayInteractWithPostElseThrow(post, user, course);
preCheckPostValidity(post);
// set author to current user
post.setAuthor(user);
// set default value display priority -> NONE
post.setDisplayPriority(DisplayPriority.NONE);
if (post.getCourseWideContext() == CourseWideContext.ANNOUNCEMENT) {
// display priority of announcement is set to pinned per default
post.setDisplayPriority(DisplayPriority.PINNED);
Post savedPost = postRepository.save(post);
sendNotification(savedPost, course);
broadcastForPost(new MetisPostDTO(savedPost, MetisPostAction.CREATE_POST), course);
return savedPost;
}
Post savedPost = postRepository.save(post);
// handle posts for plagiarism cases specifically
if (savedPost.getPlagiarismCase() != null) {
plagiarismCaseService.savePostForPlagiarismCaseAndNotifyStudent(savedPost.getPlagiarismCase().getId(), savedPost);
} else {
broadcastForPost(new MetisPostDTO(savedPost, MetisPostAction.CREATE_POST), course);
sendNotification(savedPost, course);
}
return savedPost;
}
Aggregations