diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-07-13 21:28:08 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-07-13 21:28:11 +0100 |
commit | 28ee65809e3933ba08826c9ccddcc651f9dd23b1 (patch) | |
tree | 80bead9206975576e90559caafb1d8d9fc5af254 | |
parent | 1b42f3310a8d19145aa1c870794e394851921083 (diff) | |
download | cheatdb-28ee65809e3933ba08826c9ccddcc651f9dd23b1.tar.xz |
Fix 2 filter_by bugs
Fixes #101
-rw-r--r-- | app/models.py | 7 | ||||
-rw-r--r-- | app/templates/macros/threads.html | 2 | ||||
-rw-r--r-- | app/views/packages/__init__.py | 4 | ||||
-rw-r--r-- | 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 @@ <ul> {% for t in threads %} <li><a href="{{ url_for('thread_page', id=t.id) }}">{{ t.title }}</a> by {{ t.author.display_name }}</li> + {% else %} + <li><i>No threads found</i></li> {% endfor %} </ul> {% 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/<int:id>/", methods=["GET", "POST"]) def thread_page(id): |