mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 20:55:14 +00:00
chore: 完成多批次代码优化与重构
- 重构工作流模块目录结构,迁移代码文件 - 修复类型断言空值安全问题,添加 ! 操作符 - 优化样式类名,替换 flex-cc 为标准 flex 工具类 - 更新路由标签简化文案,移除冗余注释 - 调整 ruff 配置,放宽行长度限制 - 更新 README 与多语言文案,优化项目描述 - 修复表单、图表组件的类型与样式问题 - 简化搜索表单、数据卡片的布局代码
This commit is contained in:
@@ -21,7 +21,7 @@ from .schema import (
|
||||
)
|
||||
from .service import RoleService
|
||||
|
||||
RoleRouter = APIRouter(route_class=OperationLogRoute, prefix="/role", tags=["系统管理/角色管理"])
|
||||
RoleRouter = APIRouter(route_class=OperationLogRoute, prefix="/role", tags=["角色管理"])
|
||||
|
||||
_ROLE_NS = "role"
|
||||
|
||||
@@ -35,7 +35,7 @@ _ROLE_NS = "role"
|
||||
async def get_obj_list_controller(
|
||||
page: Annotated[PaginationQueryParam, Depends()],
|
||||
search: Annotated[RoleQueryParam, Depends()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:query']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:query"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
查询角色
|
||||
@@ -68,7 +68,7 @@ async def get_obj_list_controller(
|
||||
)
|
||||
async def get_obj_detail_controller(
|
||||
id: Annotated[int, Path(description="角色ID")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:detail']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:detail"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
查询角色详情
|
||||
@@ -91,7 +91,7 @@ async def get_obj_detail_controller(
|
||||
)
|
||||
async def create_obj_controller(
|
||||
data: RoleCreateSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:create']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:create"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
创建角色
|
||||
@@ -116,7 +116,7 @@ async def create_obj_controller(
|
||||
async def update_obj_controller(
|
||||
data: RoleUpdateSchema,
|
||||
id: Annotated[int, Path(description="角色ID")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:update']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:update"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
修改角色
|
||||
@@ -141,7 +141,7 @@ async def update_obj_controller(
|
||||
)
|
||||
async def delete_obj_controller(
|
||||
ids: Annotated[list[int], Body(description="ID列表")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:delete']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:delete"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
删除角色
|
||||
@@ -165,7 +165,7 @@ async def delete_obj_controller(
|
||||
)
|
||||
async def batch_set_available_obj_controller(
|
||||
data: BatchSetAvailable,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:patch']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:patch"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
批量修改角色状态
|
||||
@@ -189,7 +189,7 @@ async def batch_set_available_obj_controller(
|
||||
)
|
||||
async def set_role_permission_controller(
|
||||
data: RolePermissionSettingSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:permission']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:permission"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
角色授权
|
||||
@@ -213,7 +213,7 @@ async def set_role_permission_controller(
|
||||
)
|
||||
async def export_obj_list_controller(
|
||||
search: Annotated[RoleQueryParam, Depends()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(['module_system:role:export']))],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:role:export"]))],
|
||||
) -> StreamingResponse:
|
||||
"""
|
||||
导出角色
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from app.api.v1.module_platform.menu.crud import MenuCRUD
|
||||
from app.api.v1.module_system.dept.crud import DeptCRUD
|
||||
from app.core.base_crud import CRUDBase
|
||||
@@ -13,15 +12,6 @@ class RoleCRUD(CRUDBase[RoleModel, RoleCreateSchema, RoleUpdateSchema]):
|
||||
"""角色模块数据层"""
|
||||
|
||||
def __init__(self, auth: AuthSchema) -> None:
|
||||
"""
|
||||
初始化角色数据层。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
super().__init__(model=RoleModel, auth=auth)
|
||||
|
||||
async def set_role_menus_crud(self, role_ids: list[int], menu_ids: list[int]) -> None:
|
||||
@@ -36,18 +26,12 @@ class RoleCRUD(CRUDBase[RoleModel, RoleCreateSchema, RoleUpdateSchema]):
|
||||
- None
|
||||
"""
|
||||
roles = await self.list(search={"id": ("in", role_ids)})
|
||||
menus = (
|
||||
[]
|
||||
if not menu_ids
|
||||
else await MenuCRUD(self.auth).list(search={"id": ("in", menu_ids)})
|
||||
)
|
||||
menus = [] if not menu_ids else await MenuCRUD(self.auth).list(search={"id": ("in", menu_ids)})
|
||||
|
||||
from app.api.v1.module_platform.package.service import PackageService
|
||||
|
||||
if self.auth.user and not self.auth.user.is_superuser and self.auth.tenant_id:
|
||||
allowed_menu_ids = await PackageService.get_tenant_available_menu_ids(
|
||||
self.auth, self.auth.tenant_id
|
||||
)
|
||||
allowed_menu_ids = await PackageService.get_tenant_available_menu_ids(self.auth, self.auth.tenant_id)
|
||||
allowed_set = set(allowed_menu_ids)
|
||||
for menu in menus:
|
||||
if int(menu.id) not in allowed_set:
|
||||
@@ -71,11 +55,7 @@ class RoleCRUD(CRUDBase[RoleModel, RoleCreateSchema, RoleUpdateSchema]):
|
||||
- None
|
||||
"""
|
||||
roles = await self.list(search={"id": ("in", role_ids)})
|
||||
depts = (
|
||||
[]
|
||||
if not dept_ids
|
||||
else await DeptCRUD(self.auth).list(search={"id": ("in", dept_ids)})
|
||||
)
|
||||
depts = [] if not dept_ids else await DeptCRUD(self.auth).list(search={"id": ("in", dept_ids)})
|
||||
|
||||
for obj in roles:
|
||||
relationship = obj.depts
|
||||
|
||||
@@ -76,22 +76,10 @@ class RoleModel(ModelMixin, TenantMixin):
|
||||
name: Mapped[str] = mapped_column(String(64), nullable=False, comment="角色名称")
|
||||
code: Mapped[str] = mapped_column(String(64), nullable=False, comment="角色编码")
|
||||
order: Mapped[int] = mapped_column(Integer, nullable=False, default=999, comment="显示排序")
|
||||
data_scope: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
default=1,
|
||||
nullable=False,
|
||||
comment="数据权限范围(1:仅本人 2:本部门 3:本部门及以下 4:全部 5:自定义)",
|
||||
)
|
||||
status: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="状态(0:启动 1:停用)", index=True)
|
||||
description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="备注")
|
||||
data_scope: Mapped[int] = mapped_column(Integer, default=1, nullable=False, comment="数据权限范围(1:仅本人 2:本部门 3:本部门及以下 4:全部 5:自定义)")
|
||||
|
||||
menus: Mapped[list["MenuModel"]] = relationship(
|
||||
secondary="sys_role_menus",
|
||||
back_populates="roles",
|
||||
lazy="selectin",
|
||||
order_by="MenuModel.order",
|
||||
)
|
||||
depts: Mapped[list["DeptModel"]] = relationship(
|
||||
secondary="sys_role_depts", back_populates="roles", lazy="selectin"
|
||||
)
|
||||
users: Mapped[list["UserModel"]] = relationship(
|
||||
secondary="sys_user_roles", back_populates="roles", lazy="selectin"
|
||||
)
|
||||
menus: Mapped[list["MenuModel"]] = relationship(secondary="sys_role_menus", back_populates="roles", lazy="selectin", order_by="MenuModel.order",)
|
||||
depts: Mapped[list["DeptModel"]] = relationship(secondary="sys_role_depts", back_populates="roles", lazy="selectin")
|
||||
users: Mapped[list["UserModel"]] = relationship(secondary="sys_user_roles", back_populates="roles", lazy="selectin")
|
||||
|
||||
@@ -30,7 +30,7 @@ class RoleCreateSchema(BaseModel):
|
||||
le=5,
|
||||
description="数据权限范围(1:仅本人 2:本部门 3:本部门及以下 4:全部 5:自定义)",
|
||||
)
|
||||
status: int = Field(default=0, ge=0, le=1, description="状态(0:正常 1:禁用)")
|
||||
status: int = Field(default=0, ge=0, le=1, description="状态(0:启动 1:停用)")
|
||||
description: str | None = Field(default=None, max_length=255, description="描述")
|
||||
|
||||
@field_validator("code")
|
||||
|
||||
@@ -52,9 +52,7 @@ class RoleService:
|
||||
返回:
|
||||
- list[RoleOutSchema]: 角色详情字典列表
|
||||
"""
|
||||
role_list = await RoleCRUD(auth).list(
|
||||
search=search.__dict__ if search else {}, order_by=order_by
|
||||
)
|
||||
role_list = await RoleCRUD(auth).list(search=search.__dict__ if search else {}, order_by=order_by)
|
||||
return [RoleOutSchema.model_validate(role) for role in role_list]
|
||||
|
||||
@classmethod
|
||||
@@ -109,6 +107,7 @@ class RoleService:
|
||||
|
||||
# 检查租户配额
|
||||
from app.api.v1.module_platform.tenant.service import TenantService
|
||||
|
||||
await TenantService.check_quota_service(auth, auth.tenant_id, "role")
|
||||
|
||||
new_role = await RoleCRUD(auth).create(data=data)
|
||||
@@ -164,9 +163,7 @@ class RoleService:
|
||||
await RoleCRUD(auth).delete(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def set_role_permission_service(
|
||||
cls, auth: AuthSchema, data: RolePermissionSettingSchema
|
||||
) -> None:
|
||||
async def set_role_permission_service(cls, auth: AuthSchema, data: RolePermissionSettingSchema) -> None:
|
||||
"""
|
||||
设置角色权限
|
||||
|
||||
|
||||
Reference in New Issue
Block a user