/** * @return poll in topic */ public Poll getPoll() { return topic.getPoll(); }
/** * Saves topic after edit topic form submission. * * @param topicDto Dto populated in form * @param result validation result * @param topicId the current topicId * @return {@code ModelAndView} with redirect to saved topic or the same page with validation errors, if any * @throws NotFoundException when topic or branch not found */ @RequestMapping(value = "/topics/{topicId}/edit", method = RequestMethod.POST) public ModelAndView editTopic(@Valid @ModelAttribute TopicDto topicDto, BindingResult result, @PathVariable(TOPIC_ID) Long topicId) throws NotFoundException { Topic topic = topicFetchService.get(topicId); if (result.hasErrors()) { 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)); } topicDto.fillTopic(topic); topicModificationService.updateTopic(topic, topicDto.getPoll()); return new ModelAndView(REDIRECT_URL + topicId); }
/** * 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)); }
/** * Creates a poll for the topic or updates an existing one. * On update all poll items with the same name remain unchanged, * except probably their position in list. Users, previously voted * for the deleted items can NOT vote again. * * @param poll poll data from UI form * @param persistentTopic topic from a database */ private void createPoll(Poll poll, Topic persistentTopic) { if (poll != null && poll.isHasPoll()) { if (persistentTopic.getPoll() == null) { persistentTopic.setPoll(poll); poll.setTopic(persistentTopic); pollService.createPoll(poll); } } }
/** * {@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()); }
subscriptionService.subscribe(topic); createPoll(topicDto.getPoll(), topic); userService.notifyAndMarkNewlyMentionedUsers(topic.getFirstPost()); lastReadPostService.markTopicAsRead(topic);