diff --git a/README.md b/README.md index a293630..36a05c0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 直播账号运营后台 -斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.31)。 +斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.32)。 ## 能做什么 diff --git a/docs/微博/微博账号池与个人工作台-2026-11-08.md b/docs/微博/微博账号池与个人工作台-2026-11-08.md index fb10986..885abb5 100644 --- a/docs/微博/微博账号池与个人工作台-2026-11-08.md +++ b/docs/微博/微博账号池与个人工作台-2026-11-08.md @@ -59,8 +59,9 @@ UNIQUE(account_id, exclusive_slot) - `weibo:view`:查看全局账号管理。 - `weibo:assign`:查看全部账号、进入分配管理、批量分配/取消分配客服归属。 - `weibo:assign:force`:查看「全部账号」页签,把勾选账号或指定标签下的全部账号 - 强制转给客服。默认仅超级管理员拥有;运营默认关闭,可在用户管理的权限弹窗中 - 单独打开。 + 强制转给客服;同时控制「导入账号 → 批量粘贴」里 + “其他人的工作台占用时,强制转入当前工作台”复选框。 + 默认超级管理员与运营拥有,客服没有,可在用户管理的权限弹窗中调整。 - `weibo:workbench`:访问个人微博工作台。 - `weibo:import`:导入外部 CK。 - `weibo:manage`:编辑账号标签/备注、启停账号、批量标签。 diff --git a/pyproject.toml b/pyproject.toml index 9b22b37..49a5633 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "live-hub-py" -version = "0.4.31" +version = "0.4.32" description = "直播账号运营 Web 后台" readme = "README.md" requires-python = ">=3.12,<3.13" diff --git a/tests/test_weibo_accounts.py b/tests/test_weibo_accounts.py index 07f9f14..ae0d7a0 100644 --- a/tests/test_weibo_accounts.py +++ b/tests/test_weibo_accounts.py @@ -838,7 +838,8 @@ def test_super_admin_force_adds_account_without_removing_original_owner( @pytest.mark.parametrize("role", ["operation", "support"]) -def test_non_super_admin_cannot_force_add_occupied_workbench_account(db, role): +def test_force_add_occupied_requires_force_permission(db, role): + """强制转入他人工作台跟 weibo:assign:force 对齐:运营有、客服没有。""" user = User( username=f"weibo-force-add-{role}", password_hash="hash", @@ -848,10 +849,58 @@ def test_non_super_admin_cannot_force_add_occupied_workbench_account(db, role): db.add(user) db.commit() + owner = User( + username=f"weibo-force-add-owner-{role}", + password_hash="hash", + role="support", + is_active=True, + ) + db.add(owner) + db.commit() + account = WeiboAccount( + uid=f"40140009{1 if role == 'operation' else 2}", + nickname=f"用户84777918{1 if role == 'operation' else 2}", + cookie=f"SCF=a; SUB=force-add-{role}", + assigned_to=owner.id, + ) + db.add(account) + db.commit() + db.add( + WeiboWorkbenchAccount( + user_id=owner.id, + account_id=account.id, + exclusive_slot=1, + ) + ) + db.commit() + + if role == "operation": + result = import_workbench_accounts_by_text( + WeiboWorkbenchBatchImportRequest( + text=account.uid, + force_add_occupied=True, + ), + db=db, + current=user, + ) + assert result.forced_added == 1 + assert result.items[0].status == "forced_added" + # 原使用人的工作台记录不被移除 + assert ( + db.query(WeiboWorkbenchAccount) + .filter( + WeiboWorkbenchAccount.user_id == owner.id, + WeiboWorkbenchAccount.account_id == account.id, + ) + .count() + == 1 + ) + return + with pytest.raises(HTTPException) as excinfo: import_workbench_accounts_by_text( WeiboWorkbenchBatchImportRequest( - text="用户8477791859", + text=account.uid, force_add_occupied=True, ), db=db, @@ -859,7 +908,7 @@ def test_non_super_admin_cannot_force_add_occupied_workbench_account(db, role): ) assert excinfo.value.status_code == 403 - assert "仅超级管理员" in str(excinfo.value.detail) + assert "weibo:assign:force" in str(excinfo.value.detail) def test_operation_can_transfer_workbench_account_to_collab(db): diff --git a/uv.lock b/uv.lock index e0e0690..d8d1f5d 100644 --- a/uv.lock +++ b/uv.lock @@ -381,7 +381,7 @@ wheels = [ [[package]] name = "live-hub-py" -version = "0.4.31" +version = "0.4.32" source = { editable = "." } dependencies = [ { name = "alembic" }, diff --git a/web/backend/routers/weibo.py b/web/backend/routers/weibo.py index 8d91be5..4e03a0c 100644 --- a/web/backend/routers/weibo.py +++ b/web/backend/routers/weibo.py @@ -383,10 +383,12 @@ def import_workbench_accounts_by_text( """按 UID/用户名/角色批量解析账号并加入当前用户工作台。""" _require_weibo_perm(current, "weibo:workbench") - if req.force_add_occupied and current.role != "super_admin": + if req.force_add_occupied and not user_has_permission( + current, "weibo:assign:force" + ): raise HTTPException( status_code=403, - detail="仅超级管理员可以强制转入其他人的工作台账号", + detail="没有强制转入他人工作台账号的权限(需要 weibo:assign:force)", ) identifiers: list[str] = [] for token in re.split(r"[\s,,;;]+", req.text.strip()): diff --git a/web/frontend/src/pages/WeiboAccountsPage.tsx b/web/frontend/src/pages/WeiboAccountsPage.tsx index aadcefb..187b0f8 100644 --- a/web/frontend/src/pages/WeiboAccountsPage.tsx +++ b/web/frontend/src/pages/WeiboAccountsPage.tsx @@ -195,9 +195,8 @@ export default function WeiboAccountsPage({ mode?: WeiboAccountsPageMode; }) { const { token } = theme.useToken(); - const { can, user } = usePermissions(); + const { can } = usePermissions(); const navigate = useNavigate(); - const isSuperAdmin = user?.role === 'super_admin'; const isWorkbench = mode === 'workbench'; const canImport = can('weibo:import'); const canManage = can('weibo:manage'); @@ -208,6 +207,8 @@ export default function WeiboAccountsPage({ const canDelete = can('weibo:delete'); const canAssign = can('weibo:assign'); const canForceUpdateCk = can('weibo:assign:force'); + // 强制转入他人工作台与强制改归属共用同一个权限点:超管 + 运营有,客服没有。 + const canForceAddOccupied = canForceUpdateCk; const canTransferCollab = can('weibo:workbench'); const [items, setItems] = useState([]); @@ -513,7 +514,7 @@ export default function WeiboAccountsPage({ setPoolSelectedIds([]); setWorkbenchImportTab('paste'); setBatchImportText(''); - setForceAddOccupied(isSuperAdmin); + setForceAddOccupied(canForceAddOccupied); setBatchImportResult(null); setPoolOpen(true); void loadWorkbenchPool(1, poolPageSize, ''); @@ -530,7 +531,7 @@ export default function WeiboAccountsPage({ try { const result = await weiboApi.batchImportWorkbenchAccounts( text, - isSuperAdmin && forceAddOccupied, + canForceAddOccupied && forceAddOccupied, ); const refreshResult = await refreshImportedAccounts( result.items @@ -3025,7 +3026,7 @@ export default function WeiboAccountsPage({ title="支持多行、空格、逗号分隔" description="优先按 UID 精确匹配;也支持微博用户名和角色名。重名时请改用 UID。导入成功后会立即刷新角色绑定和微豆余额。" /> - {isSuperAdmin && ( + {canForceAddOccupied && (