From df8d05f09d3dd7dacdb401661ea60706d2f21779 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 28 Jul 2018 15:08:08 +0100 Subject: [PATCH] Add thread list to package view --- app/templates/packages/view.html | 19 ++++++++++++++----- app/views/packages/__init__.py | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index 181ae998..4bcc1cd7 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -57,11 +57,13 @@ {% if package.author == current_user or package.checkPerm(current_user, "APPROVE_NEW") %} {% if review_thread %} -

🔒 {{ review_thread.title }}

-

- This thread is only visible to the package owner and users of - Editor rank or above. -

+

{% if review_thread.private %}🔒{% endif %} {{ review_thread.title }}

+ {% if review_thread.private %} +

+ This thread is only visible to the package owner and users of + Editor rank or above. +

+ {% endif %} {% from "macros/threads.html" import render_thread %} {{ render_thread(review_thread, current_user) }} @@ -313,4 +315,11 @@ {% endfor %} {% endif %} + + {% if threads %} +

Threads

+ + {% from "macros/threads.html" import render_threadlist %} + {{ render_threadlist(threads) }} + {% endif %} {% endblock %} diff --git a/app/views/packages/__init__.py b/app/views/packages/__init__.py index a4f7a045..4d9f791a 100644 --- a/app/views/packages/__init__.py +++ b/app/views/packages/__init__.py @@ -29,6 +29,7 @@ from flask_wtf import FlaskForm from wtforms import * from wtforms.validators import * from wtforms.ext.sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField +from sqlalchemy import or_ def build_packages_query(): type_name = request.args.get("type") @@ -112,7 +113,7 @@ def package_page(package): releases = getReleases(package) requests = [r for r in package.requests if r.status == 0] - review_thread = Thread.query.filter_by(package_id=package.id, private=True).first() + review_thread = package.review_thread if review_thread is not None and not review_thread.checkPerm(current_user, Permission.SEE_THREAD): review_thread = None @@ -137,10 +138,19 @@ def package_page(package): topic_error = "
".join(errors) + + threads = Thread.query.filter_by(package_id=package.id) + if not current_user.is_authenticated: + threads = threads.filter_by(private=False) + elif not current_user.rank.atLeast(UserRank.EDITOR) and not current_user == package.author: + threads = threads.filter(or_(Thread.private == False, Thread.author == current_user)) + + return render_template("packages/view.html", \ package=package, releases=releases, requests=requests, \ alternatives=alternatives, similar_topics=similar_topics, \ - review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl) + review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl, \ + threads=threads.all()) @app.route("/packages///download/")