fix comment

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-09 13:01:05 +03:00
parent cc18360279
commit e439c2e8fb
1 changed files with 53 additions and 54 deletions

View File

@ -1341,10 +1341,8 @@ def comment_delete(
interpretation_id: int,
sub_collection_id: int | None = None,
):
form = f.DeleteCommentForm()
if form.validate_on_submit():
book: m.Book = db.session.get(m.Book, book_id)
comment_id = form.comment_id.data
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
@ -1357,9 +1355,7 @@ def comment_delete(
return redirect(url_for("book.collection_view", book_id=book_id))
if sub_collection_id:
sub_collection: m.Collection = db.session.get(
m.Collection, sub_collection_id
)
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
if not sub_collection or sub_collection.is_deleted:
log(
log.WARNING,
@ -1397,12 +1393,15 @@ def comment_delete(
flash("Interpretation not found", "danger")
return redirect(redirect_url)
form = f.DeleteCommentForm()
comment_id = form.comment_id.data
comment: m.Comment = db.session.get(m.Comment, comment_id)
if not comment or comment.is_deleted:
log(log.WARNING, "Comment with id [%s] not found", comment_id)
flash("Comment not found", "danger")
return redirect(redirect_url)
if form.validate_on_submit():
comment.is_deleted = True
log(log.INFO, "Delete comment [%s]", comment)
comment.save()