diff --git a/M01_MasterData/M01_MasterData_Router.py b/M01_MasterData/M01_MasterData_Router.py index 3706dd065..76f24e24e 100644 --- a/M01_MasterData/M01_MasterData_Router.py +++ b/M01_MasterData/M01_MasterData_Router.py @@ -250,6 +250,18 @@ def get_logic_flow(key: str, file: str = "") -> dict: return _call(flow.get_flow, file, key) +class FlowDraft(BaseModel): + file: str = "" + key: str = "" + row: dict[str, Any] + + +@router.post("/logic/flow") +def post_logic_flow(body: FlowDraft) -> dict: + """저장 안 한 고친 줄(옛 편집기) → 흐름 변환 — {flow, converted, notes} · 쓰기 없음.""" + return _call(flow.get_flow, body.file, body.key, body.row) + + @router.post("/logic/new") def post_logic_new(body: NewLogic) -> dict: return _call(make.logic_new, body.logic, body.owner) diff --git a/M01_MasterData/M01_MasterData_Store_Flow.py b/M01_MasterData/M01_MasterData_Store_Flow.py index c2e279f44..9b5089f05 100644 --- a/M01_MasterData/M01_MasterData_Store_Flow.py +++ b/M01_MasterData/M01_MasterData_Store_Flow.py @@ -262,10 +262,13 @@ def _row(file: str, key: str) -> dict: return hit -def get_flow(file: str, key: str) -> dict: - """{flow, converted, notes} — 흐름이 있으면 그대로 · 없으면 변환(파일은 안 바뀜).""" - row = _row(file, key) - if isinstance(row.get(FLOW), dict): +def get_flow(file: str, key: str, draft: dict | None = None) -> dict: + """{flow, converted, notes} — 흐름이 있으면 그대로 · 없으면 변환(파일은 안 바뀜) + · draft = 저장 안 한 고친 줄(옛 편집기) — 늘 그 줄 그대로 변환(쓰기 없음).""" + row = _row(file, key) if draft is None else store._dec({**draft, "키": draft.get("키") or key}) + if draft is not None: + row.pop(FLOW, None) + elif isinstance(row.get(FLOW), dict): return {"flow": {**row[FLOW], "key": key}, "converted": False, "notes": []} try: convert = importlib.import_module(CONVERT).convert diff --git a/resources/tester/test_m01_logic_flow_save.py b/resources/tester/test_m01_logic_flow_save.py index 312664317..dd1f29e5e 100644 --- a/resources/tester/test_m01_logic_flow_save.py +++ b/resources/tester/test_m01_logic_flow_save.py @@ -235,6 +235,20 @@ def test_시스템_관리자가_아니면_403(folder: Path) -> None: client = TestClient(app) before = _hashes(folder) assert client.get("/api/m01/logic/flow", params={"key": KEY}).status_code == 403 + assert client.post("/api/m01/logic/flow", json={"key": KEY, "row": {}}).status_code == 403 assert client.post("/api/m01/save", json={"files": []}).status_code == 403 assert client.post("/api/m01/calc", json={"key": KEY, "inputs": {}}).status_code == 403 assert _hashes(folder) == before + + +def test_저장_안_한_고친_줄_변환(client: TestClient, folder: Path) -> None: + """POST /logic/flow — 옛 편집기 고친 줄 그대로 변환 · 파일은 안 바뀜 · 줄에 흐름이 있어도 변환.""" + before = _hashes(folder) + row = copy.deepcopy(_get(client, "/api/m01/logic", key=OLD)["logic"]) + row["이름"] = "고친 이름" + row["흐름"] = _flow() + got = _post(client, "/api/m01/logic/flow", {"key": OLD, "row": row}) + assert got["converted"] is True and got["flow"]["key"] == OLD + if importlib.util.find_spec(sflow.CONVERT) is not None: + assert got["flow"]["name"] == "고친 이름" and got["flow"]["boxes"] + assert _hashes(folder) == before