feat: restore system messages admin page

This commit is contained in:
chengkml
2026-06-14 00:38:33 +08:00
parent 98a65821e7
commit 2098e6797d
13 changed files with 472 additions and 17 deletions
+1 -1
View File
@@ -34,7 +34,6 @@ AUDIT_LOG_LOAD_OPTIONS = (
REMOVED_MENU_CODES = {
"dashboard",
"admin.wxapp",
"admin.system_message",
"admin.inbox",
"admin.code_review",
"admin.git_desktop",
@@ -408,6 +407,7 @@ def delete_menu(db: Session, menu_id: int) -> bool:
"admin.roles",
"admin.menus",
"admin.system_params",
"admin.system_message",
"admin.system",
"admin.system_monitor",
"admin.basic_data",
@@ -33,7 +33,6 @@ PROTECTED_ROLE_IDS = {"admin", "user", "sys_mgr"}
REMOVED_MENU_CODES = {
"dashboard",
"admin.wxapp",
"admin.system_message",
"admin.inbox",
"admin.code_review",
"admin.git_desktop",
@@ -66,6 +65,7 @@ PROTECTED_MENU_CODES = {
"admin.roles",
"admin.menus",
"admin.system_params",
"admin.system_message",
"admin.system",
"admin.system_monitor",
"admin.wxapp",
+2 -1
View File
@@ -18,6 +18,7 @@ DEFAULT_ADMIN_PERMISSION_CODES: set[str] = {
"menu.manage",
"system_param.read",
"system_param.manage",
"admin.system_message",
"file.read",
"file.manage",
"line.read",
@@ -49,7 +50,6 @@ ADMIN_ROLE_IDS = {
DISABLED_MENU_CODES: set[str] = {
"dashboard",
"admin.wxapp",
"admin.system_message",
"admin.inbox",
"admin.code_review",
"admin.git_desktop",
@@ -88,6 +88,7 @@ MENU_CODE_PERMISSION_MAP: dict[str, set[str]] = {
"admin.roles": {"role.read", "role.manage"},
"admin.menus": {"menu.read", "menu.manage"},
"admin.system_params": {"system_param.read", "system_param.manage"},
"admin.system_message": {"admin.system_message"},
"admin.fl_analysis": {"line.read", "line.manage"},
"admin.files": {"file.read", "file.manage"},
"admin.elevation": {"elevation.read", "elevation.manage"},
+16
View File
@@ -92,6 +92,7 @@ DEFAULT_PERMISSIONS: dict[str, str] = {
"menu.manage": "Manage menus",
"system_param.read": "Read system parameters",
"system_param.manage": "Manage system parameters",
"admin.system_message": "Manage system messages",
"file.read": "Read file mounts and indexed entries",
"file.manage": "Manage file operations and storage sync",
"line.read": "Read power lines",
@@ -126,6 +127,7 @@ DEFAULT_ROLES: dict[str, dict[str, object]] = {
"menu.manage",
"system_param.read",
"system_param.manage",
"admin.system_message",
"file.read",
"file.manage",
"line.read",
@@ -206,6 +208,19 @@ DEFAULT_MENUS: list[dict[str, object]] = [
"cacheable": False,
"permission_code": "system_param.read",
},
{
"code": "admin.system_message",
"name": "系统消息",
"path": "/admin/system-messages",
"icon": "Bell",
"parent_code": None,
"type": "menu",
"sort_order": 46,
"status": "enabled",
"visible": True,
"cacheable": False,
"permission_code": "admin.system_message",
},
{
"code": "admin.power_lines",
"name": "线路管理",
@@ -435,6 +450,7 @@ ROLE_MENU_BINDINGS: dict[str, list[str]] = {
"admin.roles",
"admin.menus",
"admin.system_params",
"admin.system_message",
"admin.power_lines",
"admin.fl_analysis",
"admin.fault_recurrence",
+7 -7
View File
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import select, update
from sqlalchemy import func, select, update
from sqlalchemy.orm import Session
from ..models.system_message import SystemMessage
@@ -45,17 +45,17 @@ def list_user_messages(
query = query.where(SystemMessage.is_read == False)
# 获取总数
total_query = select(SystemMessage).where(
total_query = select(func.count()).select_from(SystemMessage).where(
(SystemMessage.target_user_id == user_id) | (SystemMessage.target_user_id.is_(None))
)
total = db.scalar(select(len(total_query.subquery().c.message_id)))
total = db.scalar(total_query)
# 获取未读数
unread_query = select(SystemMessage).where(
unread_query = select(func.count()).select_from(SystemMessage).where(
(SystemMessage.target_user_id == user_id) | (SystemMessage.target_user_id.is_(None)),
SystemMessage.is_read == False,
)
unread_count = db.scalar(select(len(unread_query.subquery().c.message_id)))
unread_count = db.scalar(unread_query)
# 按创建时间倒序
query = query.order_by(SystemMessage.created_at.desc())
@@ -88,9 +88,9 @@ def mark_messages_as_read(
def get_unread_count(db: Session, user_id: str) -> int:
"""获取用户未读消息数量"""
query = select(SystemMessage).where(
query = select(func.count()).select_from(SystemMessage).where(
(SystemMessage.target_user_id == user_id) | (SystemMessage.target_user_id.is_(None)),
SystemMessage.is_read == False,
)
count = db.scalar(select(len(query.subquery().c.message_id)))
count = db.scalar(query)
return count or 0
+1
View File
@@ -21,6 +21,7 @@ TOPIC_RULES: dict[str, TopicRule] = {
"admin.roles": TopicRule(any_permission_codes={"role.read", "role.manage"}),
"admin.menus": TopicRule(any_permission_codes={"menu.read", "menu.manage"}),
"admin.system-params": TopicRule(any_permission_codes={"system_param.read", "system_param.manage"}),
"admin.system-messages": TopicRule(any_permission_codes={"admin.system_message"}),
"admin.files": TopicRule(any_permission_codes={"file.read", "file.manage"}),
"admin.tower-models": TopicRule(any_permission_codes={"tower_model.read", "tower_model.manage", "tower.read", "tower.manage"}),
"admin.elevation": TopicRule(any_permission_codes={"elevation.read", "elevation.manage"}),