mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Merge pull request #1397 from LemmyNet/parent_comment_check
Add check for parent comment. Fixes #1390
This commit is contained in:
commit
6b36bf772e
1 changed files with 13 additions and 0 deletions
|
@ -64,6 +64,19 @@ impl Perform for CreateComment {
|
||||||
return Err(APIError::err("locked").into());
|
return Err(APIError::err("locked").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there's a parent_id, check to make sure that comment is in that post
|
||||||
|
if let Some(parent_id) = data.parent_id {
|
||||||
|
// Make sure the parent comment exists
|
||||||
|
let parent =
|
||||||
|
match blocking(context.pool(), move |conn| Comment::read(&conn, parent_id)).await? {
|
||||||
|
Ok(comment) => comment,
|
||||||
|
Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
|
||||||
|
};
|
||||||
|
if parent.post_id != post_id {
|
||||||
|
return Err(APIError::err("couldnt_create_comment").into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: content_slurs_removed,
|
content: content_slurs_removed,
|
||||||
parent_id: data.parent_id.to_owned(),
|
parent_id: data.parent_id.to_owned(),
|
||||||
|
|
Loading…
Reference in a new issue