Files
model-platform/.env.example
T
tao.chenandClaude b493907775 feat(scripts): 跨 owner 懒加载目录树 + 跨用户可见 workspace/public
修两个后端接口问题:
1) /api/v1/workspace-directories 返回为空,目录树结构消失
2) 同 workspace 内脚本/数据互相可见但默认排除 private

后端改动
--------
* list_scripts / list_resources / list_workspace_directories 新增
  owner_user_id 可选 query 参数;缺省 = 当前请求者本人(scope 到
  workspace/{me}/...),传值时 scope 到该 owner 的子树。前端根加载
  默认只见自己一级,其他成员以折叠分组呈现。
* visibility 过滤统一:非 admin 请求者只返回 owner==me 或
  visibility ∈ {workspace, public};admin 跳过。owner=me 含自己
  的 private,owner=other 只剩其 workspace/public,排除他人 private。
* create_workspace_directory 两个分支 visibility 默认 'public'
  (非 private),使跨 owner 目录树可见;响应新增 owner_user_id 字段。
* platform.list_members 鉴权从 system_admin_context 放宽为
  系统管理员或该 workspace 活跃成员(让普通用户也能渲染同
  workspace 成员名册,用于跨 owner 分组)。
* main.py 注册 platform 模块(随 list_members 改动补齐导入)。
* .env.example 同步 common/config.py 26 个字段。

前端改动
--------
* ScriptExplorer.memberScriptGroups 改由 members 列表播种分组,
  display_name 取 members.display_name;inferredDirectories 现在按
  owner_user_id 标记,统一跨 owner 目录渲染。删除脚本目录页头与
  树分组标题的工作副本数量角标。
* WorkspaceTree 新增 ownerUserId 透传到 store.toggleExpanded;
  仅"我"的分组 mount 时 auto-expand,他人分组默认折叠,展开才
  调 loadOwnerGroup / owner-scoped loadScripts / loadChildren。
* scriptWorkspaceStore 引入 namespaced cache key
  (ownerCacheKey = `${ownerUserId ?? me}:${path}`),loadedScriptPaths
  / loadedChildPaths / loadedOwnerGroups 全部按 owner 隔离;
  toggleExpanded 用 loadPath === undefined 区分 group 头与真实
  目录,修"他人子目录点击不触发接口"的 loadPath 前缀误判 bug。
* api.ts / AuthContext 透传 ownerUserId 给 listScripts /
  listResources / listWorkspaceDirectories。

文档
----
* API.md: §3.2 创建目录 visibility 默认 public + 响应加 owner_user_id;
  §3.3.1 GET directories 加 owner_user_id 参数 + 响应字段;
  §3.4 GET scripts 改写为 owner 作用域 + visibility 过滤语义;
  §五.1 GET data-resources 新增,同一套统一语义;
  §7 intro 例外 — GET members 对系统管理员或 workspace 活跃成员开放。
