From 5d6325d74ced5f8ada8dcaf0db2673093402c475 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Sun, 8 Nov 2026 15:02:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(weibo):=20=E5=A2=9E=E5=8A=A0=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E9=BB=98=E8=AE=A4=E6=93=8D=E4=BD=9C=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_weibo_accounts.py | 33 ++++++++++++++++++++++++++++++++- web/backend/permissions.py | 9 +++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/test_weibo_accounts.py b/tests/test_weibo_accounts.py index 2534c5d..d82d5f3 100644 --- a/tests/test_weibo_accounts.py +++ b/tests/test_weibo_accounts.py @@ -19,6 +19,7 @@ from core.weibo import ( WeiboRechargeOrder, ) from web.backend.models import AuditLog, User, WeiboAccount +from web.backend.permissions import ROLE_PERMISSIONS from web.backend.routers import weibo as weibo_router from web.backend.routers.weibo import ( copy_account_ck, @@ -256,8 +257,20 @@ def test_copy_account_ck_uses_export_permission_defaults(db, current_user): db.add(support) db.commit() + support_result = copy_account_ck(account_out.id, db=db, current=support) + assert support_result.ck_text == "SCF=a; SUB=b" + + denied = User( + username="weibo-copy-denied", + password_hash="hash", + role="support", + custom_permissions=[], + is_active=True, + ) + db.add(denied) + db.commit() with pytest.raises(HTTPException) as exc_info: - copy_account_ck(account_out.id, db=db, current=support) + copy_account_ck(account_out.id, db=db, current=denied) assert exc_info.value.status_code == 403 @@ -273,6 +286,24 @@ def test_copy_account_ck_uses_export_permission_defaults(db, current_user): assert result.ck_text == "SCF=a; SUB=b" +def test_support_role_has_weibo_operation_permissions_without_delete(): + support = set(ROLE_PERMISSIONS["support"]) + + assert { + "weibo:view", + "weibo:import", + "weibo:manage", + "weibo:account:ck_export", + "weibo:bind", + "weibo:recharge", + "weibo:exchange", + "weibo:collab:view", + "weibo:collab:edit", + } <= support + assert "weibo:delete" not in support + assert "weibo:collab:manage" not in support + + def test_list_accounts_returns_parallel_page_shape(db, current_user): assert ( import_cookies( diff --git a/web/backend/permissions.py b/web/backend/permissions.py index 25ee4ad..4f36d0f 100644 --- a/web/backend/permissions.py +++ b/web/backend/permissions.py @@ -159,6 +159,15 @@ ROLE_PERMISSIONS = { "douyu:collab:edit", "yyb:session", "yyb:history", + "weibo:view", + "weibo:import", + "weibo:manage", + "weibo:account:ck_export", + "weibo:bind", + "weibo:recharge", + "weibo:exchange", + "weibo:collab:view", + "weibo:collab:edit", "huya:view_assigned", "huya:tag", "huya:task",