mod log rework

master
Aevann 2024-10-29 20:33:38 +03:00
parent 0aca7fd078
commit 84341ec4f7
9 changed files with 106 additions and 82 deletions

View File

@ -50,7 +50,7 @@ class HoleAction(Base):
@property
@lazy
def string(self):
output = HOLEACTION_TYPES[self.kind]["str"].format(self=self)
output = HOLEACTION_KINDS[self.kind]["str"].format(self=self)
if self._note: output += f" <i>({self._note})</i>"
return output
@ -67,16 +67,16 @@ class HoleAction(Base):
@property
@lazy
def icon(self):
return HOLEACTION_TYPES[self.kind]['icon']
return HOLEACTION_KINDS[self.kind]['icon']
@property
@lazy
def color(self):
return HOLEACTION_TYPES[self.kind]['color']
return HOLEACTION_KINDS[self.kind]['color']
@property
@lazy
def permalink(self):
return f"{SITE_FULL}/h/{self.hole}/log/{self.id}"
from files.helpers.config.holeaction_types import HOLEACTION_TYPES
from files.helpers.config.holeaction_kinds import HOLEACTION_KINDS

View File

@ -100,7 +100,7 @@ class ModAction(Base):
@property
@lazy
def string(self):
output = MODACTION_TYPES[self.kind]["str"].format(self=self)
output = MODACTION_KINDS[self.kind]["str"].format(self=self)
if self.note: output += f" <i>({self.note})</i>"
return output
@ -117,16 +117,16 @@ class ModAction(Base):
@property
@lazy
def icon(self):
return MODACTION_TYPES[self.kind]['icon']
return MODACTION_KINDS[self.kind]['icon']
@property
@lazy
def color(self):
return MODACTION_TYPES[self.kind]['color']
return MODACTION_KINDS[self.kind]['color']
@property
@lazy
def permalink(self):
return f"{SITE_FULL}/log/{self.id}"
from files.helpers.config.modaction_types import MODACTION_TYPES, MODACTION_TYPES_FILTERED
from files.helpers.config.modaction_kinds import MODACTION_KINDS, MODACTION_KINDS_FILTERED

View File

@ -19,7 +19,7 @@ from files.classes.chats import *
from files.classes.currency_logs import CurrencyLog
from files.classes.mod_logs import ModAction
from files.helpers.config.const import *
from files.helpers.config.modaction_types import *
from files.helpers.config.modaction_kinds import *
from files.helpers.config.awards import *
from files.helpers.media import *
from files.helpers.security import *
@ -919,7 +919,7 @@ class User(Base):
ModAction.user_id != self.id,
)
if self.id == AEVANN_ID:
q = q.filter(ModAction.kind.notin_(AEVANN_EXCLUDED_MODACTION_TYPES))
q = q.filter(ModAction.kind.notin_(AEVANN_EXCLUDED_MODACTION_KINDS))
if self.admin_level < PERMS['PROGSTACK']:
q = q.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__TYPES))

View File