* DEVELOP.md: Code layout 重写以反映 backend api/services/clients/
  schemas 拆分 + schedule domain/scheduling/application/execution/
  infrastructure 拆分 + common 子包(auth/storage/backends);
  Configuration 系统补全 26 个 settings 字段;新增
  "Owner-scoping + visibility (cross-owner browsing)" 小节;
  Per-service dev 注释用 uv run 的源布局要求;Add a new DAG endpoint /
  storage bucket 路径改为 backend/src/backend/api/* 与 services/*。

测试
----
* test_list_scripts_parent_path.py /
  test_resources.py 补充 owner_user_id 参数化直接调用 + LIKE
  前缀断言(workspace/{owner}/... 前缀)。

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-21 19:26:53 +08:00

124 lines
5.6 KiB
Bash

COMPOSE_PROJECT_NAME=model-platform-develop
SCHEDULE_EVENT_NAMESPACE=model-platform-develop
# External port of the Nginx gateway. Only Nginx is exposed to the host
# (architecture §2.2); backend/runtime/schedule stay on the Docker internal
# network. Override here to expose Nginx on a different host port.
GATEWAY_PORT=8890
# External MySQL. URL-encode reserved characters in DATABASE_URL.
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=change-me
MYSQL_DATABASE=model_platform
DATABASE_URL=mysql+asyncmy://root:change-me@127.0.0.1:3306/model_platform?charset=utf8mb4
JWT_SECRET=change-this-development-secret
# Force the Secure flag on the session cookie even when the inbound request
# scheme is plain HTTP. Enable behind a TLS-terminating reverse proxy that
# strips/rewrites X-Forwarded-Proto — otherwise the cookie is written without
# Secure and browsers refuse to send it back over HTTPS.
COOKIE_FORCE_SECURE=false
# Service label surfaced in lifespan / health checks.
SERVICE_NAME=service
# ============================================================================
# CRITICAL: must set BEFORE first run. The initial admin user is seeded by
# the deployment bootstrap. Never keep the development default in production.
# ============================================================================
INITIAL_ADMIN_PASSWORD=admin12345
# Backend loguru stderr sink level. One of DEBUG / INFO / WARNING / ERROR
# / CRITICAL. Anything else (e.g. lowercase) falls back to INFO inside
# configure_logging(). Change to DEBUG to see request bodies in
# runtime_client._jupyter_request.
LOG_LEVEL=INFO
# Audit log (backend HTTP interface compliance log). One line per HTTP
# request, written to data/logs/audit/audit-YYYY-MM-DD.log (one file per
# day). AUDIT_LOG_DIR is relative to the backend process cwd (/app in the
# container). AUDIT_LOG_RETENTION_DAYS=0 disables cleanup of old files.
AUDIT_LOG_DIR=
AUDIT_LOG_RETENTION_DAYS=30
# Exact paths excluded from the audit line (health/root probes carry no
# business value but fire every second from K8s/LB). The default already
# covers /health/live /health/ready /api/v1/health / /health/storage;
# leave empty to keep the default. Comma-separated, e.g. /health/live,/api/v1/health.
AUDIT_EXCLUDED_PATHS=
# Object storage. Two modes are supported:
# STORAGE_BACKEND=s3 — connects to an S3-compatible service (MinIO,
# RustFS, SeaweedFS, AWS S3, …). Requires the
# S3_* block below.
# STORAGE_BACKEND=local — stores objects on the local filesystem under
# LOCAL_STORAGE_BASE_DIR. Backend and runtime
# share this directory via a Docker volume
# (docker-compose.yml mounts `local-storage`).
# Useful for dev, single-node, air-gapped.
STORAGE_BACKEND=s3
LOCAL_STORAGE_BASE_DIR=/data
# Object storage (S3-compatible). Only used when STORAGE_BACKEND=s3.
# S3_ENDPOINT is the single upstream URL consumed by all 4 services:
# - nginx (via scripts/nginx-entrypoint.sh, which parses host + port)
# - backend / runtime / schedule (passed through to boto3 / rclone)
# S3_ACCESS_KEY / S3_SECRET_KEY are read by Python code in
# backend/ and schedule/ (boto3 credentials).
#
# S3 buckets are purpose-named:
# S3_WORKSPACE_BUCKET — workspace files (notebooks, scripts, working
# copies); layout is ``s3://<bucket>/<workspace_id>/...``.
# S3_VERSION_BUCKET — immutable script-version artifacts.
# S3_RUN_LOG_BUCKET — schedule run logs and execution results.
# S3_TRASH_BUCKET — soft-deleted objects; source bucket key is preserved
# as a prefix so restore is a same-key move.
S3_HOST=127.0.0.1
S3_PORT=9000
S3_ENDPOINT=http://127.0.0.1:9000
S3_ACCESS_KEY=change-me
S3_SECRET_KEY=change-me
S3_WORKSPACE_BUCKET=workspace
S3_VERSION_BUCKET=version
S3_RUN_LOG_BUCKET=run-log
S3_TRASH_BUCKET=trash
S3_TRASH_RETENTION_DAYS=30
# rclone RC (HTTP control API). The runtime container starts rclone with
# `--rc --rc-addr 0.0.0.0:5572 --rc-no-auth` (see runtime/src/runtime/mount.py),
# so the backend can POST /vfs/refresh here to invalidate the FUSE dir-cache
# after writing new workspace files. Default points at the runtime service
# over the compose network.
RCLONE_RC_URL=http://runtime:5572
# Backend → Runtime HTTP endpoint (Jupyter contents API, file ops).
RUNTIME_API_URL=http://runtime:8000
# Public base URL for the runtime container (surfaced to clients for
# Jupyter access tickets / embedded URLs).
PUBLIC_BASE_URL=http://runtime
# ============================================================================
# Service-to-service auth (P0-1 fix).
# Backend's /internal/v1/* storage control plane requires this shared secret.
# The schedule worker reads the same value and sends it as the
# ``X-Internal-Service-Token`` header. Value MUST match between backend and
# schedule. Generate a random 64-char string for any non-dev deployment:
# python -c "import secrets; print(secrets.token_urlsafe(48))"
# ============================================================================
INTERNAL_SERVICE_TOKEN=change-me-internal-service-token
# Schedule → Backend HTTP base URL (cron post-back / status callbacks).
BACKEND_API_URL=http://backend:8000
# Max concurrent notebooks running in the schedule worker. Each notebook is
# dispatched as an asyncio task bounded by a semaphore; the polling loop is
# never blocked.
SCHEDULE_EXECUTION_CONCURRENCY=4
# Readiness probe targets. Comma-separated host:port list checked by
# /health/ready; empty disables the check. e.g. mysql:3306,s3:9000
READINESS_TARGETS=