mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Allow watchers to see private threads, add list of users able to see thread
This commit is contained in:
parent
b8e40b166d
commit
ee2311025c
@ -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()
|
||||
|
||||
|
@ -81,14 +81,30 @@
|
||||
|
||||
{% if thread.package %}
|
||||
<p>
|
||||
{{ _("Package") }}: <a href="{{ thread.package.getURL("packages.view") }}">{{ thread.package.title }}</a>
|
||||
{{ _("Package") }}: <a href="{{ thread.package.getURL('packages.view') }}">{{ thread.package.title }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if thread.private %}
|
||||
<i>
|
||||
{{ _("This thread is only visible to its creator, the package owner, and users of Approver rank or above.") }}
|
||||
</i>
|
||||
<aside class="row">
|
||||
<div class="col-md-9">
|
||||
<i>
|
||||
{{ _("This thread is only visible to its creator, the package owner, and users of Approver rank or above.") }}
|
||||
</i>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="d-flex flex-row justify-content-end flex-wrap align-items-center" style="gap: 0.5em;">
|
||||
{% for viewer in thread.get_visible_to() %}
|
||||
<a href="{{ url_for('users.profile', username=viewer.username) }}" title="{{ viewer.display_name }}">
|
||||
<img style="max-height: 2em;" src="{{ viewer.getProfilePicURL() }}" alt="{{ viewer.display_name }}" />
|
||||
</a>
|
||||
{% endfor %}
|
||||
<a href="{{ url_for('users.list_all') }}" title="{{ _('Plus approvers and editors') }}">
|
||||
+ <i class="fas fa-user-check"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
{% endif %}
|
||||
|
||||
{% from "macros/threads.html" import render_thread %}
|
||||
|
Loading…
Reference in New Issue
Block a user