@ -1,4 +1,4 @@
HOLEACTION_TYPES = {
HOLEACTION_KINDS = {
'exile_user': {
"str": 'exiled user {self.target_link}',
"icon": 'fa-user-slash',
@ -156,4 +156,4 @@ HOLEACTION_TYPES = {
},
}
HOLEACTION_TYPES = dict(sorted(HOLEACTION_TYPES.items()))
HOLEACTION_KINDS = dict(sorted(HOLEACTION_KINDS.items()))

View File

@ -1,6 +1,6 @@
from copy import deepcopy
MODACTION_TYPES = {
MODACTION_KINDS = {
'chud': {
"str": 'chudded {self.target_link}',
"icon": 'fa-snooze',
@ -463,9 +463,9 @@ MODACTION_TYPES = {
},
}
MODACTION_TYPES = dict(sorted(MODACTION_TYPES.items()))
MODACTION_KINDS = dict(sorted(MODACTION_KINDS.items()))
MODACTION_PRIVILEGED_TYPES = {
MODACTION_PRIVILEGED_KINDS = {
'shadowban', 'unshadowban',
'mute_user', 'unmute_user',
'link_accounts', 'delink_accounts',
@ -481,11 +481,11 @@ MODACTION_PRIVILEGED_TYPES = {
}
MODACTION_PRIVILEGED__TYPES = {'progstack_post', 'progstack_comment',
'unprogstack_post', 'unprogstack_comment'}
MODACTION_TYPES_FILTERED = deepcopy({t:v for t,v in MODACTION_TYPES.items()
if not t in MODACTION_PRIVILEGED_TYPES})
MODACTION_TYPES__FILTERED = deepcopy({t:v for t,v in MODACTION_TYPES.items()
MODACTION_KINDS_FILTERED = deepcopy({t:v for t,v in MODACTION_KINDS.items()
if not t in MODACTION_PRIVILEGED_KINDS})
MODACTION_KINDS__FILTERED = deepcopy({t:v for t,v in MODACTION_KINDS.items()
if not t in MODACTION_PRIVILEGED__TYPES})
AEVANN_EXCLUDED_MODACTION_TYPES = {'pin_post', 'unpin_post',
AEVANN_EXCLUDED_MODACTION_KINDS = {'pin_post', 'unpin_post',
'pin_comment', 'unpin_comment',
'approve_emoji', 'reject_emoji',
'distribute', 'mark_effortpost'}

View File

@ -891,9 +891,9 @@ def hole_log(v, hole):
kind = request.values.get("kind")
types = HOLEACTION_TYPES
used_kinds = HOLEACTION_KINDS
if kind and kind not in types:
if kind and kind not in used_kinds:
kind = None
actions = []
total=0
@ -904,10 +904,10 @@ def hole_log(v, hole):
actions = actions.filter_by(user_id=mod_id)
kinds = {x.kind for x in actions}
if kind: kinds.add(kind)
types2 = {}
for k,val in types.items():
if k in kinds: types2[k] = val
types = types2
kinds2 = {}
for k,val in used_kinds.items():
if k in kinds: kinds2[k] = val
kinds = kinds2
if kind: actions = actions.filter_by(kind=kind)
total = actions.count()
actions = actions.order_by(HoleAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
@ -915,7 +915,7 @@ def hole_log(v, hole):
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)]
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)]
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, hole=hole, single_user_url='mod')
return render_template("log.html", v=v, admins=mods, kinds=kinds, admin=mod, kind=kind, actions=actions, total=total, page=page, hole=hole, single_user_url='mod')
@app.get("/h/<hole>/log/<int:id>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@ -933,7 +933,7 @@ def hole_log_item(id, v, hole):
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)]
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)]
types = HOLEACTION_TYPES
types = HOLEACTION_KINDS
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, hole=hole, single_user_url='mod')

View File

@ -7,7 +7,7 @@ from files.classes.mod_logs import ModAction
from files.classes.hole_logs import HoleAction
from files.classes.chats import *
from files.helpers.config.const import *
from files.helpers.config.modaction_types import *
from files.helpers.config.modaction_kinds import *
from files.helpers.get import *
from files.helpers.can_see import *
from files.routes.wrappers import *
@ -266,7 +266,7 @@ def notifications_modactions(v):
listing = g.db.query(cls).filter(cls.user_id != v.id)
if v.id == AEVANN_ID:
listing = listing.filter(cls.kind.notin_(AEVANN_EXCLUDED_MODACTION_TYPES))
listing = listing.filter(cls.kind.notin_(AEVANN_EXCLUDED_MODACTION_KINDS))
if v.admin_level < PERMS['PROGSTACK']:
listing = listing.filter(cls.kind.notin_(MODACTION_PRIVILEGED__TYPES))

View File

@ -13,7 +13,7 @@ from files.classes.usermute import UserMute
from files.helpers.actions import *
from files.helpers.alerts import *
from files.helpers.config.const import *
from files.helpers.config.modaction_types import *
from files.helpers.config.modaction_kinds import *
from files.routes.wrappers import *
from files.routes.notifications import modmail_listing
from files.__main__ import app, cache, limiter
@ -249,29 +249,29 @@ def log(v):
if v.admin_level >= PERMS['USER_SHADOWBAN']:
if v.admin_level >= PERMS['PROGSTACK']:
types = MODACTION_TYPES
used_kinds = MODACTION_KINDS
else:
types = MODACTION_TYPES__FILTERED
else: types = MODACTION_TYPES_FILTERED
used_kinds = MODACTION_KINDS__FILTERED
else: used_kinds = MODACTION_KINDS_FILTERED
if kind and kind not in types:
if kind and kind not in used_kinds:
kind = None
actions = []
total = 0
else:
actions = g.db.query(ModAction)
if v.admin_level < PERMS['USER_SHADOWBAN']:
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED_TYPES))
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED_KINDS))
if v.admin_level < PERMS['PROGSTACK']:
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__TYPES))
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__KINDS))
if admin_id:
actions = actions.filter_by(user_id=admin_id)
kinds = {x.kind for x in actions}
kinds.add(kind)
types2 = {}
for k,val in types.items():
if k in kinds: types2[k] = val
types = types2
kinds2 = {}
for k,val in used_kinds.items():
if k in kinds: kinds2[k] = val
kinds = kinds2
if target_id:
target_post_ids = [x[0] for x in g.db.query(Post.id).filter_by(author_id=target_id)]
target_comment_ids = [x[0] for x in g.db.query(Comment.id).filter_by(author_id=target_id)]
@ -282,17 +282,17 @@ def log(v):
))
kinds = {x.kind for x in actions}
kinds.add(kind)
types2 = {}
for k,val in types.items():
if k in kinds: types2[k] = val
types = types2
kinds2 = {}
for k,val in used_kinds.items():
if k in kinds: kinds2[k] = val
kinds = kinds2
if kind: actions = actions.filter_by(kind=kind)
total = actions.count()
actions = actions.order_by(ModAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).order_by(User.username)]
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, total=total, page=page, single_user_url='admin')
return render_template("log.html", v=v, admins=admins, kinds=kinds, admin=admin, target_id=target_id, kind=kind, actions=actions, total=total, page=page, single_user_url='admin')
@app.get("/log/<int:id>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@ -303,17 +303,17 @@ def log_item(id, v):
if not action: stop(404)
if action.kind in MODACTION_PRIVILEGED_TYPES and v.admin_level < PERMS['USER_SHADOWBAN']:
if action.kind in MODACTION_PRIVILEGED_KINDS and v.admin_level < PERMS['USER_SHADOWBAN']:
stop(404)
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE'])]
if v.admin_level >= PERMS['USER_SHADOWBAN']:
if v.admin_level >= PERMS['PROGSTACK']:
types = MODACTION_TYPES
types = MODACTION_KINDS
else:
types = MODACTION_TYPES__FILTERED
else: types = MODACTION_TYPES_FILTERED
types = MODACTION_KINDS__FILTERED
else: types = MODACTION_KINDS_FILTERED
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=admins, types=types, single_user_url='admin')

