旧库升级期全链路兼容:登录/权限降级与待升级提示
1. 权限解析降级:数据库无 permission_groups/group_id 时按旧 role_type 使用内置预置权限,保证登录、会话同步、升级弹窗可用(升级后自动切真实权限组) 2. 管理员列表/角色查询降级;权限组列表降级为只读占位 3. 管理员/权限组/邮箱写操作在旧库返回明确的待升级提示;create_admin 不传邮箱不写 email 列 4. 全局异常对缺表/缺列错误返回待升级提示
This commit is contained in:
1 parent
6c8fd2b432
commit
8cd2c83412
7 files changed
+273
-79
No files matched your search
@@ -11,6 +11,10 @@
|
||||
|
||||
from typing import Optional, Dict, Any, List
|
||||
from utils.database import execute_one, execute_query, execute_insert, execute_update
|
||||
from utils.logger import get_logger
|
||||
from models.permission_group import apply_legacy_group_fields
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class AdminRoleModel:
|
||||
@@ -30,7 +34,19 @@ class AdminRoleModel:
|
||||
WHERE ar.user_id = %s
|
||||
LIMIT 1
|
||||
"""
|
||||
return await execute_one(sql, (user_id,))
|
||||
try:
|
||||
return await execute_one(sql, (user_id,))
|
||||
except Exception as e:
|
||||
# 数据库尚未升级(缺少 group_id / permission_groups)时按旧角色降级
|
||||
logger.warning(f"读取管理员角色失败,按旧角色降级(数据库可能待升级): {e}")
|
||||
legacy_sql = """
|
||||
SELECT ar.*, s.subject_name
|
||||
FROM admin_roles ar
|
||||
LEFT JOIN subjects s ON ar.subject_id = s.subject_id
|
||||
WHERE ar.user_id = %s
|
||||
LIMIT 1
|
||||
"""
|
||||
return apply_legacy_group_fields(await execute_one(legacy_sql, (user_id,)))
|
||||
|
||||
@staticmethod
|
||||
async def get_all() -> List[Dict[str, Any]]:
|
||||
@@ -45,7 +61,20 @@ class AdminRoleModel:
|
||||
LEFT JOIN permission_groups pg ON ar.group_id = pg.group_id
|
||||
ORDER BY COALESCE(pg.is_locked, 0) DESC, COALESCE(pg.is_system, 0) DESC, ar.user_id
|
||||
"""
|
||||
return await execute_query(sql)
|
||||
try:
|
||||
return await execute_query(sql)
|
||||
except Exception as e:
|
||||
# 数据库尚未升级(缺少 group_id / permission_groups / users.email)时降级
|
||||
logger.warning(f"读取管理员列表失败,按旧角色降级(数据库可能待升级): {e}")
|
||||
legacy_sql = """
|
||||
SELECT ar.*, u.real_name, u.username, u.status, s.subject_name
|
||||
FROM admin_roles ar
|
||||
JOIN users u ON ar.user_id = u.user_id
|
||||
LEFT JOIN subjects s ON ar.subject_id = s.subject_id
|
||||
ORDER BY ar.user_id
|
||||
"""
|
||||
rows = await execute_query(legacy_sql)
|
||||
return [apply_legacy_group_fields(row) for row in rows]
|
||||
|
||||
@staticmethod
|
||||
async def create(
|
||||
|
||||
Reference in new issue
Block a user