/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.CREATE_POSTS') " + "and #post.userCreated.username != principal.username") public Post vote(Post post, PostVote vote) { JCUser currentUser = userService.getCurrentUser(); if (!post.canBeVotedBy(currentUser, vote.isVotedUp())) { logger.info("User [{}] tries to vote for post with id={} in same direction more than one time", currentUser.getUsername(), post.getId()); throw new AccessDeniedException("User can't vote in same direction more than one time"); } vote.setUser(currentUser); int ratingChanges = post.calculateRatingChanges(vote); post.putVote(vote); getDao().saveOrUpdate(post); getDao().changeRating(post.getId(), ratingChanges); return post; }