usermod/Router/AuthRuleRouter.py

78 lines
3.7 KiB
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from CrudModel.DefaultAuthRule import default_auth_rule_crud
from Schemas import AuthRuleSchemas
from Crud import AuthRuleCrud
from Utils.AuthUtils import admin_auth_token_depend
from Utils.SqlAlchemyUtils import get_db
router = APIRouter(
tags=["权限规则"],
prefix="/api/user_mod/auth_rule",
dependencies=[Depends(admin_auth_token_depend)]
)
default_auth_rule_crud.mount(router)
@router.post("/add_auth_rule", summary="添加权限规则", response_model=AuthRuleSchemas.AuthRuleInfo)
def add_auth_rule(body: AuthRuleSchemas.AuthRuleAddInfo, db: Session = Depends(get_db)):
new_auth_rule = AuthRuleCrud.add_auth_rule(db, body.name, body.category1, body.category2)
return new_auth_rule.to_dict()
@router.post("/delete_auth_rule", summary="删除权限规则")
def delete_auth_rule(body: AuthRuleSchemas.AuthRuleId, db: Session = Depends(get_db)):
AuthRuleCrud.delete_auth_rule(db, body.id)
return {"msg": "删除成功", "state": 1}
# @router.post("/delete_auth_rule_by_id_list", summary="批量删除权限规则节点")
# def delete_auth_rule_node_by_id_list(body: AuthRuleSchemas.AuthRuleIdList, db: Session = Depends(get_db)):
# AuthRuleCrud.delete_auth_rule_by_id_list(db, body.id_list)
# return {"msg": "删除成功", "state": 1}
@router.post("/change_auth_rule", summary="修改权限规则")
def change_auth_rule(body: AuthRuleSchemas.AuthRuleChangeInfo, db: Session = Depends(get_db)):
AuthRuleCrud.change_auth_rule(db, body.id, body.dict())
return {"msg": "修改成功", "state": 1}
@router.get("/get_auth_rule_tree", summary="获取权限规则树")
def get_auth_rule_tree(db: Session = Depends(get_db)):
auth_rule_tree = AuthRuleCrud.get_auth_rule_tree(db)
return auth_rule_tree
@router.post("/get_auth_rule_list", summary="获取权限规则列表", response_model=AuthRuleSchemas.AuthRuleInfoList)
def get_auth_rule_list(query_params: AuthRuleSchemas.AuthRuleQueryParams, db: Session = Depends(get_db)):
count, auth_rule_list = AuthRuleCrud.get_auth_rule_list(db, query_params)
rule_info_list = [item.to_dict() for item in auth_rule_list]
data = AuthRuleSchemas.AuthRuleInfoList(auth_rule_list=rule_info_list, count=count)
return data
# @router.post("/add_auth_category", summary="添加权限规则分类", response_model=AuthRuleSchemas.AuthCategoryAddInfo)
# def add_auth_category(body: AuthRuleSchemas.AuthCategoryAddInfo, db: Session = Depends(get_db)):
# new_auth_rule = AuthRuleCrud.add_auth_category(db, body.name, body.belong, body.category_level)
# return new_auth_rule
# @router.post("/change_auth_category", summary="修改权限规则分类信息")
# def change_auth_category(body: AuthRuleSchemas.AuthCategoryChangeInfo, db: Session = Depends(get_db)):
# AuthRuleCrud.change_auth_category(db, body.id, {'name': body.name, 'belong': body.belong,'':"category_level"})
# return {"msg": "修改成功", "state": 1}
#
#
# @router.post("/delete_auth_category", summary="删除权限规则分类")
# def delete_auth_category(body: AuthRuleSchemas.AuthCategoryId, db: Session = Depends(get_db)):
# new_auth_rule = AuthRuleCrud.delete_auth_category(db, body.name, body.belong, body.category_level)
# return new_auth_rule
#
#
# @router.post("/get_default_auth_rule_config_list", summary="获取默认权限规则配置列表",
# response_model=AuthRuleSchemas.AuthRuleConfigInfoList)
# def get_default_auth_rule_config(query_params: AuthRuleSchemas.AuthRuleConfigQueryParams,
# db: Session = Depends(get_db)):
# default_auth_rule_config_list = AuthRuleCrud.get_default_auth_rule_config_list(db, query_params)
# return default_auth_rule_config_list