From 23c8631bb28f6003519ce68d4ec42cfa5736f26d Mon Sep 17 00:00:00 2001 From: Vibhav Katre Date: Mon, 20 Jul 2026 10:37:35 +0530 Subject: [PATCH] Frappe Draw: Drive integration opens diagrams in Draw (link file, no renderer) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit register_in_drive now registers a diagram as a Drive LINK file whose target is the Draw editor route (/draw/d/), via drive.api.files.create_link. So a diagram appears in Frappe Drive AND clicking it opens the diagram in Draw — with NO Drive-side renderer required (a Drive-repo change was the only remaining gap). - api/drive_integration.py: diagram_link(name) -> /draw/d/; register_in_drive creates the Drive link in the user's team (idempotent by file_url), still a safe no-op when Drive is absent / has no team. Dropped the native-doc content_doctype linkage (which needed a Drive viewer). - test: assert the registered File is a link to /draw/d/ + idempotent. Verified locally with Drive installed: run-tests --app draw -> 9 pass (creates a team, registers the link, confirms file_url + idempotency). CI (no Drive) skips the Drive-present case, as before. Co-Authored-By: Claude Opus 4.8 (1M context) --- draw/api/drive_integration.py | 33 +++++++++---------- .../doctype/draw_diagram/test_draw_diagram.py | 7 ++-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/draw/api/drive_integration.py b/draw/api/drive_integration.py index 9e21325..df2a585 100644 --- a/draw/api/drive_integration.py +++ b/draw/api/drive_integration.py @@ -11,8 +11,6 @@ import frappe -DIAGRAM_MIME = "frappe_doc" - def drive_installed() -> bool: return "drive" in frappe.get_installed_apps() @@ -31,33 +29,32 @@ def _default_team() -> str | None: return teams[0] if teams else None +def diagram_link(diagram_name: str) -> str: + """The Draw editor route for a diagram — the Drive link target.""" + return f"/draw/d/{diagram_name}" + + def register_in_drive(diagram_name: str, team: str | None = None) -> str | None: - """Ensure a Drive File links to this diagram; returns the File name (or None - when Drive is unavailable / has no team). Idempotent — reuses an existing link.""" + """Register the diagram in Drive as a LINK file that opens the Draw editor + (/draw/d/) — so it appears in Drive and clicking it opens the diagram in + Draw, with NO Drive-side renderer needed. Returns the File name, or None when + Drive is unavailable / not set up (no team). Idempotent — reuses an existing + link for this diagram.""" if not drive_installed() or not frappe.db.exists("Draw Diagram", diagram_name): return None team = team or _default_team() if not team: return None # Drive present but not set up (no team) — nothing to do yet. - existing = frappe.db.exists( - "File", {"content_doctype": "Draw Diagram", "content_docname": diagram_name} - ) + link = diagram_link(diagram_name) + existing = frappe.db.exists("File", {"file_url": link, "team": team}) if existing: return existing + from drive.api.files import create_link + diagram = frappe.get_doc("Draw Diagram", diagram_name) - drive_file = frappe.get_doc( - { - "doctype": "File", - "file_name": diagram.title or diagram_name, - "is_private": 1, - "team": team, - "content_doctype": "Draw Diagram", - "content_docname": diagram_name, - "mime_type": DIAGRAM_MIME, - } - ).insert(ignore_permissions=True) + drive_file = create_link(team, diagram.title or diagram_name, link) return drive_file.name diff --git a/draw/draw/doctype/draw_diagram/test_draw_diagram.py b/draw/draw/doctype/draw_diagram/test_draw_diagram.py index 748503b..0980978 100644 --- a/draw/draw/doctype/draw_diagram/test_draw_diagram.py +++ b/draw/draw/doctype/draw_diagram/test_draw_diagram.py @@ -129,10 +129,9 @@ def test_register_in_drive_when_available(self): file_name = register_in_drive(doc.name, team=team) self.addCleanup(lambda: frappe.delete_doc("File", file_name, force=True, ignore_permissions=True)) self.assertTrue(file_name) - self.assertTrue( - frappe.db.exists( - "File", {"content_doctype": "Draw Diagram", "content_docname": doc.name} - ) + # Registered as a Drive link that opens the Draw editor. + self.assertEqual( + frappe.db.get_value("File", file_name, "file_url"), f"/draw/d/{doc.name}" ) # Idempotent — a second call reuses the same File. self.assertEqual(register_in_drive(doc.name, team=team), file_name)