mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 13:13:09 +00:00
这是一次综合性的项目迭代,包含以下核心变更:
1. **目录与模块重构**
- 调整工作流节点类型模块目录结构,迁移节点类型相关代码
- 重命名platform模块为system模块,更新插件配置信息
- 重构代码生成模块导入路径
2. **数据库与CRUD优化**
- 统一所有CRUD类构造函数,新增数据库会话参数
- 修复权限过滤器数据库会话使用问题
- 更新模板生成器的CRUD代码模板
3. **认证与安全改进**
- 重构JWT密钥配置,移除默认密钥强制要求环境变量
- 重命名密码工具类,统一密码加密校验逻辑
- 优化OAuth认证流程,修复匿名认证使用问题
4. **前端与静态资源**
- 重构前端挂载逻辑,增加目录存在性校验
- 使用标准StaticFiles替换自定义前端挂载实现
5. **工具类与依赖更新**
- 修复导入工具的表名重复检测逻辑
- 优化限流回调代码,移除冗余依赖
- 更新用户、租户等模块的响应模型字段
6. **数据与配置修正**
- 修复系统版本数据字段命名不统一问题
- 简化枚举类校验逻辑,移除冗余注释
- 修复测试用例中的密码工具类导入错误
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
from collections.abc import Sequence
|
|
from typing import Any
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.api.v1.module_system.dict.model import DictDataModel, DictTypeModel
|
|
from app.api.v1.module_system.dict.schema import (
|
|
DictDataCreateSchema,
|
|
DictDataUpdateSchema,
|
|
DictTypeCreateSchema,
|
|
DictTypeUpdateSchema,
|
|
)
|
|
from app.core.base_crud import CRUDBase
|
|
from app.core.base_schema import AuthSchema
|
|
|
|
|
|
class DictTypeCRUD(CRUDBase[DictTypeModel, DictTypeCreateSchema, DictTypeUpdateSchema]):
|
|
"""数据字典类型数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema, db: AsyncSession) -> None:
|
|
"""初始化数据字典类型数据层。
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
|
- db (AsyncSession): 数据库会话。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
super().__init__(model=DictTypeModel, auth=auth, db=db)
|
|
|
|
|
|
class DictDataCRUD(CRUDBase[DictDataModel, DictDataCreateSchema, DictDataUpdateSchema]):
|
|
"""数据字典数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema, db: AsyncSession) -> None:
|
|
"""初始化数据字典项数据层。
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
|
- db (AsyncSession): 数据库会话。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
super().__init__(model=DictDataModel, auth=auth, db=db)
|
|
|
|
async def batch_delete(self, ids: list[int], exclude_system: bool = True) -> int:
|
|
"""批量删除数据字典数据
|
|
|
|
参数:
|
|
- ids (list[int]): 数据字典数据ID列表
|
|
- exclude_system (bool): 是否排除系统默认数据,默认为True
|
|
|
|
返回:
|
|
- int: 删除的记录数量
|
|
"""
|
|
if exclude_system:
|
|
system_data = await self.get_list(
|
|
search={
|
|
"id__in": ids,
|
|
"remark__contains": "系统默认",
|
|
},
|
|
)
|
|
system_ids = [item.id for item in system_data]
|
|
ids = [id for id in ids if id not in system_ids]
|
|
|
|
if ids:
|
|
await self.delete(ids=ids)
|
|
return len(ids)
|
|
|
|
async def get_list_by_dict_type(self, dict_type: str, status: int | None = 0) -> Sequence[DictDataModel]:
|
|
"""根据字典类型获取字典数据列表
|
|
|
|
参数:
|
|
- dict_type (str): 字典类型
|
|
- status (str | None): 状态过滤,None表示不过滤
|
|
|
|
返回:
|
|
- Sequence[DictDataModel]: 数据字典数据模型序列
|
|
"""
|
|
search: dict[str, Any] = {"dict_type": dict_type}
|
|
if status is not None:
|
|
search["status"] = status
|
|
return await self.get_list(search=search, order_by=[{"id": "asc"}])
|