/**
   * Контроллер блокирования и полного удаления комментариев и топиков пользователя
   *
   * @param request http запрос
   * @param user блокируемый пользователь
   * @return возвращаемся в профиль
   * @throws Exception обычно если текущий пользователь не модератор или пользователя нельзя
   *     блокировать
   */
  @RequestMapping(
      value = "/usermod.jsp",
      method = RequestMethod.POST,
      params = "action=block-n-delete-comments")
  public ModelAndView blockAndMassiveDeleteCommentUser(
      HttpServletRequest request,
      @RequestParam("id") User user,
      @RequestParam(value = "reason", required = false) String reason)
      throws Exception {
    User moderator = getModerator(request);
    if (!user.isBlockable() && !moderator.isAdministrator()) {
      throw new AccessViolationException(
          "Пользователя " + user.getNick() + " нельзя заблокировать");
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("message", "Удалено");
    DeleteCommentResult deleteCommentResult =
        commentService.deleteAllCommentsAndBlock(user, moderator, reason);

    logger.info("User " + user.getNick() + " blocked by " + moderator.getNick());

    params.put("bigMessage", deleteCommentResult.getDeletedCommentIds()); // TODO

    for (int topicId : deleteCommentResult.getDeletedTopicIds()) {
      searchQueueSender.updateMessage(topicId, true);
    }
    searchQueueSender.updateComment(deleteCommentResult.getDeletedCommentIds());

    return new ModelAndView("action-done", params);
  }
Ejemplo n.º 2
0
  @RequestMapping(
      value = "/{section}/{group}/{id}/comments",
      produces = "application/json; charset=UTF-8",
      method = RequestMethod.GET)
  @ResponseBody
  public Map<String, Object> getComments(
      @PathVariable("section") String sectionName,
      @PathVariable("group") String groupName,
      @PathVariable("id") int msgid,
      @RequestParam(value = "page", defaultValue = "0") int page,
      HttpServletRequest request)
      throws Exception {
    Topic topic = topicDao.getById(msgid);
    Group group = groupDao.getGroup(topic.getGroupId());
    Section section = sectionService.getSection(group.getSectionId());

    if (!section.getUrlName().equals(sectionName)
        || !group.getUrlName().equals(groupName)
        || page < 0) {
      throw new MessageNotFoundException(msgid);
    }

    permissionService.checkView(topic, AuthUtil.getCurrentUser());

    CommentList comments = commentService.getCommentList(topic, false);

    CommentFilter cv = new CommentFilter(comments);

    int messagesPerPage = AuthUtil.getProfile().getMessages();

    List<Comment> commentsFiltered =
        cv.getCommentsForPage(false, page, messagesPerPage, ImmutableSet.<Integer>of());

    List<PreparedComment> preparedComments =
        prepareService.prepareCommentList(
            comments, commentsFiltered, request.isSecure(), Template.getTemplate(request), topic);

    return ImmutableMap.of(
        "comments",
        preparedComments,
        "topic",
        new ApiCommentTopicInfo(
            topic.getId(),
            topic.getLink(),
            permissionService.isCommentsAllowed(topic, AuthUtil.getCurrentUser())));
  }