Frappe Draw: optional Frappe Drive integration (register diagram as a Drive file)#14
Conversation
…s a Drive file Roadmap item: a diagram can live on Frappe Drive like a Sheets/Slides/Writer doc. Soft-coupled: Draw does NOT add Drive to required_apps, so it stays installable standalone (Frappe Cloud without Drive). Every entry point no-ops cleanly when Drive is absent or not set up (no team). - draw/api/drive_integration.py: register_in_drive(name[, team]) creates a Drive "native document" File (content_doctype="Draw Diagram", content_docname=name, mime_type=frappe_doc) in a team, idempotently reusing an existing link. Team defaults to the user's first Drive team, else the first on the site, else no-op. Whitelisted add_to_drive(name) entry point for a future "Add to Drive" action. - tests: with Drive installed, registration creates a File + is idempotent; when Drive is absent it returns None. The Drive-present test skips on CI (fresh site has no Drive); the no-op test runs everywhere. Verified locally (Drive installed on the dev bench): run-tests --app draw → 9 pass. CI (no Drive) will skip the Drive-present case and pass. Not included (needs a Drive-side change, out of this repo's scope): a Drive viewer that renders a Draw diagram content type, so opening the Drive file shows the diagram. Registration makes the diagram APPEAR in Drive today. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Confidence Score: 3/5The whitelisted endpoint exposes a permission bypass that lets any logged-in user link private diagrams to their Drive account. The draw/api/drive_integration.py — specifically the Reviews (1): Last reviewed commit: "Frappe Draw: optional Frappe Drive integ..." | Re-trigger Greptile |
|
|
||
| @frappe.whitelist() | ||
| def add_to_drive(name: str) -> dict: | ||
| """Whitelisted entry point for an "Add to Drive" action. Returns whether Drive | ||
| is available and the linked File name if created.""" | ||
| file_name = register_in_drive(name) | ||
| return {"drive_installed": drive_installed(), "file": file_name} |
There was a problem hiding this comment.
Missing permission check before Drive registration —
frappe.db.exists("Draw Diagram", diagram_name) bypasses Frappe's permission layer, so any authenticated user can call add_to_drive with any diagram name (including private diagrams they can't read) and link it into their Drive. Add frappe.has_permission("Draw Diagram", doc=name, throw=True) at the top of add_to_drive before calling register_in_drive.
| ) | ||
| # Idempotent — a second call reuses the same File. | ||
| self.assertEqual(register_in_drive(doc.name, team=team), file_name) | ||
|
|
||
| def test_drive_registration_noops_without_team(self): | ||
| # Registration is a safe no-op when Drive isn't set up / not installed. | ||
| from draw.api import drive_integration | ||
|
|
There was a problem hiding this comment.
Test asserts nothing when Drive is installed —
test_drive_registration_noops_without_team only calls assertIsNone inside the if not drive_installed() branch, so on a bench with Drive installed but no team the test body is empty and passes vacuously. Add an else branch (or an unconditional assertion) to cover the "installed but no team" path the test name promises.
What & why
Roadmap item — a diagram can live on Frappe Drive like a Sheets/Slides/Writer doc. Soft-coupled: Draw does not add Drive to
required_apps, so it stays installable standalone (incl. Frappe Cloud without Drive). Every entry point no-ops cleanly when Drive is absent or not set up (no team).Changes
draw/api/drive_integration.py:register_in_drive(name[, team])creates a Drive "native document"File(content_doctype="Draw Diagram",content_docname=name,mime_type=frappe_doc) in a team, idempotently reusing an existing link. Team defaults to the user's first Drive team → first team on the site → else no-op. Whitelistedadd_to_drive(name)for a future "Add to Drive" button.None.Testing
run-tests --app draw→ 9 pass (I installed Drive, created a team, confirmed aFilelinks to the diagram and repeat calls don't duplicate).Explicitly NOT included (needs a Drive-side change, outside this repo)
A Drive viewer that renders the
Draw Diagramcontent type so opening the Drive file shows the diagram. Registration makes the diagram appear in Drive today; rendering it inside Drive's UI is a Drive-repo follow-up (a/drive/g/<name>renderer or a redirect to/draw/d/<name>).🤖 Generated with Claude Code