add hole actions notifs for hole mods

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-11-08 15:49:43 +02:00
parent 4465061162
commit 8b1f76f727
4 changed files with 35 additions and 12 deletions

View File

@ -16,6 +16,7 @@ from .userblock import *
from .badges import *
from .clients import *
from .mod_logs import *
from .sub_logs import *
from .mod import *
from .exiles import *
from .sub_block import *
@ -644,11 +645,23 @@ class User(Base):
@property
@lazy
def modaction_notifications_count(self):
if not self.admin_level or self.id == AEVANN_ID: return 0
return g.db.query(ModAction).filter(
ModAction.created_utc > self.last_viewed_log_notifs,
ModAction.user_id != self.id,
).count()
if self.id == AEVANN_ID: return 0
if self.admin_level:
return g.db.query(ModAction).filter(
ModAction.created_utc > self.last_viewed_log_notifs,
ModAction.user_id != self.id,
).count()
if self.moderated_subs:
return g.db.query(SubAction).filter(
SubAction.created_utc > self.last_viewed_log_notifs,
SubAction.user_id != self.id,
SubAction.sub.in_(self.moderated_subs),
).count()
return 0
@property
@lazy
@ -738,8 +751,7 @@ class User(Base):
@property
@lazy
def moderated_subs(self):
modded_subs = g.db.query(Mod.sub).filter_by(user_id=self.id).all()
return modded_subs
return [x[0] for x in g.db.query(Mod.sub).filter_by(user_id=self.id).all()]
@lazy
def has_follower(self, user):

View File

@ -172,13 +172,24 @@ def notifications_posts(v):
@app.get("/notifications/modactions")
@admin_level_required(PERMS['NOTIFICATIONS_MODERATOR_ACTIONS'])
@auth_required
def notifications_modactions(v):
try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1
listing = g.db.query(ModAction).filter(ModAction.user_id != v.id).order_by(ModAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all()
if v.admin_level >= PERMS['NOTIFICATIONS_MODERATOR_ACTIONS']:
cls = ModAction
elif v.moderated_subs:
cls = SubAction
else:
abort(403)
listing = g.db.query(cls).filter(cls.user_id != v.id)
if cls == SubAction:
listing = listing.filter(cls.sub.in_(v.moderated_subs))
listing = listing.order_by(cls.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE+1).all()
next_exists = len(listing) > PAGE_SIZE
listing = listing[:PAGE_SIZE]

View File

@ -28,7 +28,7 @@
Posts {% if v.post_notifications_count %}<span class="font-weight-bold" style="color:#0000ff">({{v.post_notifications_count}})</span>{% endif %}
</a>
</li>
{% if v.admin_level >= PERMS['NOTIFICATIONS_MODERATOR_ACTIONS'] %}
{% if v.admin_level >= PERMS['NOTIFICATIONS_MODERATOR_ACTIONS'] or v.moderated_subs %}
<li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/modactions' %} active{% endif %}" href="/notifications/modactions">
Modactions {% if v.modaction_notifications_count %}<span class="font-weight-bold" style="color:#1ad80d">({{v.modaction_notifications_count}})</span>{% endif %}

View File

@ -153,7 +153,7 @@
<p class="text-uppercase my-0 pb-1" style="font-weight: bold; font-size: 12px;">Moderator of</p>
{% for a in u.moderated_subs %}
<span class="d-inline-block mx-1">
<a href="/h/{{a['sub']}}">/h/{{a['sub']}}</a>
<a href="/h/{{a}}">/h/{{a}}</a>
</span>
{% endfor %}
</div>
@ -384,7 +384,7 @@
<p class="text-uppercase my-0 pb-1" style="font-weight: bold; font-size: 12px;">Moderator of</p>
{% for a in u.moderated_subs %}
<span class="d-inline-block mx-1">
<a href="/h/{{a['sub']}}">/h/{{a['sub']}}</a>
<a href="/h/{{a}}">/h/{{a}}</a>
</span>
{% endfor %}
</div>