feat(weibo): 支持工作台账号转入外部单协作

This commit is contained in:
yml
2026-11-11 20:32:42 +08:00
parent 50bb829101
commit 3f860c3272
8 changed files with 237 additions and 3 deletions
+74
View File
@@ -41,6 +41,7 @@ from web.backend.routers.weibo import (
list_workbench_tags,
refresh_account,
remove_workbench_accounts,
transfer_workbench_to_collab,
update_account,
)
from web.backend.schemas import (
@@ -54,6 +55,7 @@ from web.backend.schemas import (
WeiboRechargeRequest,
WeiboWorkbenchAccountsRequest,
WeiboWorkbenchBatchImportRequest,
WeiboWorkbenchTransferToCollabRequest,
)
from web.backend.services import weibo_service
@@ -564,6 +566,78 @@ def test_batch_import_workbench_accounts_reports_each_identifier(db, current_use
assert workbench_ids == {existing.id, added.id}
def test_operation_can_transfer_workbench_account_to_collab(db):
operator = User(
username="weibo-transfer-operator",
password_hash="hash",
role="operation",
is_active=True,
)
db.add(operator)
db.commit()
account = WeiboAccount(
uid="4014000951",
nickname="转入协作运营账号",
cookie="SCF=a; SUB=transfer",
game_role_name="测试角色",
assigned_to=operator.id,
)
db.add(account)
db.commit()
db.add(
WeiboWorkbenchAccount(
user_id=operator.id,
account_id=account.id,
)
)
db.commit()
result = transfer_workbench_to_collab(
WeiboWorkbenchTransferToCollabRequest(account_id=account.id),
db=db,
current=operator,
).model_dump()
assert result == {
"success": True,
"account_id": account.id,
"uid": account.uid,
"nickname": account.nickname,
"game_role_name": "测试角色",
}
assert (
db.query(WeiboWorkbenchAccount)
.filter(WeiboWorkbenchAccount.account_id == account.id)
.count()
== 0
)
audit = (
db.query(AuditLog)
.filter(AuditLog.action == "weibo:workbench:transfer_collab")
.one()
)
assert audit.target == f"weibo_account:{account.id}"
def test_transfer_to_collab_requires_account_in_current_workbench(db, current_user):
account = WeiboAccount(
uid="4014000952",
nickname="不在工作台",
cookie="SCF=a; SUB=not-member",
)
db.add(account)
db.commit()
with pytest.raises(HTTPException) as excinfo:
transfer_workbench_to_collab(
WeiboWorkbenchTransferToCollabRequest(account_id=account.id),
db=db,
current=current_user,
)
assert excinfo.value.status_code == 404
def test_batch_tag_updates_selected_accounts(db, current_user):
first = WeiboAccount(
uid="4014000201",