aboutsummaryrefslogtreecommitdiff
path: root/app/blueprints/threads/__init__.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-07-11 02:32:17 +0100
committerrubenwardy <rw@rubenwardy.com>2020-07-11 02:32:17 +0100
commita4dd4f04293b6ad6dab5d3dc0a4c52a3290b4394 (patch)
tree8e56f86e0318bd41266ad4cf9178269fe6da4dbb /app/blueprints/threads/__init__.py
parentbf927c50f00bd15c7bc1765b7d5fb0c6a6abeb86 (diff)
downloadcheatdb-a4dd4f04293b6ad6dab5d3dc0a4c52a3290b4394.tar.xz
Add audit log
Diffstat (limited to 'app/blueprints/threads/__init__.py')
-rw-r--r--app/blueprints/threads/__init__.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py
index e54c7c8..e3043c0 100644
--- a/app/blueprints/threads/__init__.py
+++ b/app/blueprints/threads/__init__.py
@@ -21,7 +21,7 @@ bp = Blueprint("threads", __name__)
from flask_user import *
from app.models import *
-from app.utils import addNotification, clearNotifications, isYes
+from app.utils import addNotification, clearNotifications, isYes, addAuditLog
import datetime
@@ -91,13 +91,19 @@ def set_lock(id):
if thread.locked is None:
abort(400)
- db.session.commit()
-
+ msg = None
if thread.locked:
+ msg = "Locked thread '{}'".format(thread.title)
flash("Locked thread", "success")
else:
+ msg = "Unlocked thread '{}'".format(thread.title)
flash("Unlocked thread", "success")
+ addNotification(thread.watchers, current_user, msg, thread.getViewURL(), thread.package)
+ addAuditLog(AuditSeverity.MODERATION, current_user, msg, thread.getViewURL(), thread.package)
+
+ db.session.commit()
+
return redirect(thread.getViewURL())
@@ -129,10 +135,10 @@ def view(id):
thread.watchers.append(current_user)
msg = "New comment on '{}'".format(thread.title)
- addNotification(thread.watchers, current_user, msg, url_for("threads.view", id=thread.id), thread.package)
+ addNotification(thread.watchers, current_user, msg, thread.getViewURL(), thread.package)
db.session.commit()
- return redirect(url_for("threads.view", id=id))
+ return redirect(thread.getViewURL())
else:
flash("Comment needs to be between 3 and 500 characters.")
@@ -175,7 +181,7 @@ def new():
# Only allow creating one thread when not approved
elif is_review_thread and package.review_thread is not None:
flash("A review thread already exists!", "danger")
- return redirect(url_for("threads.view", id=package.review_thread.id))
+ return redirect(package.review_thread.getViewURL())
elif not current_user.canOpenThreadRL():
flash("Please wait before opening another thread", "danger")
@@ -218,14 +224,14 @@ def new():
notif_msg = "New thread '{}'".format(thread.title)
if package is not None:
- addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id), package)
+ addNotification(package.maintainers, current_user, notif_msg, thread.getViewURL(), package)
editors = User.query.filter(User.rank >= UserRank.EDITOR).all()
- addNotification(editors, current_user, notif_msg, url_for("threads.view", id=thread.id), package)
+ addNotification(editors, current_user, notif_msg, thread.getViewURL(), package)
db.session.commit()
- return redirect(url_for("threads.view", id=thread.id))
+ return redirect(thread.getViewURL())
return render_template("threads/new.html", form=form, allow_private_change=allow_change, package=package)