feat(weibo): 强制转入他人工作台改为权限控制并开放给运营 (v0.4.32)
微博工作台「导入账号 → 批量粘贴」的“其他人的工作台占用时强制转入”
原本写死 current.role != "super_admin",运营看不到也用不了。
- 后端改为按 weibo:assign:force 权限判断(与强制改归属共用权限点),
请求被拒时提示具体权限名
- 前端复选框的显示、默认勾选和提交参数统一走 can('weibo:assign:force'),
运营可见可用,客服仍不可见
- 测试:运营强制转入成功(原使用人工作台保留)、客服 403
- 文档修正该权限点的默认归属,版本 0.4.31 → 0.4.32
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 直播账号运营后台
|
# 直播账号运营后台
|
||||||
|
|
||||||
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.31)。
|
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.32)。
|
||||||
|
|
||||||
## 能做什么
|
## 能做什么
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ UNIQUE(account_id, exclusive_slot)
|
|||||||
- `weibo:view`:查看全局账号管理。
|
- `weibo:view`:查看全局账号管理。
|
||||||
- `weibo:assign`:查看全部账号、进入分配管理、批量分配/取消分配客服归属。
|
- `weibo:assign`:查看全部账号、进入分配管理、批量分配/取消分配客服归属。
|
||||||
- `weibo:assign:force`:查看「全部账号」页签,把勾选账号或指定标签下的全部账号
|
- `weibo:assign:force`:查看「全部账号」页签,把勾选账号或指定标签下的全部账号
|
||||||
强制转给客服。默认仅超级管理员拥有;运营默认关闭,可在用户管理的权限弹窗中
|
强制转给客服;同时控制「导入账号 → 批量粘贴」里
|
||||||
单独打开。
|
“其他人的工作台占用时,强制转入当前工作台”复选框。
|
||||||
|
默认超级管理员与运营拥有,客服没有,可在用户管理的权限弹窗中调整。
|
||||||
- `weibo:workbench`:访问个人微博工作台。
|
- `weibo:workbench`:访问个人微博工作台。
|
||||||
- `weibo:import`:导入外部 CK。
|
- `weibo:import`:导入外部 CK。
|
||||||
- `weibo:manage`:编辑账号标签/备注、启停账号、批量标签。
|
- `weibo:manage`:编辑账号标签/备注、启停账号、批量标签。
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.31"
|
version = "0.4.32"
|
||||||
description = "直播账号运营 Web 后台"
|
description = "直播账号运营 Web 后台"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12,<3.13"
|
requires-python = ">=3.12,<3.13"
|
||||||
|
|||||||
@@ -838,7 +838,8 @@ def test_super_admin_force_adds_account_without_removing_original_owner(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("role", ["operation", "support"])
|
@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(
|
user = User(
|
||||||
username=f"weibo-force-add-{role}",
|
username=f"weibo-force-add-{role}",
|
||||||
password_hash="hash",
|
password_hash="hash",
|
||||||
@@ -848,10 +849,58 @@ def test_non_super_admin_cannot_force_add_occupied_workbench_account(db, role):
|
|||||||
db.add(user)
|
db.add(user)
|
||||||
db.commit()
|
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:
|
with pytest.raises(HTTPException) as excinfo:
|
||||||
import_workbench_accounts_by_text(
|
import_workbench_accounts_by_text(
|
||||||
WeiboWorkbenchBatchImportRequest(
|
WeiboWorkbenchBatchImportRequest(
|
||||||
text="用户8477791859",
|
text=account.uid,
|
||||||
force_add_occupied=True,
|
force_add_occupied=True,
|
||||||
),
|
),
|
||||||
db=db,
|
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 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):
|
def test_operation_can_transfer_workbench_account_to_collab(db):
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.31"
|
version = "0.4.32"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "alembic" },
|
{ name = "alembic" },
|
||||||
|
|||||||
@@ -383,10 +383,12 @@ def import_workbench_accounts_by_text(
|
|||||||
"""按 UID/用户名/角色批量解析账号并加入当前用户工作台。"""
|
"""按 UID/用户名/角色批量解析账号并加入当前用户工作台。"""
|
||||||
|
|
||||||
_require_weibo_perm(current, "weibo:workbench")
|
_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(
|
raise HTTPException(
|
||||||
status_code=403,
|
status_code=403,
|
||||||
detail="仅超级管理员可以强制转入其他人的工作台账号",
|
detail="没有强制转入他人工作台账号的权限(需要 weibo:assign:force)",
|
||||||
)
|
)
|
||||||
identifiers: list[str] = []
|
identifiers: list[str] = []
|
||||||
for token in re.split(r"[\s,,;;]+", req.text.strip()):
|
for token in re.split(r"[\s,,;;]+", req.text.strip()):
|
||||||
|
|||||||
@@ -195,9 +195,8 @@ export default function WeiboAccountsPage({
|
|||||||
mode?: WeiboAccountsPageMode;
|
mode?: WeiboAccountsPageMode;
|
||||||
}) {
|
}) {
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { can, user } = usePermissions();
|
const { can } = usePermissions();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isSuperAdmin = user?.role === 'super_admin';
|
|
||||||
const isWorkbench = mode === 'workbench';
|
const isWorkbench = mode === 'workbench';
|
||||||
const canImport = can('weibo:import');
|
const canImport = can('weibo:import');
|
||||||
const canManage = can('weibo:manage');
|
const canManage = can('weibo:manage');
|
||||||
@@ -208,6 +207,8 @@ export default function WeiboAccountsPage({
|
|||||||
const canDelete = can('weibo:delete');
|
const canDelete = can('weibo:delete');
|
||||||
const canAssign = can('weibo:assign');
|
const canAssign = can('weibo:assign');
|
||||||
const canForceUpdateCk = can('weibo:assign:force');
|
const canForceUpdateCk = can('weibo:assign:force');
|
||||||
|
// 强制转入他人工作台与强制改归属共用同一个权限点:超管 + 运营有,客服没有。
|
||||||
|
const canForceAddOccupied = canForceUpdateCk;
|
||||||
const canTransferCollab = can('weibo:workbench');
|
const canTransferCollab = can('weibo:workbench');
|
||||||
|
|
||||||
const [items, setItems] = useState<WeiboAccountItem[]>([]);
|
const [items, setItems] = useState<WeiboAccountItem[]>([]);
|
||||||
@@ -513,7 +514,7 @@ export default function WeiboAccountsPage({
|
|||||||
setPoolSelectedIds([]);
|
setPoolSelectedIds([]);
|
||||||
setWorkbenchImportTab('paste');
|
setWorkbenchImportTab('paste');
|
||||||
setBatchImportText('');
|
setBatchImportText('');
|
||||||
setForceAddOccupied(isSuperAdmin);
|
setForceAddOccupied(canForceAddOccupied);
|
||||||
setBatchImportResult(null);
|
setBatchImportResult(null);
|
||||||
setPoolOpen(true);
|
setPoolOpen(true);
|
||||||
void loadWorkbenchPool(1, poolPageSize, '');
|
void loadWorkbenchPool(1, poolPageSize, '');
|
||||||
@@ -530,7 +531,7 @@ export default function WeiboAccountsPage({
|
|||||||
try {
|
try {
|
||||||
const result = await weiboApi.batchImportWorkbenchAccounts(
|
const result = await weiboApi.batchImportWorkbenchAccounts(
|
||||||
text,
|
text,
|
||||||
isSuperAdmin && forceAddOccupied,
|
canForceAddOccupied && forceAddOccupied,
|
||||||
);
|
);
|
||||||
const refreshResult = await refreshImportedAccounts(
|
const refreshResult = await refreshImportedAccounts(
|
||||||
result.items
|
result.items
|
||||||
@@ -3025,7 +3026,7 @@ export default function WeiboAccountsPage({
|
|||||||
title="支持多行、空格、逗号分隔"
|
title="支持多行、空格、逗号分隔"
|
||||||
description="优先按 UID 精确匹配;也支持微博用户名和角色名。重名时请改用 UID。导入成功后会立即刷新角色绑定和微豆余额。"
|
description="优先按 UID 精确匹配;也支持微博用户名和角色名。重名时请改用 UID。导入成功后会立即刷新角色绑定和微豆余额。"
|
||||||
/>
|
/>
|
||||||
{isSuperAdmin && (
|
{canForceAddOccupied && (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={forceAddOccupied}
|
checked={forceAddOccupied}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user