/** * Handles deletion of announcements * * @param topicId * @param annId * @param response * @throws PortletException */ @RequestMapping(params = "action=deleteAnnouncement") public void actionDeleteAnnouncement( @RequestParam("topicId") Long topicId, @RequestParam("annId") Long annId, ActionRequest request, ActionResponse response) throws PortletException { Topic topic = announcementService.getTopic(topicId); Announcement ann = announcementService.getAnnouncement(annId); UserPermissionChecker upChecker = userPermissionCheckerFactory.createUserPermissionChecker(request, topic); if (upChecker.isAdmin() || upChecker.isModerator() || (upChecker.isAuthor() && ann.getAuthor() != null && ann.getAuthor().equals(request.getRemoteUser()))) { // the person deleting the announcement must be the author, a moderator or an admin announcementService.deleteAnnouncement(ann); } else { throw new UnauthorizedException("You do not have permission to delete this announcement"); } response.setRenderParameter("topicId", topicId.toString()); response.setRenderParameter("action", "showTopic"); }
/** Does all the prep work before showing the form */ @RequestMapping(params = "action=addAnnouncement") public String showAddAnnouncementForm( @RequestParam(value = "editId", required = false) Long editId, @RequestParam(value = "topicId", required = false) Long topicId, RenderRequest request, Model model) throws PortletException { PortletPreferences prefs = request.getPreferences(); if (!model.containsAttribute("announcement")) { Announcement ann = new Announcement(); Topic topic = null; if (editId != null) { try { log.debug( "editId found. This is an edit request for announcement Id " + editId.toString()); ann = announcementService.getAnnouncement(editId); // return immediately when we have our announcement } catch (NumberFormatException e) { log.debug("No editId found. This is not an edit request"); } } if (ann != null && ann.getParent() == null) { try { topic = announcementService.getTopic(topicId); ann.setParent(topic); } catch (NumberFormatException e) { log.error("Unable to get topicId from request"); } } model.addAttribute("announcement", ann); } model.addAttribute("datePickerFormat", datePickerFormat); model.addAttribute( "abstractMaxLength", prefs.getValue(PREFERENCE_ABSTRACT_MAX_LENGTH, DEFAULT_ABSTRACT_MAX_LENGTH)); model.addAttribute( "tinyMceInitializationOptions", prefs.getValue( PREFERENCE_TINY_MCE_INITIALIZATION_OPTIONS, DEFAULT_TINY_MCE_INITIALIZATION_OPTIONS)); return "addAnnouncement"; }