From ee2311025cf2184738b68d0e53246dd128612e98 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 23 Apr 2022 20:42:58 +0100 Subject: [PATCH] Allow watchers to see private threads, add list of users able to see thread --- app/models/threads.py | 18 ++++++++++++++++-- app/templates/threads/view.html | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/models/threads.py b/app/models/threads.py index 6fdfa81b..58f5ade4 100644 --- a/app/models/threads.py +++ b/app/models/threads.py @@ -20,7 +20,7 @@ from typing import Tuple, List from flask import url_for from . import db -from .users import Permission, UserRank +from .users import Permission, UserRank, User from .packages import Package watchers = db.Table("watchers", @@ -88,7 +88,7 @@ class Thread(db.Model): if self.package: isMaintainer = isMaintainer or user in self.package.maintainers - canSee = not self.private or isMaintainer or user.rank.atLeast(UserRank.APPROVER) + canSee = not self.private or isMaintainer or user.rank.atLeast(UserRank.APPROVER) or user in self.watchers if perm == Permission.SEE_THREAD: return canSee @@ -107,6 +107,20 @@ class Thread(db.Model): else: raise Exception("Permission {} is not related to threads".format(perm.name)) + def get_visible_to(self) -> list[User]: + retval = { + self.author.username: self.author + } + + for user in self.watchers: + retval[user.username] = user + + if self.package: + for user in self.package.maintainers: + retval[user.username] = user + + return list(retval.values()) + def get_latest_reply(self): return ThreadReply.query.filter_by(thread_id=self.id).order_by(db.desc(ThreadReply.id)).first() diff --git a/app/templates/threads/view.html b/app/templates/threads/view.html index 73635916..692c2c8a 100644 --- a/app/templates/threads/view.html +++ b/app/templates/threads/view.html @@ -81,14 +81,30 @@ {% if thread.package %}

- {{ _("Package") }}: {{ thread.package.title }} + {{ _("Package") }}: {{ thread.package.title }}

{% endif %} {% if thread.private %} - - {{ _("This thread is only visible to its creator, the package owner, and users of Approver rank or above.") }} - + {% endif %} {% from "macros/threads.html" import render_thread %}