aboutsummaryrefslogtreecommitdiff
path: root/app/blueprints/threads/__init__.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-07-11 03:52:56 +0100
committerrubenwardy <rw@rubenwardy.com>2020-07-11 03:53:03 +0100
commitdfbcbbbb476cbbd467cabb1e36ea56ee84c99b43 (patch)
tree39255ac145664f3679788e774ae6cc750f41daa0 /app/blueprints/threads/__init__.py
parent08f6bd8befa266d40f56b143193c8c1ca5fb2716 (diff)
downloadcheatdb-dfbcbbbb476cbbd467cabb1e36ea56ee84c99b43.tar.xz
Add ability to edit comments
Diffstat (limited to 'app/blueprints/threads/__init__.py')
-rw-r--r--app/blueprints/threads/__init__.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py
index 113cdfa..21666af 100644
--- a/app/blueprints/threads/__init__.py
+++ b/app/blueprints/threads/__init__.py
@@ -141,6 +141,50 @@ def delete_reply(id):
return redirect(thread.getViewURL())
+
+
+class CommentForm(FlaskForm):
+ comment = TextAreaField("Comment", [InputRequired(), Length(10, 500)])
+ submit = SubmitField("Comment")
+
+
+
+@bp.route("/threads/<int:id>/edit/", methods=["GET", "POST"])
+@login_required
+def edit_reply(id):
+ thread = Thread.query.get(id)
+ if thread is None:
+ abort(404)
+
+ reply_id = request.args.get("reply")
+ if reply_id is None:
+ abort(404)
+
+ reply = ThreadReply.query.get(reply_id)
+ if reply is None or reply.thread != thread:
+ abort(404)
+
+ if not reply.checkPerm(current_user, Permission.EDIT_REPLY):
+ abort(403)
+
+ form = CommentForm(formdata=request.form, obj=reply)
+ if request.method == "POST" and form.validate():
+ comment = form.comment.data
+
+ msg = "Edited reply by {}".format(reply.author.display_name)
+ severity = AuditSeverity.NORMAL if current_user == reply.author else AuditSeverity.MODERATION
+ addNotification(reply.author, current_user, msg, thread.getViewURL(), thread.package)
+ addAuditLog(severity, current_user, msg, thread.getViewURL(), thread.package, reply.comment)
+
+ reply.comment = comment
+
+ db.session.commit()
+
+ return redirect(thread.getViewURL())
+
+ return render_template("threads/edit_reply.html", thread=thread, reply=reply, form=form)
+
+
@bp.route("/threads/<int:id>/", methods=["GET", "POST"])
def view(id):
thread = Thread.query.get(id)