feat:新增投顾agent和nl2sqlagent
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""投顾 Agent 的角色与客户关系授权规则。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from common.common_const import (
|
||||
CUSTOMER_REL_STATUS_SIGNED,
|
||||
CUSTOMER_REL_STATUS_UNSIGNED,
|
||||
EMPLOYEE_ROLE_ADVISOR,
|
||||
ERR_CODE_FORBIDDEN_CUSTOMER,
|
||||
)
|
||||
from utils.exceptions import ApiError
|
||||
from repositories.customer_relation import CustomerRelationRepo
|
||||
|
||||
|
||||
def ensure_advisor_role(user) -> bool:
|
||||
if (
|
||||
getattr(user, "user_type", None) != "EMPLOYEE"
|
||||
or getattr(user, "employee_role", None) != EMPLOYEE_ROLE_ADVISOR
|
||||
):
|
||||
raise ApiError(ERR_CODE_FORBIDDEN_CUSTOMER, "无权操作该客户数据")
|
||||
return True
|
||||
|
||||
|
||||
def relation_allows_access(status: str) -> bool:
|
||||
return status in {CUSTOMER_REL_STATUS_UNSIGNED, CUSTOMER_REL_STATUS_SIGNED}
|
||||
|
||||
|
||||
async def ensure_customer_access(db, *, advisor_id: int, customer_id: int):
|
||||
relation = await CustomerRelationRepo(db).get_active_relation(
|
||||
customer_id=customer_id,
|
||||
advisor_id=advisor_id,
|
||||
)
|
||||
if relation is None:
|
||||
raise ApiError(ERR_CODE_FORBIDDEN_CUSTOMER, "无权操作该客户数据")
|
||||
return relation
|
||||
Reference in New Issue
Block a user