/** * Change BB user tag to mark user as already notified * * @param username this user was mentioned * @param postDao service for working with Post objects */ private void markUserAsAlreadyNotified(String username, PostDao postDao) { String initialUserMentioning = format(MENTIONED_NOT_NOTIFIED_USER_TEMPLATE, username); String notifiedUserMentioning = format(MENTIONED_AND_NOTIFIED_USER_TEMPLATE, username); String newPostContent = post.getPostContent().replace(initialUserMentioning, notifiedUserMentioning); post.setPostContent(newPostContent); postDao.saveOrUpdate(post); }
/** * Performs update with security checking. * * @param post an instance of post, that will be updated * @param postContent new content of the post * @throws AccessDeniedException if user tries to update the first post of code review which should be impossible, * see <a href="http://jtalks.org/display/jcommune/1.1+Larks">Requirements</a> * for details */ @PreAuthorize("(hasPermission(#post.id, 'POST', 'GeneralPermission.WRITE') and " + "hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OWN_POSTS')) or " + "(not hasPermission(#post.id, 'POST', 'GeneralPermission.WRITE') and " + "hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OTHERS_POSTS'))") @Override public void updatePost(Post post, String postContent) { Topic postTopic = post.getTopic(); if (postTopic.isCodeReview() && postTopic.getPosts().get(0).getId() == post.getId()) { throw new AccessDeniedException("It is impossible to edit code review!"); } post.setPostContent(postContent); post.updateModificationDate(); this.getDao().saveOrUpdate(post); userService.notifyAndMarkNewlyMentionedUsers(post); logger.debug("Post id={} updated.", post.getId()); }
/** * Fills persistent topic object with data from the current dto * * @param persistentTopic persistent topic * @return the same topic with fields set from dto */ public Topic fillTopic(Topic persistentTopic) { persistentTopic.setTitle(topic.getTitle()); persistentTopic.getFirstPost().setPostContent(bodyText); persistentTopic.setAnnouncement(topic.isAnnouncement()); persistentTopic.setSticked(topic.isSticked()); return topic; } }