feat(weibo): 拆分账号管理与个人工作台

This commit is contained in:
yml2213
2026-11-08 16:26:53 +08:00
parent 5d6325d74c
commit d566518478
13 changed files with 1307 additions and 93 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ TESTS_DIR = Path(__file__).resolve().parent
PROJECT_ROOT = TESTS_DIR.parent
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
HEAD_REVISION = "20261108_0071"
HEAD_REVISION = "20261108_0072"
# 迁移新增、但不声明在模型里的复合查询索引。
EXTRA_INDEXES = (
+106 -1
View File
@@ -18,10 +18,12 @@ from core.weibo import (
WeiboRechargeError,
WeiboRechargeOrder,
)
from web.backend.models import AuditLog, User, WeiboAccount
from web.backend.models import AuditLog, User, WeiboAccount, WeiboWorkbenchAccount
from web.backend.permissions import ROLE_PERMISSIONS
from web.backend.routers import weibo as weibo_router
from web.backend.routers.weibo import (
add_workbench_accounts,
batch_tag_accounts,
copy_account_ck,
create_bind_qrcodes,
disable_account,
@@ -29,16 +31,21 @@ from web.backend.routers.weibo import (
get_account,
import_cookies,
list_accounts,
list_workbench_accounts,
list_workbench_pool,
refresh_account,
remove_workbench_accounts,
update_account,
)
from web.backend.schemas import (
WeiboAccountBatchTagRequest,
WeiboAccountDisableRequest,
WeiboAccountUpdate,
WeiboCookieImport,
WeiboExchangeRequest,
WeiboPaymentStatusRequest,
WeiboRechargeRequest,
WeiboWorkbenchAccountsRequest,
)
from web.backend.services import weibo_service
@@ -291,6 +298,7 @@ def test_support_role_has_weibo_operation_permissions_without_delete():
assert {
"weibo:view",
"weibo:workbench",
"weibo:import",
"weibo:manage",
"weibo:account:ck_export",
@@ -304,6 +312,103 @@ def test_support_role_has_weibo_operation_permissions_without_delete():
assert "weibo:collab:manage" not in support
def test_weibo_workbench_is_isolated_per_user(db, current_user):
first = WeiboAccount(
uid="4014000101",
nickname="工作台账号A",
cookie="SCF=a; SUB=first",
tag="A",
)
second = WeiboAccount(
uid="4014000102",
nickname="工作台账号B",
cookie="SCF=b; SUB=second",
tag="B",
)
db.add_all([first, second])
db.commit()
user_a = User(
username="weibo-workbench-a",
password_hash="hash",
role="support",
is_active=True,
)
user_b = User(
username="weibo-workbench-b",
password_hash="hash",
role="support",
is_active=True,
)
db.add_all([user_a, user_b])
db.commit()
add_workbench_accounts(
WeiboWorkbenchAccountsRequest(account_ids=[first.id]),
db=db,
current=user_a,
)
add_workbench_accounts(
WeiboWorkbenchAccountsRequest(account_ids=[second.id]),
db=db,
current=user_b,
)
page_a = list_workbench_accounts(page=1, page_size=20, db=db, current=user_a)
page_b = list_workbench_accounts(page=1, page_size=20, db=db, current=user_b)
assert [item.uid for item in page_a["items"]] == [first.uid]
assert [item.uid for item in page_b["items"]] == [second.uid]
assert db.query(WeiboWorkbenchAccount).count() == 2
pool_a = list_workbench_pool(page=1, page_size=20, db=db, current=user_a)
assert [item.uid for item in pool_a["items"]] == [second.uid]
remove_workbench_accounts(
WeiboWorkbenchAccountsRequest(account_ids=[first.id]),
db=db,
current=user_a,
)
assert (
list_workbench_accounts(page=1, page_size=20, db=db, current=user_a)["total"]
== 0
)
assert (
list_workbench_accounts(page=1, page_size=20, db=db, current=user_b)["total"]
== 1
)
def test_batch_tag_updates_selected_accounts(db, current_user):
first = WeiboAccount(
uid="4014000201",
nickname="批量标签A",
cookie="SCF=a; SUB=first",
tag="旧A",
)
second = WeiboAccount(
uid="4014000202",
nickname="批量标签B",
cookie="SCF=b; SUB=second",
tag="旧B",
)
db.add_all([first, second])
db.commit()
result = batch_tag_accounts(
WeiboAccountBatchTagRequest(ids=[first.id, second.id], tag="客服组"),
db=db,
current=current_user,
)
assert result["updated"] == 2
tags = {
account.id: account.tag
for account in db.query(WeiboAccount)
.filter(WeiboAccount.id.in_([first.id, second.id]))
.all()
}
assert tags == {first.id: "客服组", second.id: "客服组"}
def test_list_accounts_returns_parallel_page_shape(db, current_user):
assert (
import_cookies(