Use middleware to clear notifications

Fixes #70
This commit is contained in:
rubenwardy 2020-07-10 22:23:52 +01:00
parent 1d8abd8f4b
commit b9386d5a47
6 changed files with 7 additions and 9 deletions

@ -92,3 +92,10 @@ def check_for_ban():
elif current_user.rank == models.UserRank.NOT_JOINED: elif current_user.rank == models.UserRank.NOT_JOINED:
current_user.rank = models.UserRank.MEMBER current_user.rank = models.UserRank.MEMBER
models.db.session.commit() models.db.session.commit()
from .utils import clearNotifications
@app.before_request
def check_for_notifications():
if current_user.is_authenticated:
clearNotifications(request.path)

@ -119,7 +119,6 @@ def view_editrequest_page(package, id):
if erequest is None or erequest.package != package: if erequest is None or erequest.package != package:
abort(404) abort(404)
clearNotifications(erequest.getURL())
return render_template("packages/editrequest_view.html", package=package, request=erequest) return render_template("packages/editrequest_view.html", package=package, request=erequest)

@ -101,8 +101,6 @@ def getReleases(package):
@bp.route("/packages/<author>/<name>/") @bp.route("/packages/<author>/<name>/")
@is_package_page @is_package_page
def view(package): def view(package):
clearNotifications(package.getDetailsURL())
alternatives = None alternatives = None
if package.type == PackageType.MOD: if package.type == PackageType.MOD:
alternatives = Package.query \ alternatives = Package.query \

@ -157,8 +157,6 @@ def edit_release(package, id):
if release is None or release.package != package: if release is None or release.package != package:
abort(404) abort(404)
clearNotifications(release.getEditURL())
canEdit = package.checkPerm(current_user, Permission.MAKE_RELEASE) canEdit = package.checkPerm(current_user, Permission.MAKE_RELEASE)
canApprove = package.checkPerm(current_user, Permission.APPROVE_RELEASE) canApprove = package.checkPerm(current_user, Permission.APPROVE_RELEASE)
if not (canEdit or canApprove): if not (canEdit or canApprove):

@ -81,8 +81,6 @@ def edit_screenshot(package, id):
if not (canEdit or canApprove): if not (canEdit or canApprove):
return redirect(package.getDetailsURL()) return redirect(package.getDetailsURL())
clearNotifications(screenshot.getEditURL())
# Initial form class from post data and default data # Initial form class from post data and default data
form = EditScreenshotForm(formdata=request.form, obj=screenshot) form = EditScreenshotForm(formdata=request.form, obj=screenshot)

@ -82,8 +82,6 @@ def unsubscribe(id):
@bp.route("/threads/<int:id>/", methods=["GET", "POST"]) @bp.route("/threads/<int:id>/", methods=["GET", "POST"])
def view(id): def view(id):
clearNotifications(url_for("threads.view", id=id))
thread = Thread.query.get(id) thread = Thread.query.get(id)
if thread is None or not thread.checkPerm(current_user, Permission.SEE_THREAD): if thread is None or not thread.checkPerm(current_user, Permission.SEE_THREAD):
abort(404) abort(404)