From 28ee65809e3933ba08826c9ccddcc651f9dd23b1 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 13 Jul 2018 21:28:08 +0100 Subject: [PATCH] Fix 2 filter_by bugs Fixes #101 --- app/models.py | 7 ++++--- app/templates/macros/threads.html | 2 ++ app/views/packages/__init__.py | 4 ++-- app/views/threads.py | 6 ++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/models.py b/app/models.py index c703783..c402d09 100644 --- a/app/models.py +++ b/app/models.py @@ -85,9 +85,10 @@ class Permission(enum.Enum): return False if self == Permission.APPROVE_NEW or \ - self == Permission.APPROVE_CHANGES or \ - self == Permission.APPROVE_RELEASE or \ - self == Permission.APPROVE_SCREENSHOT: + self == Permission.APPROVE_CHANGES or \ + self == Permission.APPROVE_RELEASE or \ + self == Permission.APPROVE_SCREENSHOT or \ + self == Permission.SEE_THREAD: return user.rank.atLeast(UserRank.EDITOR) else: raise Exception("Non-global permission checked globally. Use Package.checkPerm or User.checkPerm instead.") diff --git a/app/templates/macros/threads.html b/app/templates/macros/threads.html index b74edda..6552f2a 100644 --- a/app/templates/macros/threads.html +++ b/app/templates/macros/threads.html @@ -29,6 +29,8 @@ {% endmacro %} diff --git a/app/views/packages/__init__.py b/app/views/packages/__init__.py index 6184813..a4f7a04 100644 --- a/app/views/packages/__init__.py +++ b/app/views/packages/__init__.py @@ -37,11 +37,11 @@ def build_packages_query(): type = PackageType[type_name.upper()] title = "Packages" - query = Package.query.filter_by(soft_deleted=False) + query = Package.query.filter_by(soft_deleted=False, approved=True) if type is not None: title = type.value + "s" - query = query.filter_by(type=type, approved=True) + query = query.filter_by(type=type) search = request.args.get("q") if search is not None and search.strip() != "": diff --git a/app/views/threads.py b/app/views/threads.py index a842d58..2aa815e 100644 --- a/app/views/threads.py +++ b/app/views/threads.py @@ -27,8 +27,10 @@ from wtforms.validators import * @app.route("/threads/") def threads_page(): - threads = Thread.query.filter_by(private=False).all() - return render_template("threads/list.html", threads=threads) + query = Thread.query + if not Permission.SEE_THREAD.check(current_user): + query = query.filter_by(private=False) + return render_template("threads/list.html", threads=query.all()) @app.route("/threads//", methods=["GET", "POST"]) def thread_page(id):