mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-28 06:57:54 +00:00
- 修改alembic配置以使用异步数据库URI和更新Base类引用 - 新增数据库Schema优化脚本,统一字段长度,添加索引,规范外键策略 - 重构API路由管理,按模块类型分组并统一前缀 - 删除示例、监控及系统各子模块的模型定义,减少冗余代码 - 将mcp_server相关代码迁移到module_ai模块下,规范模块目录结构 - 迁移example控制器至module_application.application模块,并重命名相关服务和参数名 - 优化示例控制器中的依赖和响应结构,统一命名规范
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Sequence, Optional
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
from .model import RoleModel
|
|
from .schema import RoleCreateSchema, RoleUpdateSchema
|
|
from ..auth.schema import AuthSchema
|
|
from ..menu.crud import MenuCRUD
|
|
from ..dept.crud import DeptCRUD
|
|
|
|
|
|
class RoleCRUD(CRUDBase[RoleModel, RoleCreateSchema, RoleUpdateSchema]):
|
|
"""角色模块数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
self.auth = auth
|
|
super().__init__(model=RoleModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[RoleModel]:
|
|
"""根据id获取角色信息"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_list_crud(self, search: Dict = None, order_by: List[Dict[str, str]] = None) -> Sequence[RoleModel]:
|
|
"""获取角色列表"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|
|
async def set_role_menus_crud(self, role_ids: List[int], menu_ids: List[int]) -> None:
|
|
"""设置角色的菜单权限"""
|
|
roles = await self.list(search={"id": ("in", role_ids)})
|
|
menus = await MenuCRUD(self.auth).get_list_crud(search={"id": ("in", menu_ids)})
|
|
await self.update_relationships(
|
|
objs_to_update=roles,
|
|
relationship_field="menus",
|
|
related_objs=menus
|
|
)
|
|
|
|
async def set_role_data_scope_crud(self, role_ids: List[int], data_scope: int) -> None:
|
|
"""设置角色的数据范围"""
|
|
await self.set(ids=role_ids, data_scope=data_scope)
|
|
|
|
async def set_role_depts_crud(self, role_ids: List[int], dept_ids: List[int]) -> None:
|
|
"""设置角色的部门权限"""
|
|
roles = await self.list(search={"id": ("in", role_ids)})
|
|
depts = await DeptCRUD(self.auth).get_list_crud(search={"id": ("in", dept_ids)})
|
|
await self.update_relationships(
|
|
objs_to_update=roles,
|
|
relationship_field="depts",
|
|
related_objs=depts
|
|
)
|
|
|
|
async def set_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""设置角色的可用状态"""
|
|
await self.set(ids=ids, status=status)
|