示例#1
0
  /**
   * {@code posting}에 {@code original} 정보를 채우고 갱신한다.
   *
   * <p>when: 게시물이나 이슈를 수정할 떄 사용한다.
   *
   * @param original
   * @param posting
   * @param postingForm
   * @param redirectTo
   * @param updatePosting
   * @return
   */
  protected static Result editPosting(
      AbstractPosting original,
      AbstractPosting posting,
      Form<? extends AbstractPosting> postingForm,
      Call redirectTo,
      Callback updatePosting) {
    if (postingForm.hasErrors()) {
      return badRequest(postingForm.errors().toString());
    }

    if (!AccessControl.isAllowed(UserApp.currentUser(), original.asResource(), Operation.UPDATE)) {
      return forbidden(views.html.error.forbidden.render(original.project));
    }

    posting.id = original.id;
    posting.createdDate = original.createdDate;
    posting.authorId = original.authorId;
    posting.authorLoginId = original.authorLoginId;
    posting.authorName = original.authorName;
    posting.project = original.project;
    updatePosting.run();
    posting.update();

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

    return redirect(redirectTo);
  }
示例#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);
  }