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:
yml
2026-12-03 14:29:21 +08:00
parent 1d77ae6eff
commit 36a4658e0e
7 changed files with 68 additions and 15 deletions
+52 -3
View File
@@ -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):