if (parentComment == null) return Either.left(new PostReplyError(DELETED_OR_PERMISSION_DENIED)); if (!permissionManager.hasCreatePermission(user, page, Comment.class)) return Either.left(new PostReplyError(UNAUTHORIZED)); return Either.left(new PostReplyError(UNKNOWN_ERROR, ex));
@Override public Either<PostReplyError, URI> postReply(final URI baseUri, final Iterable<String> itemPath, final String comment) { checkArgument(size(itemPath) == 2, "Item path must contain exactly 2 parts."); int reviewId = Integer.parseInt(get(itemPath, 0)); int commentId = Integer.parseInt(get(itemPath, 1)); FecruUser user = cenquaUserManager.getUser(salUserManager.getRemoteUsername()); Review review = reviewManager.getReviewById(reviewId); if (review == null) { return left(new PostReplyError(DELETED_OR_PERMISSION_DENIED)); } else if (!permissionAccessor.currentUserCanComment(review)) { return left(new PostReplyError(UNAUTHORIZED)); } Comment replyToComment = commentManager.getById(commentId); if (replyToComment == null) { return left(new PostReplyError(DELETED_OR_PERMISSION_DENIED)); } else if (!permissionAccessor.currentUserCanReplyToComment(replyToComment)) { return left(new PostReplyError(UNAUTHORIZED)); } Comment newComment = addReply(comment, replyToComment, review, user); return right(uriProvider.getCommentUri(baseUri, newComment)); }
public Either<PostReplyError, URI> postReply(URI baseUri, Iterable<String> itemPath, String comment) throws StreamsException { ApplicationUser user = authenticationContext.getLoggedInUser(); String issueKey = getOnlyElement(itemPath); Issue issue = issueManager.getIssueObject(issueKey); if (issue == null) { return Either.left(new PostReplyError(DELETED_OR_PERMISSION_DENIED)); } else if (!permissionManager.hasPermission(Permissions.COMMENT_ISSUE, issue, user)) { return Either.left(new PostReplyError(UNAUTHORIZED)); } ErrorCollection errorCollection = new SimpleErrorCollection(); Comment commentObject = commentService.create(user, issue, comment, true, errorCollection); if (errorCollection.hasAnyErrors()) { return Either.left(new PostReplyError(UNKNOWN_ERROR)); } return Either.right(URI.create( baseUri.toASCIIString() + "/browse/" + issueKey + "#action_" + commentObject.getId())); }