View File

@ -1,6 +1,33 @@
{% extends "meta_navbar.html" %}
{% block pagetitle %}Moderation Log{% endblock %}
{% block content %}
{%- macro get_href(new_admin=None, new_kind=None) -%}
{%- if hole -%}
{%- set href = "/h/" ~ hole ~ "/log?" -%}
{%- else -%}
{%- set href = "/log?" -%}
{%- endif -%}
{%- if new_admin -%}
{%- set admin = new_admin -%}
{%- endif -%}
{%- if new_kind -%}
{%- set kind = new_kind -%}
{%- endif -%}
{%- if target_id -%}
{%- set href = href ~ "target_id=" ~ target_id ~ "&" -%}
{%- endif -%}
{%- if admin and admin != 'All' -%}
{%- set href = href ~ "admin=" ~ admin ~ "&" -%}
{%- endif -%}
{%- if kind and kind != 'All' -%}
{%- set href = href ~ "kind=" ~ kind ~ "&" -%}
{%- endif -%}
{{- href[:-1] -}}
{%- endmacro -%}
<div class="row justify-content-around">
<div class="col h-100">
<div class="justify-content-between">
@ -12,40 +39,37 @@
<div class="row" style="overflow: visible;padding-top:5px">
<div class="col">
<div class="d-flex justify-content-between align-items-center">
{% block navbar %}
<div class="d-flex align-items-center mb-3 ml-auto">
<div class="dropdown dropdown-actions">
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton" data-bs-toggle="dropdown">
{% if admin %}<img loading="lazy" src="/@{{admin}}/pic" alt="avatar" class="profile-pic-20 mr-2">{{admin}}{% else %}<img loading="lazy" src="{{SITE_FULL_IMAGES}}/e/marseyjanny.webp" alt="avatar" class="profile-pic-20 mr-2">All{% endif %}
{% if admin %}<img loading="lazy" src="/@{{admin}}/pic" alt="avatar" class="profile-pic-20 mr-2">{{admin}}{% else %}<img loading="lazy" src="{{SITE_FULL_IMAGES}}/e/marseyjanny2.webp" alt="avatar" class="profile-pic-20 mr-2">All{% endif %}
</button>
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px); max-height: 50vh;
overflow: auto">
<a class="dropdown-item" href="{% if hole %}/h/{{hole}}{% endif %}/log{% if type %}?kind={{type}}{% endif %}"><img loading="lazy" src="{{SITE_FULL_IMAGES}}/e/marseyjanny.webp" alt="avatar" class="profile-pic-20 mr-2">All</a>
<a class="dropdown-item" href="{{get_href(new_admin='All')}}"><img loading="lazy" src="{{SITE_FULL_IMAGES}}/e/marseyjanny2.webp" alt="avatar" class="profile-pic-20 mr-2">All</a>
{% if not hole %}
<a class="dropdown-item" href="/log?{{single_user_url}}=AutoJanny{% if type %}&kind={{type}}{% endif %}"><img loading="lazy" src="/@AutoJanny/pic" alt="avatar" class="profile-pic-20 mr-2">AutoJanny</a>
<a class="dropdown-item" href="{{get_href(new_admin='AutoJanny')}}"><img loading="lazy" src="/@AutoJanny/pic" alt="avatar" class="profile-pic-20 mr-2">AutoJanny</a>
{% endif %}
{% for a in admins %}
<a class="dropdown-item" href="{% if hole %}/h/{{hole}}{% endif %}/log?{{single_user_url}}={{a}}{% if type %}&kind={{type}}{% endif %}"><img loading="lazy" src="/@{{a}}/pic" alt="avatar" class="profile-pic-20 mr-2">{{a}}</a>
<a class="dropdown-item" href="{{get_href(new_admin=a)}}"><img loading="lazy" src="/@{{a}}/pic" alt="avatar" class="profile-pic-20 mr-2">{{a}}</a>
{% endfor %}
</div>
</div>
<div class="dropdown dropdown-actions ml-3">
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton2" data-bs-toggle="dropdown">
{% if type %}<i class="fas {{types[type]['icon']}} mr-2"></i>{{type}}{% else %}<i class="fas fa-broom mr-2"></i>All{% endif %}
{% if kind %}<i class="fas {{kinds[kind]['icon']}} mr-2"></i>{{kind}}{% else %}<i class="fas fa-broom mr-2"></i>All{% endif %}
</button>
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px); max-height: 50vh;
overflow: auto">
<a class="dropdown-item" href="{% if hole %}/h/{{hole}}{% endif %}/log{% if admin %}?{{single_user_url}}={{admin}}{% endif %}"><i class="fas fa-broom mr-2"></i>All</a>
{% for t, v in types.items() %}
<a class="dropdown-item" href="{% if hole %}/h/{{hole}}{% endif %}/log?{% if admin %}{{single_user_url}}={{admin}}&{% endif %}kind={{t}}"><i class="fas {{v['icon']}} mr-2"></i>{{t}}</a>
<a class="dropdown-item" href="{{get_href(new_kind='All')}}"><i class="fas fa-broom mr-2"></i>All</a>
{% for t, v in kinds.items() %}
<a class="dropdown-item" href="{{get_href(new_kind=t)}}"><i class="fas {{v['icon']}} mr-2"></i>{{t}}</a>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
</div>
</div>
</div>
@ -54,13 +78,13 @@
{% for ma in actions %}
<div id="action-{{ma.id}}" class="modlog-action{% if ma.unread %} unread{% endif %}">
<div class="d-flex flex-grow-1 align-items-center">
<a href="{% if hole %}/h/{{hole}}{% endif %}/log?{% if admin %}{{single_user_url}}={{admin}}&{% endif %}kind={{ma.kind}}">
<a href="{{get_href(new_kind=ma.kind)}}">
<div class="d-flex align-items-center justify-content-center {{ma.color}} mr-3 rounded-lg flex-shrink-0" style="width: 32px;height: 32px">
<i class="fas text-center {{ma.icon}} text-lg text-white fa-fw"></i>
</div>
</a>
<div class="d-flex align-items-center">
<a href="{% if hole %}/h/{{hole}}{% endif %}/log?{{single_user_url}}={{ma.user.username}}{% if type %}&kind={{type}}{% endif %}">
<a href="{{get_href(new_admin=ma.user.username)}}">
<span class="rounded">
<div class="profile-pic-35-wrapper">
<img loading="lazy" src="{{ma.user.profile_url}}" alt="avatar" class="profile-pic-35">