fix(templates): persist workspace context so template pages actually save
Pages created via the page-template picker (weekly report, project doc, meeting notes, ...) previously got workspace_id=NULL and workspace=login, so they never appeared in the active local/Gitea workspace tree — they looked like they 'didn't save' even though the row existed. Frontend: _useTemplate now sends the active workspace context (workspace_id or workspace key), mirroring _createPlainPage. Backend: use_page_template resolves/validates the workspace and persists both workspace and workspace_id on the new page.
This commit is contained in:
@@ -283,6 +283,39 @@ def test_use_builtin_template_creates_page(client):
|
||||
cookies={"flowdeck_session": s}, headers={"X-CSRF-Token": c}).status_code == 404
|
||||
|
||||
|
||||
def test_use_template_persists_workspace_id(client):
|
||||
s, c, uid = _login(client)
|
||||
# Create a local workspace owned by this user
|
||||
r = client.post("/api/workspaces", json={"name": "Tpl WS"},
|
||||
cookies={"flowdeck_session": s}, headers={"X-CSRF-Token": c})
|
||||
assert r.status_code == 200
|
||||
ws_id = r.json()["id"]
|
||||
client.post(f"/api/workspaces/{ws_id}/select", cookies={"flowdeck_session": s})
|
||||
# built-in template use with workspace context
|
||||
r2 = client.post("/board/api/page-templates/0/use", json={"key": "meeting_notes", "workspace_id": ws_id},
|
||||
cookies={"flowdeck_session": s}, headers={"X-CSRF-Token": c})
|
||||
assert r2.status_code == 200
|
||||
pid = r2.json()["id"]
|
||||
page = client.get(f"/board/api/pages/{pid}").json()
|
||||
assert page["workspace_id"] == ws_id
|
||||
assert page["workspace"] == "Tpl WS"
|
||||
# user template use with workspace context
|
||||
r3 = client.post("/board/api/page-templates",
|
||||
json={"name": "Tpl WS template", "blocks": _blocks_b("ws body")},
|
||||
cookies={"flowdeck_session": s}, headers={"X-CSRF-Token": c})
|
||||
tid = r3.json()["id"]
|
||||
r4 = client.post(f"/board/api/page-templates/{tid}/use", json={"workspace_id": ws_id},
|
||||
cookies={"flowdeck_session": s}, headers={"X-CSRF-Token": c})
|
||||
assert r4.status_code == 200
|
||||
page2 = client.get(f"/board/api/pages/{r4.json()['id']}").json()
|
||||
assert page2["workspace_id"] == ws_id
|
||||
assert page2["workspace"] == "Tpl WS"
|
||||
# routing: template-created page must appear in the workspace tree
|
||||
tree = client.get("/api/local-workspace/tree", cookies={"flowdeck_session": s}).json()
|
||||
ids = [n["id"] for n in tree["tree"]]
|
||||
assert pid in ids
|
||||
|
||||
|
||||
def test_user_template_roundtrip(client):
|
||||
s, c, uid = _login(client)
|
||||
pid = _mk_page(client, s, "My Weekly", _blocks_b("body text"))
|
||||
|
||||
Reference in New Issue
Block a user