k0880k commited on
Commit
ec5cbb5
·
1 Parent(s): 6c9b9c1

fix(postmeet): accept URL imports before publish permission

Browse files
Files changed (1) hide show
  1. editor/postmeet_routes.py +86 -0
editor/postmeet_routes.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PostMeet route seam for the mounted Site Editor.
2
+
3
+ Importing/transcribing a recording is a read/evidence operation. It must not be
4
+ blocked by Joomla page-creation permission; creation is checked only when the
5
+ operator explicitly publishes the verified result.
6
+
7
+ This module also exposes a tiny unauthenticated contract marker under the mounted
8
+ editor. It contains no site/session data and exists so a deployed runtime can be
9
+ proven to contain the URL-capable PostMeet contract instead of mistaking an old
10
+ still-running Space for the newly built image.
11
+ """
12
+ from __future__ import annotations
13
+
14
+ from typing import Any
15
+
16
+ from fastapi import Cookie, HTTPException
17
+
18
+ CONTRACT = "postmeet-source-agnostic/v2"
19
+
20
+
21
+ def _drop_postmeet_post(app) -> None:
22
+ """Remove only the old POST /api/postmeet route; keep status/publish routes."""
23
+ kept = []
24
+ for route in app.router.routes:
25
+ methods = set(getattr(route, "methods", set()) or set())
26
+ if getattr(route, "path", "") == "/api/postmeet" and "POST" in methods:
27
+ continue
28
+ kept.append(route)
29
+ app.router.routes[:] = kept
30
+
31
+
32
+ def accept_import(editor: Any, body: Any, fx: str | None):
33
+ """Accept source work under a real site session without creating Joomla data."""
34
+ # Auth/site scope is still mandatory. Creation permission is deliberately not:
35
+ # no Joomla article/menu/category is created by this operation.
36
+ editor._sess(fx)
37
+
38
+ source = str(getattr(body, "video_url", "") or "").strip()
39
+ if not source:
40
+ raise HTTPException(422, "A meeting recording URL or site-media path is required.")
41
+
42
+ from core import capability_fq
43
+
44
+ try:
45
+ return capability_fq.call(
46
+ editor.postmeet_capability.CAPABILITY_ID,
47
+ "capability.execute",
48
+ action="meeting.import",
49
+ target=source,
50
+ input={"title": str(getattr(body, "title", "") or "")},
51
+ context={
52
+ "site_url": editor.mesh.env().get("JOOMLA_URL", ""),
53
+ "site": editor.mesh.CURRENT.get() or "",
54
+ },
55
+ )
56
+ except ValueError as exc:
57
+ raise HTTPException(422, str(exc)) from exc
58
+
59
+
60
+ def install(app, editor: Any) -> None:
61
+ """Install the corrected import route once on the mounted editor app."""
62
+ if getattr(app.state, "postmeet_url_contract", "") == CONTRACT:
63
+ return
64
+
65
+ _drop_postmeet_post(app)
66
+
67
+ @app.post("/api/postmeet")
68
+ def api_postmeet_source_agnostic(body: editor.PostMeetImport, fx: str = Cookie(None)):
69
+ return accept_import(editor, body, fx)
70
+
71
+ @app.get("/runtime-contract", include_in_schema=False)
72
+ def runtime_contract():
73
+ return {
74
+ "ok": True,
75
+ "postmeet": CONTRACT,
76
+ "accepts": [
77
+ "site media path",
78
+ "direct media URL",
79
+ "YouTube/Vimeo/Drive/platform URL",
80
+ "generic page containing discoverable media",
81
+ ],
82
+ "import_writes_joomla": False,
83
+ "publish_requires_create": True,
84
+ }
85
+
86
+ app.state.postmeet_url_contract = CONTRACT