Default per-user main.py; invite-only by default
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
27
src/editor_app/services/user_workspace.py
Normal file
27
src/editor_app/services/user_workspace.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from editor_app import config
|
||||
|
||||
DEFAULT_MAIN_PY = 'print("Hello, World!")\n'
|
||||
|
||||
|
||||
def safe_workspace_leaf(username: str, user_id: int) -> str:
|
||||
base = re.sub(r"[^a-zA-Z0-9._-]+", "-", username.strip()).strip("-").lower() or "user"
|
||||
return f"{base}-{user_id}"
|
||||
|
||||
|
||||
def user_workspace_root(user_id: int, username: str, workspace_root: Path | None = None) -> Path:
|
||||
root = (workspace_root or config.WORKSPACE_ROOT).resolve()
|
||||
return root / "users" / safe_workspace_leaf(username, user_id)
|
||||
|
||||
|
||||
def ensure_default_code_main(user_root: Path) -> None:
|
||||
"""Ensure code/ exists and add a starter main.py when missing."""
|
||||
code_dir = user_root / "code"
|
||||
code_dir.mkdir(parents=True, exist_ok=True)
|
||||
main_py = code_dir / "main.py"
|
||||
if not main_py.exists():
|
||||
main_py.write_text(DEFAULT_MAIN_PY, encoding="utf-8")
|
||||
Reference in New Issue
Block a user