feat(slice4): Owner-gated collection migrate endpoint (§22.4a PUC-5)
POST .../collections/{cid}/migrate — now safe to ship since all write paths
are sidecar-aware. Idempotent, one commit per collection.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -84,4 +84,29 @@ def make_router(config: Config, gitea: Gitea, bot: Bot) -> APIRouter:
|
||||
"meta": metadata_mod.metadata_dict(new_entry),
|
||||
}
|
||||
|
||||
@router.post("/api/projects/{project_id}/collections/{collection_id}/migrate")
|
||||
async def migrate(
|
||||
project_id: str, collection_id: str, request: Request
|
||||
) -> dict[str, Any]:
|
||||
"""§22.4a PUC-5: migrate a collection's legacy-frontmatter entries to
|
||||
clean body-only `.md` + sidecars, one commit per collection. Owner-gated
|
||||
operator action. Safe to ship now that every entry write path is
|
||||
sidecar-aware (SLICE-4 carried work). Idempotent."""
|
||||
viewer = auth.current_user(request)
|
||||
if collections_mod.project_of_collection(collection_id) != project_id:
|
||||
raise HTTPException(404, "Collection not in project")
|
||||
if not auth.is_collection_superuser(viewer, collection_id):
|
||||
raise HTTPException(403, "Owner access required to migrate a collection")
|
||||
org, repo = _content_repo()
|
||||
subfolder = collections_mod.subfolder_of(collection_id) or ""
|
||||
try:
|
||||
result = await metadata_mod.migrate_collection(
|
||||
gitea, org=org, repo=repo, subfolder=subfolder,
|
||||
actor=viewer.as_actor())
|
||||
except GiteaError as e:
|
||||
raise HTTPException(502, f"Gitea: {e.detail}")
|
||||
if result["committed"]:
|
||||
await cache.refresh_meta_repo(config, gitea)
|
||||
return result
|
||||
|
||||
return router
|
||||
|
||||
Reference in New Issue
Block a user