Ejemplo n.º 1
0
  /**
   * Create a comment from the given email.
   *
   * @param message
   * @param target
   * @throws MessagingException
   * @throws MailHandlerException
   * @throws IOException
   * @throws NoSuchAlgorithmException
   */
  @Transactional
  public static Comment saveComment(IMAPMessage message, Resource target)
      throws MessagingException, MailHandlerException, IOException, NoSuchAlgorithmException {
    User author = IMAPMessageUtil.extractSender(message);

    if (!AccessControl.isProjectResourceCreatable(author, target.getProject(), target.getType())) {
      throw new PermissionDenied(
          cannotCreateMessage(author, target.getProject(), target.getType()));
    }

    Content parsedMessage = extractContent(message);

    Comment comment = makeNewComment(target, author, parsedMessage.body);

    comment.save();

    Map<String, Attachment> relatedAttachments =
        saveAttachments(parsedMessage.attachments, comment.asResource());

    if (new ContentType(parsedMessage.type).match(MimeType.HTML)) {
      // replace cid with attachments
      comment.contents = replaceCidWithAttachments(comment.contents, relatedAttachments);
      comment.update();
    }

    new OriginalEmail(message.getMessageID(), comment.asResource()).save();

    // Add the event
    addEvent(NotificationEvent.forNewComment(comment, author), message.getAllRecipients(), author);

    return comment;
  }
Ejemplo n.º 2
0
  /**
   * 새 댓글 저장 핸들러
   *
   * <p>{@code commentForm}에서 입력값을 꺼내 현재 사용자를 작성자로 설정하고 댓글을 저장한다. 현재 사용자 임시 저장소에 있는 첨부파일을 댓글의 첨부파일로
   * 옮긴다.
   *
   * @param comment
   * @param commentForm
   * @param redirectTo
   * @param containerUpdater
   * @return
   * @throws IOException
   */
  public static Result newComment(
      Comment comment,
      Form<? extends Comment> commentForm,
      Call redirectTo,
      Callback containerUpdater)
      throws IOException {
    if (commentForm.hasErrors()) {
      flash(Constants.WARNING, "board.comment.empty");
      return redirect(redirectTo);
    }

    comment.setAuthor(UserApp.currentUser());
    containerUpdater.run(); // this updates comment.issue or comment.posting;
    comment.save();

    // Attach all of the files in the current user's temporary storage.
    Attachment.moveAll(UserApp.currentUser().asResource(), comment.asResource());

    return redirect(redirectTo);
  }