§22 S5: in-app create-project + global-directory empty states (@S5 C3.1–C3.2)
Adds the global-Owner create-project action and the role-aware deployment directory, completing slice S5 of the three-tier refactor (release v0.44.0, minor/non-breaking — no migration). Per docs/design/2026-06-05-three-tier-projects-collections.md Part E (S5), Part C.3 (C3.1–C3.2). Backend: - auth.can_create_project — global-Owner gate (deployment owner/admin or an explicit scope_type='global' Owner grant). - bot.create_project — provision the Gitea content repo (seed README so main exists), read+append+commit projects.yaml in the registry repo, audit-log (create_project). The bot stays the only git writer (§1). - POST /api/projects (api_deployment) — global-Owner gated; validates the id (slug, not 'default'), name, type, visibility, content_repo; commits via the bot, then re-mirrors the registry so projects + default collection rows flow from git (§22.2). GET /api/deployment gains viewer.can_create_project and default_project_readable. make_router now takes gitea + bot. Frontend: - api.createProject; DeploymentProvider surfaces viewer + defaultProjectReadable + refresh; DeploymentLanding redirects into the default only when readable (gated/absent default falls through to the directory, no 404 bounce). - Directory.jsx role-aware empty states (C3.1 "Create your first project" CTA; C3.2 "Nothing has been shared with you yet") + Owner-only "New project" control + CreateProjectModal. Tests: backend test_create_project_vertical.py (vertical + gates + the deployment empty-state signals); frontend Directory.test.jsx empty-state cases. Also: ignore the session-local .superpowers/ tooling dir. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -198,6 +198,82 @@ class Bot:
|
||||
)
|
||||
return created
|
||||
|
||||
async def create_project(
|
||||
self,
|
||||
actor: Actor,
|
||||
*,
|
||||
org: str,
|
||||
registry_repo: str,
|
||||
content_repo: str,
|
||||
project_id: str,
|
||||
projects_yaml_new: str,
|
||||
projects_yaml_sha: str,
|
||||
readme_text: str,
|
||||
) -> dict:
|
||||
"""§22 S5 (§A.2): stand up a new project. A global-Owner action wrapping
|
||||
a bot write at two git sources:
|
||||
|
||||
1. **provision the content repo** — create `org/content_repo` if it
|
||||
doesn't exist, then seed a `README.md` on `main` so the branch
|
||||
exists (the contents API initialises the repo with that commit; the
|
||||
corpus mirror and the propose path both need a `main` to write to).
|
||||
2. **register the project** — commit the caller-composed
|
||||
`projects.yaml` (the existing doc with the new project appended) to
|
||||
the registry repo's `main`.
|
||||
|
||||
Like `create_collection`, this is a structural admin action committed
|
||||
straight to main (no PR), like the registry config it feeds; the caller
|
||||
then re-runs the registry mirror so the new `projects` + default
|
||||
`collections` rows flow from the registry (§22.2 keeps the registry the
|
||||
source of truth). Logs a `create_project` audit row for the §6.5 trail.
|
||||
Returns the registry update_file result (carries the new commit sha)."""
|
||||
ae = actor.email or f"{actor.gitea_login}@users.noreply"
|
||||
existing = await self._gitea.get_repo(org, content_repo)
|
||||
if existing is None:
|
||||
await self._gitea.create_org_repo(
|
||||
org, content_repo, description=f"Content repo for project {project_id}"
|
||||
)
|
||||
# Seed a README if absent, which also establishes `main` on a freshly
|
||||
# created (auto_init=False) repo — the contents API initialises the repo
|
||||
# with that commit. Keyed on the README rather than the branch so it is
|
||||
# idempotent and behaves identically whether the repo has a bare `main`
|
||||
# or no branch at all. Mirrors `ensure_rfc_repo_seed`'s empty-repo seed.
|
||||
readme = await self._gitea.get_contents(org, content_repo, "README.md", ref="main")
|
||||
if readme is None:
|
||||
await self._gitea.create_file(
|
||||
org,
|
||||
content_repo,
|
||||
"README.md",
|
||||
content=readme_text,
|
||||
message=_stamp_single(f"chore: initialise content repo for {project_id}", actor),
|
||||
branch="main",
|
||||
author_name=actor.display_name,
|
||||
author_email=ae,
|
||||
)
|
||||
result = await self._gitea.update_file(
|
||||
org,
|
||||
registry_repo,
|
||||
"projects.yaml",
|
||||
content=projects_yaml_new,
|
||||
sha=projects_yaml_sha,
|
||||
message=_stamp_single(f"chore: create project {project_id}", actor),
|
||||
branch="main",
|
||||
author_name=actor.display_name,
|
||||
author_email=ae,
|
||||
)
|
||||
commit_sha = (
|
||||
result.get("commit", {}).get("sha")
|
||||
or result.get("content", {}).get("sha")
|
||||
or ""
|
||||
)
|
||||
_log(
|
||||
actor,
|
||||
"create_project",
|
||||
bot_commit_sha=commit_sha,
|
||||
details={"project_id": project_id, "content_repo": content_repo},
|
||||
)
|
||||
return result
|
||||
|
||||
# ----- Meta repo: idea PRs (§9.1 / §9.2) -----
|
||||
|
||||
async def open_idea_pr(
|
||||
|
||||
Reference in New Issue
Block a user