Duplicate flows and dashboards: POST /flows/{name}/duplicate and /dashboards/{name}/duplicate copy the working copy into {name}_copy (then _copy_2, ...) as an unpublished draft with " (copy)" on the title. A flow copy takes its node sources as drafts and leaves origin and runtime.json behind; copying code nodes is a superuser's (the save check, now taking the replaced copy). Client regenerated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 09:21:30 +02:00
co-authored by Claude Opus 5.5
parent 8b1a456cd3
commit 8a868e0f26
9 changed files with 215 additions and 9 deletions
+12
View File
@@ -201,6 +201,18 @@ async def delete_dashboard(
return Message(message=f"Deleted dashboard '{name}'")
@router.post("/{name}/duplicate", response_model=DashboardDef)
async def duplicate_dashboard(name: str, store: DashboardStoreDep) -> Any:
"""Copy a dashboard into a new one that is only a draft, named after it.
No history limits to apply, as for a new dashboard: nothing published moved.
"""
try:
return await run_in_threadpool(store.duplicate, name)
except DashboardNotFound:
raise HTTPException(status_code=404, detail=f"No dashboard named '{name}'")
@router.post("/{name}/rename", response_model=DashboardDef)
async def rename_dashboard(
name: str, body: RenameRequest, store: DashboardStoreDep
+23 -7
View File
@@ -480,15 +480,12 @@ def _changes_code(node: NodeDef, old: NodeDef | None) -> bool:
)
def _refuse_code_changes(
controller: FlowController, name: str, definition: FlowDef
) -> None:
def _refuse_code_changes(definition: FlowDef, before: FlowDef | None) -> None:
"""Refuse a non-superuser a change to code this flow would run.
Wiring, titles, a function node's settings and every other node stay
anyone's.
*before* is the working copy being replaced, None for a new flow. Wiring,
titles, a function node's settings and every other node stay anyone's.
"""
before = _read_flow(controller, name) if controller.store.exists(name) else None
previous = {node.id: node for node in before.nodes} if before else {}
for node in definition.nodes:
if _changes_code(node, previous.get(node.id)):
@@ -524,7 +521,8 @@ async def save_flow(
_check_flavors(definition)
_check_origin(definition)
if not user.is_superuser:
_refuse_code_changes(controller, name, definition)
before = _read_flow(controller, name) if controller.store.exists(name) else None
_refuse_code_changes(definition, before)
try:
stored = await run_in_threadpool(
@@ -648,6 +646,24 @@ async def rename_flow(
return _detail(controller, renamed)
@router.post("/{name}/duplicate", response_model=FlowDetail)
async def duplicate_flow(
name: str, controller: FlowControllerDep, user: CurrentUser
) -> Any:
"""Copy a flow into a new one that is only a draft, named after it.
Nothing to reload: a draft does not run. Its code nodes are new code in
the copy, so copying them is a superuser's, like writing them.
"""
if not user.is_superuser:
_refuse_code_changes(_read_flow(controller, name), None)
try:
copy = await run_in_threadpool(controller.store.duplicate_flow, name)
except FlowNotFound:
raise HTTPException(status_code=404, detail=f"No flow named '{name}'")
return _detail(controller, copy)
# -----------------------------------------------------------------------------
# Node source
# -----------------------------------------------------------------------------