Fix 2 filter_by bugs

Fixes #101
This commit is contained in:
rubenwardy 2018-07-13 21:28:08 +01:00
parent 1b42f3310a
commit 28ee65809e
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
4 changed files with 12 additions and 7 deletions

View File

@ -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.")

View File

@ -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 %}

View File

@ -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() != "":

View File

@ -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):