mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-17 05:38:28 +08:00

* Reconstruct RBAC authentication logic * fix typo * Migrate casbin sqla Adapter to redis * Delete casbin model conf file * Add permission dependencies * Add request permission depends on execution condition * Update openapi authorization method * Add request permission identity * Add request permission dependency description * Migrate casbin redis adapter to sqla * Update menu model and add function * Fix menu permission identification * Update user partial interface permissions * Update menu table SQL * Add role menu permission description to README * fix README typo * Simplify permission dependency injection * Fix menu authorization store * Fix interface permission dependency order * Update role menu permission flag * Update the background permission logic of the interface
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path
|
|
|
|
from backend.app.common.jwt import DependsJwtAuth
|
|
from backend.app.common.permission import RequestPermission
|
|
from backend.app.common.rbac import DependsRBAC
|
|
from backend.app.common.response.response_code import CustomResponseCode
|
|
from backend.app.common.response.response_schema import response_base
|
|
from backend.app.services.task_service import TaskService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get('', summary='获取所有可执行任务模块', dependencies=[DependsJwtAuth])
|
|
async def get_all_tasks():
|
|
tasks = TaskService.gets()
|
|
return await response_base.success(data=tasks)
|
|
|
|
|
|
@router.get('/{pk}', summary='获取任务结果', dependencies=[DependsJwtAuth])
|
|
async def get_task_result(pk: str = Path(description='任务ID')):
|
|
task = TaskService.get(pk)
|
|
if not task:
|
|
return await response_base.fail(res=CustomResponseCode.HTTP_204, data=pk)
|
|
return await response_base.success(data=task.result)
|
|
|
|
|
|
@router.post(
|
|
'/{module}',
|
|
summary='执行任务',
|
|
dependencies=[
|
|
Depends(RequestPermission('sys:task:run')),
|
|
DependsRBAC,
|
|
],
|
|
)
|
|
async def run_task(
|
|
module: Annotated[str, Path(description='任务模块')],
|
|
args: Annotated[list | None, Body()] = None,
|
|
kwargs: Annotated[dict | None, Body()] = None,
|
|
):
|
|
task = TaskService.run(module=module, args=args, kwargs=kwargs)
|
|
return await response_base.success(data=task.result)
|