/** * {@inheritDoc} */ @Override @PreAuthorize("(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS') and " + "#post.userCreated.username == principal.username) or " + "(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OTHERS_POSTS') and " + "#post.userCreated.username != principal.username)") public void deletePost(Post post) { JCUser postCreator = post.getUserCreated(); postCreator.setPostCount(postCreator.getPostCount() - 1); Topic topic = post.getTopic(); topic.removePost(post); Branch branch = topic.getBranch(); boolean deletedPostIsLastPostInBranch = branch.isLastPost(post); if (deletedPostIsLastPostInBranch) { branch.clearLastPost(); } // todo: event API? topicDao.saveOrUpdate(topic); securityService.deleteFromAcl(post); /* only the creator of the post should be notified when it's removed. */ notificationService.subscribedEntityChanged(post); if (deletedPostIsLastPostInBranch) { branchLastPostService.refreshLastPostInBranch(branch); } logger.debug("Deleted post id={}", post.getId()); }
/** * Constructor which fills dto fields from user. * * @param user copying source */ public UserProfileDto(JCUser user) { this.userId = user.getId(); this.firstName = user.getFirstName(); this.lastName = user.getLastName(); this.email = user.getEmail(); this.signature = user.getSignature(); this.pageSize = user.getPageSize(); this.location = user.getLocation(); this.postCount = user.getPostCount(); this.registrationDate = user.getRegistrationDate(); this.lastLogin = user.getLastLogin(); }
/** * Performs actual topic deletion. Deletes all topic related data and * recalculates user's post count. * * @param topic topic to delete * @return branch without deleted topic */ private Branch deleteTopicSilent(Topic topic) { List<Post> topicPosts = topic.getPosts(); for (Post post : topicPosts) { JCUser user = post.getUserCreated(); user.setPostCount(user.getPostCount() - 1); } Branch branch = topic.getBranch(); Post lastPostInBranch = branch.getLastPost(); boolean branchLastPostFromDeletedTopic = topicPosts.contains(lastPostInBranch); if (branchLastPostFromDeletedTopic) { branch.clearLastPost(); } branch.deleteTopic(topic); branchDao.saveOrUpdate(branch); if (branchLastPostFromDeletedTopic) { branchLastPostService.refreshLastPostInBranch(branch); } securityService.deleteFromAcl(Topic.class, topic.getId()); return branch; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#branchId, 'BRANCH', 'BranchPermission.CREATE_POSTS')") public Post replyToTopic(long topicId, String answerBody, long branchId) throws NotFoundException { Topic topic = topicFetchService.getTopicSilently(topicId); this.assertPostingIsAllowed(topic); JCUser currentUser = userService.getCurrentUser(); currentUser.setPostCount(currentUser.getPostCount() + 1); Post answer = new Post(currentUser, answerBody); topic.addPost(answer); topic.removeDraftOfUser(currentUser); if (currentUser.isAutosubscribe()){ subscriptionService.subscribe(topic); } postDao.saveOrUpdate(answer); Branch branch = topic.getBranch(); branch.setLastPost(answer); branchDao.saveOrUpdate(branch); dao.saveOrUpdate(topic); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(currentUser).on(answer).flush(); notificationService.subscribedEntityChanged(topic); userService.notifyAndMarkNewlyMentionedUsers(answer); logger.debug("New post in topic. Topic id={}, Post id={}, Post author={}", new Object[]{topicId, answer.getId(), currentUser.getUsername()}); return answer; }
Branch branch = topicDto.getBranch(); currentUser.setPostCount(currentUser.getPostCount() + 1); Topic topic = new Topic(currentUser, topicDto.getTitle()); topic.setAnnouncement(topicDto.isAnnouncement());
copy.setPostCount(user.getPostCount()); copy.setLanguage(user.getLanguage()); copy.setPageSize(user.getPageSize());