优化客服账号标签管理

This commit is contained in:
yml2213
2026-08-14 12:44:48 +08:00
parent 7fe6228901
commit baed0e61ff
6 changed files with 111 additions and 81 deletions
+12 -6
View File
@@ -94,6 +94,12 @@ def _require_huya_perm(user: User, permission: str) -> None:
raise HTTPException(status_code=403, detail="权限不足")
def _require_huya_tag_permission(user: User) -> None:
"""标签权限兼容历史上使用导入权限的运营人员。"""
if not (_has_huya_perm(user, "huya:tag") or _has_huya_perm(user, "huya:import")):
raise HTTPException(status_code=403, detail="无权修改虎牙账号标签")
def _can_view_huya_all(user: User) -> bool:
return _has_huya_perm(user, "huya:view_all")
@@ -1064,8 +1070,8 @@ def set_account_tag(
current: User = Depends(get_current_user),
):
"""设置单个虎牙账号标签。"""
_require_huya_perm(current, "huya:import")
account = db.query(HuyaAccount).filter(HuyaAccount.id == account_id).first()
_require_huya_tag_permission(current)
account = _visible_huya_accounts_query(db, current).filter(HuyaAccount.id == account_id).first()
if not account:
raise HTTPException(status_code=404, detail="账号不存在")
account.tag = (req.tag or "").strip()
@@ -1080,11 +1086,11 @@ def batch_tag(
current: User = Depends(get_current_user),
):
"""批量设置虎牙账号标签。"""
_require_huya_perm(current, "huya:import")
_require_huya_tag_permission(current)
if not req.account_ids:
raise HTTPException(status_code=400, detail="请选择账号")
tag = (req.tag or "").strip()
count = db.query(HuyaAccount).filter(HuyaAccount.id.in_(req.account_ids)).update(
count = _visible_huya_accounts_query(db, current).filter(HuyaAccount.id.in_(req.account_ids)).update(
{HuyaAccount.tag: tag},
synchronize_session=False,
)
@@ -1099,12 +1105,12 @@ def batch_tag_selection(
current: User = Depends(get_current_user),
):
"""按显式选择或当前筛选结果批量设置虎牙账号标签。"""
_require_huya_perm(current, "huya:import")
_require_huya_tag_permission(current)
ids = _selected_huya_account_ids(db, current, req)
if not ids:
raise HTTPException(status_code=400, detail="请选择虎牙账号")
tag = (req.tag_value or "").strip()
count = db.query(HuyaAccount).filter(HuyaAccount.id.in_(ids)).update(
count = _visible_huya_accounts_query(db, current).filter(HuyaAccount.id.in_(ids)).update(
{HuyaAccount.tag: tag},
synchronize_session=False,
)