add /notification_mutes

pull/200/head
Aevann 2023-09-07 12:15:22 +03:00
parent aec8d2bfb1
commit 9b7ab04ddd
3 changed files with 41 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import time import time
from sqlalchemy import Column, ForeignKey from sqlalchemy import Column, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql.sqltypes import * from sqlalchemy.sql.sqltypes import *
from files.classes import Base from files.classes import Base
@ -11,6 +12,9 @@ class UserMute(Base):
target_id = Column(Integer, ForeignKey("users.id"), primary_key=True) target_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
created_utc = Column(Integer) created_utc = Column(Integer)
user = relationship("User", primaryjoin="User.id==UserMute.user_id")
target = relationship("User", primaryjoin="User.id==UserMute.target_id")
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)

View File

@ -9,6 +9,7 @@ from files.classes.award import AWARDS
from files.classes.badges import Badge, BadgeDef from files.classes.badges import Badge, BadgeDef
from files.classes.mod_logs import ModAction from files.classes.mod_logs import ModAction
from files.classes.userblock import UserBlock from files.classes.userblock import UserBlock
from files.classes.usermute import UserMute
from files.helpers.actions import * from files.helpers.actions import *
from files.helpers.alerts import * from files.helpers.alerts import *
from files.helpers.config.const import * from files.helpers.config.const import *
@ -337,17 +338,17 @@ def badges(v):
badges, counts = badge_list(SITE, v.admin_level >= PERMS['VIEW_PATRONS']) badges, counts = badge_list(SITE, v.admin_level >= PERMS['VIEW_PATRONS'])
return render_template("badges.html", v=v, badges=badges, counts=counts) return render_template("badges.html", v=v, badges=badges, counts=counts)
@app.get("/blocks") @app.get("/notification_mutes")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required @auth_required
def blocks(v): def mutes(v):
blocks = g.db.query(UserBlock).options( mutes = g.db.query(UserMute).options(
joinedload(UserBlock.user), joinedload(UserMute.user),
joinedload(UserBlock.target), joinedload(UserMute.target),
).order_by(UserBlock.created_utc.desc()) ).order_by(UserMute.created_utc.desc())
return render_template("blocks.html", v=v, blocks=blocks) return render_template("notification_mutes.html", v=v, mutes=mutes)
@app.get("/formatting") @app.get("/formatting")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)

View File

@ -0,0 +1,29 @@
{% extends "default.html" %}
{% block pagetitle %}Notification Mutes{% endblock %}
{% block content %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><span>Notification Mutes</span></h5>
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>User</th>
<th>Target</th>
<th>Muted on</th>
</tr>
</thead>
{% for mute in mutes %}
<tr>
<td>
{% with user = mute.user %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>
{% with user = mute.target %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td data-time="{{mute.created_utc}}"></td>
</tr>
{% endfor %}
</table>
{% endblock %}