/** * Determines if topic is provided by plugin. * NOTE: currently jcommune provides two topic types: "Code review" and "Discussion" all other * topic types are provided by plugins * * @return true if topic is provided by plugin otherwise false */ public boolean isPlugable() { return type != null && !(this.isCodeReview() || type.equals(TopicTypeName.DISCUSSION.getName())); }
/** * {@inheritDoc} */ @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.CLOSE_TOPICS')") @Override public void closeTopic(Topic topic) { if (topic.isCodeReview()) { throw new AccessDeniedException("Close for code review"); } topic.setClosed(true); dao.saveOrUpdate(topic); }
/** * Shows edit topic page with form, populated with fields from topic. * * @param topicId the id of selected Topic * @return {@code ModelAndView} * @throws NotFoundException when topic or branch not found */ @RequestMapping(value = "/topics/{topicId}/edit", method = RequestMethod.GET) public ModelAndView editTopicPage(@PathVariable(TOPIC_ID) Long topicId) throws NotFoundException { Topic topic = topicFetchService.get(topicId); if (topic.isCodeReview()) { throw new AccessDeniedException("Edit page for code review"); } TopicDto topicDto = new TopicDto(topic); return new ModelAndView(TOPIC_VIEW) .addObject(BRANCH_ID, topic.getBranch().getId()) .addObject(TOPIC_DTO, topicDto) .addObject(POLL, topic.getPoll()) .addObject(SUBMIT_URL, "/topics/" + topicId + "/edit") .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(topic)); }
/** * Set mail about removing topic. * * @param recipient Recipient for which send notification * @param topic Current topic * @param curUser User that removed the topic */ public void sendRemovingTopicMail(JCUser recipient, Topic topic, String curUser) { Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(USER, recipient); model.put(RECIPIENT_LOCALE, locale); model.put(CUR_USER, curUser); //Topic not exist more and user not subscribed to branch, so simply redirect to branch model.put(LINK_UNSUBSCRIBE, this.getDeploymentRootUrl() + "/branches/" + topic.getBranch().getId()); model.put(TOPIC, topic); try { String subjectTemplate = REMOVE_TOPIC_SUBJECT_TEMPLATE; String messageBodyTemplate = REMOVE_TOPIC_MESSAGE_BODY_TEMPLATE; if (topic.isCodeReview()) { subjectTemplate = REMOVE_CODE_REVIEW_SUBJECT_TEMPLATE; messageBodyTemplate = REMOVE_CODE_REVIEW_MESSAGE_BODY_TEMPLATE; } String subject = messageSource.getMessage(subjectTemplate, new Object[]{}, locale); this.sendEmail(recipient.getEmail(), subject, model, messageBodyTemplate); } catch (MailingFailedException e) { LOGGER.error("Failed to sent mail about removing topic or code review for user: " + recipient.getUsername()); } }
/** * 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()); }
/** * {@inheritDoc} * * @throws AccessDeniedException besides other reasons, always throws this when Code Review is edited because it * shouldn't be possible to edit it. More details on requirements can be found here * <a href="http://jtalks.org/display/jcommune/1.1+Larks">here</a>. */ @Override @PreAuthorize("(hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OWN_POSTS')) or " + "(not hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OTHERS_POSTS'))") public void updateTopic(Topic topic, Poll poll) { if (topic.isCodeReview()) { throw new AccessDeniedException("It is not allowed to edit Code Review!"); } Post post = topic.getFirstPost(); post.updateModificationDate(); if (poll != null && poll.getEndingDate() != null) { topic.getPoll().setEndingDate(poll.getEndingDate()); } dao.saveOrUpdate(topic); logger.debug("Topic id={} updated", topic.getId()); }
/** * Checks if current user can create comments in specified topic * * @param topic topic to check permission * @throws AccessDeniedException if user can't create comments in specified topic */ private void assertCommentAllowed(Topic topic) { if (topic.isCodeReview()) { permissionService.checkPermission(topic.getBranch().getId(), AclClassName.BRANCH, BranchPermission.LEAVE_COMMENTS_IN_CODE_REVIEW); } else if (topic.isPlugable()) { assertCommentsAllowedForPlugableTopic(topic); } else { throw new AccessDeniedException("Adding comments not allowed for core topic types"); } if (topic.isClosed()) { permissionService.checkPermission(topic.getBranch().getId(), AclClassName.BRANCH, BranchPermission.CLOSE_TOPICS); } }
/** * Populate topicUrl, readIconUrl, unreadIconUrl parameters of dto for topics (Discussion and CodeReview) * * @param dto dto to be populated * * @return populated dto */ private TopicDto populateCoreTopicDto(TopicDto dto) { dto.setTopicUrl(PREFIX + dto.getTopic().getId()); dto.setPostUrlPrefix("/posts/"); if (dto.getTopic().isCodeReview()) { dto.setUnreadIconUrl(CODE_REVIEW_NEW_POSTS); dto.setReadIconUrl(CODE_REVIEW_NO_NEW_POSTS); } else if (dto.getTopic().isClosed()) { dto.setUnreadIconUrl(DISCUSSION_CLOSED_NEW_POSTS); dto.setReadIconUrl(DISCUSSION_CLOSED_NO_NEW_POSTS); } else { dto.setUnreadIconUrl(DISCUSSION_NEW_POSTS); dto.setReadIconUrl(DISCUSSION_NO_NEW_POSTS); } return dto; } }
topic.setSticked(topicDto.isSticked()); topic.setBranch(topicDto.getBranch()); if (topicDto.isCodeReview()) { bodyText = wrapWithCodeTag(bodyText);