feat: expose filtered UI actions
这个提交存在于:
父节点
9d59920e4f
当前提交
6926d3cfda
共有 7 个文件被更改,包括 38 次插入 和 4 次删除
|
|
@ -24,6 +24,7 @@ class RouteSpec:
|
|||
|
||||
ROUTES: tuple[RouteSpec, ...] = (
|
||||
RouteSpec("GET", "ui/bootstrap", "backend.routes.ui_routes.get_ui_bootstrap", "read"),
|
||||
RouteSpec("GET", "ui/actions", "backend.routes.ui_routes.get_ui_actions", "read"),
|
||||
RouteSpec("GET", "dashboard/summary", "backend.routes.dashboard_routes.get_dashboard_summary", "read"),
|
||||
RouteSpec("GET", "profiles", "backend.routes.profile_routes.list_profiles", "read"),
|
||||
RouteSpec("POST", "profiles", "backend.routes.profile_routes.create_profile", "write"),
|
||||
|
|
|
|||
|
|
@ -16,3 +16,13 @@ def get_ui_bootstrap(ctx: RequestContext, service: UiService | None = None) -> d
|
|||
return ui_service.get_bootstrap(ctx)
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def get_ui_actions(ctx: RequestContext, service: UiService | None = None) -> dict:
|
||||
ui_service = service or UiService()
|
||||
|
||||
def action() -> list[dict]:
|
||||
require_authenticated(ctx)
|
||||
return ui_service.get_actions(ctx)
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
|
||||
from core.config_service import ConfigService
|
||||
from core.identity import RequestContext
|
||||
from core.interactions import build_default_actions, filter_actions_for_permissions
|
||||
|
||||
|
||||
API_BASE = "/api/v1/plugins/extensions/astrbot_plugin_imagestudio"
|
||||
|
|
@ -30,3 +31,7 @@ class UiService:
|
|||
"feature_flags": config.feature_flags(),
|
||||
"api_base": API_BASE,
|
||||
}
|
||||
|
||||
def get_actions(self, ctx: RequestContext) -> list[dict]:
|
||||
actions = build_default_actions(api_base=API_BASE)
|
||||
return [action.to_dict() for action in filter_actions_for_permissions(actions, ctx.permissions)]
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ class InteractionAction:
|
|||
def build_default_actions(*, api_base: str = "") -> list[InteractionAction]:
|
||||
return [
|
||||
InteractionAction("open_workbench", "Workbench", "open_workbench", {"url": f"{api_base}/web"}),
|
||||
InteractionAction("quick_profile", "Quick profile", "quick_profile", requires_permission="write"),
|
||||
InteractionAction("quick_profile", "Quick profile", "quick_profile", requires_permission="can_write"),
|
||||
InteractionAction("open_logs", "Logs", "open_logs", {"view": "logs"}),
|
||||
InteractionAction("open_settings", "Settings", "open_settings", {"view": "settings"}, "config"),
|
||||
InteractionAction("open_settings", "Settings", "open_settings", {"view": "settings"}, "can_manage_config"),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class InteractionTests(unittest.TestCase):
|
|||
self.assertEqual(action.action_type, "open_logs")
|
||||
|
||||
actions = build_default_actions(api_base="/api/plugin")
|
||||
filtered = filter_actions_for_permissions(actions, {"write"})
|
||||
filtered = filter_actions_for_permissions(actions, {"can_write"})
|
||||
self.assertIn("quick_profile", [item.action_id for item in filtered])
|
||||
self.assertNotIn("open_settings", [item.action_id for item in filtered])
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
keys = {(route["method"], route["endpoint"]) for route in routes}
|
||||
|
||||
self.assertIn(("GET", "ui/bootstrap"), keys)
|
||||
self.assertIn(("GET", "ui/actions"), keys)
|
||||
self.assertIn(("POST", "nodes/{node_id}/generate"), keys)
|
||||
self.assertIn(("GET", "security/audit-logs"), keys)
|
||||
self.assertIn(("POST", "api-discovery/probe-provider"), keys)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ from backend.routes.settings_routes import (
|
|||
validate_settings,
|
||||
)
|
||||
from backend.routes.storage_routes import get_storage_status
|
||||
from backend.routes.ui_routes import get_ui_bootstrap
|
||||
from backend.routes.ui_routes import get_ui_actions, get_ui_bootstrap
|
||||
from backend.routes.web_routes import get_web_manifest
|
||||
from backend.routes.workflow_routes import (
|
||||
archive_workflow,
|
||||
|
|
@ -180,6 +180,23 @@ storage:
|
|||
"/api/v1/plugins/extensions/astrbot_plugin_imagestudio",
|
||||
)
|
||||
|
||||
def test_ui_actions_are_filtered_by_permissions(self):
|
||||
response = get_ui_actions(self.ctx, UiService(self.config_service))
|
||||
|
||||
self.assertTrue(response["ok"])
|
||||
action_ids = [item["action_id"] for item in response["data"]]
|
||||
self.assertIn("open_workbench", action_ids)
|
||||
self.assertIn("quick_profile", action_ids)
|
||||
self.assertIn("open_settings", action_ids)
|
||||
|
||||
read_only = RequestContext.from_astrbot(username="viewer", user_id="viewer_001")
|
||||
read_only_response = get_ui_actions(read_only, UiService(self.config_service))
|
||||
self.assertTrue(read_only_response["ok"])
|
||||
read_only_action_ids = [item["action_id"] for item in read_only_response["data"]]
|
||||
self.assertIn("open_logs", read_only_action_ids)
|
||||
self.assertNotIn("quick_profile", read_only_action_ids)
|
||||
self.assertNotIn("open_settings", read_only_action_ids)
|
||||
|
||||
def test_ui_bootstrap_requires_authentication(self):
|
||||
anonymous = RequestContext()
|
||||
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用