feat(weibo): 支持管理员强制更新占用账号 CK

This commit is contained in:
yml
2026-11-14 14:46:38 +08:00
parent b4801336c5
commit 17a2b5c464
7 changed files with 229 additions and 23 deletions
+77 -1
View File
@@ -302,11 +302,87 @@ def test_occupied_workbench_account_cannot_be_updated_by_another_user(db, curren
assert result.count == 0
assert len(result.errors) == 1
assert "其他人的工作台占用" in result.errors[0].message
assert "个人工作台排他槽位归 weibo-owner" in result.errors[0].message
assert result.errors[0].workbench_owner_id == owner.id
assert result.errors[0].workbench_owner_username == owner.username
db.refresh(imported)
assert imported.cookie == original_cookie
def test_super_admin_force_updates_occupied_ck_without_changing_owner(db, current_user):
imported_out = import_cookies(
WeiboCookieImport(text="SCF=a; SUB=owner"),
db=db,
current=current_user,
).accounts[0]
imported = db.query(WeiboAccount).filter(WeiboAccount.id == imported_out.id).one()
owner = User(
username="weibo-owner",
password_hash="hash",
role="support",
is_active=True,
)
db.add(owner)
db.commit()
imported.assigned_to = owner.id
db.add(
WeiboWorkbenchAccount(
user_id=owner.id,
account_id=imported.id,
exclusive_slot=1,
)
)
db.commit()
result = import_cookies(
WeiboCookieImport(
text="SCF=forced; SUB=fresh",
update_existing=True,
force_update=True,
),
db=db,
current=current_user,
)
assert result.count == 1
assert result.errors == []
db.refresh(imported)
assert "SUB=fresh" in imported.cookie
assert imported.assigned_to == owner.id
membership = (
db.query(WeiboWorkbenchAccount)
.filter(WeiboWorkbenchAccount.account_id == imported.id)
.one()
)
assert membership.user_id == owner.id
assert membership.exclusive_slot == 1
def test_force_update_requires_dedicated_permission(db):
user = User(
username="weibo-import-only",
password_hash="hash",
role="support",
is_active=True,
custom_permissions=["weibo:import"],
)
db.add(user)
db.commit()
with pytest.raises(HTTPException) as excinfo:
import_cookies(
WeiboCookieImport(
text="SCF=a; SUB=b",
update_existing=True,
force_update=True,
),
db=db,
current=user,
)
assert excinfo.value.status_code == 403
def test_refresh_marks_payment_access_failure(db, current_user):
account_out = import_cookies(
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),