Default per-user main.py; invite-only by default
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import Cookie, Depends, Header, HTTPException, Query
|
||||
@@ -11,6 +10,7 @@ from editor_app.db.session import get_db
|
||||
from editor_app.db.models import User
|
||||
from editor_app import config
|
||||
from editor_app.services import accounts
|
||||
from editor_app.services import user_workspace
|
||||
|
||||
|
||||
def api_key_valid(authorization: str | None) -> bool:
|
||||
@@ -66,13 +66,8 @@ async def require_superuser(
|
||||
return user
|
||||
|
||||
|
||||
def _safe_workspace_leaf(user: User) -> str:
|
||||
base = re.sub(r"[^a-zA-Z0-9._-]+", "-", user.username).strip("-").lower() or "user"
|
||||
return f"{base}-{user.id}"
|
||||
|
||||
|
||||
def _seed_user_workspace(user_root: Path) -> None:
|
||||
(user_root / "code").mkdir(parents=True, exist_ok=True)
|
||||
user_workspace.ensure_default_code_main(user_root)
|
||||
|
||||
|
||||
async def get_workspace_root(
|
||||
@@ -91,6 +86,6 @@ async def get_workspace_root(
|
||||
if lookup is None:
|
||||
raise HTTPException(status_code=404, detail="Workspace user not found")
|
||||
target_user = lookup
|
||||
user_root = root / "users" / _safe_workspace_leaf(target_user)
|
||||
user_root = user_workspace.user_workspace_root(target_user.id, target_user.username, workspace_root=root)
|
||||
_seed_user_workspace(user_root)
|
||||
return user_root
|
||||
|
||||
Reference in New Issue
Block a user