Frappe Draw: Writer-style diagram sharing (view/comment/edit) — backend#12
Conversation
…ackend
Roadmap item: share a diagram with view / comment / edit access like Frappe
Writer. Built on Frappe core DocShare + a custom "comment" permission type — NO
Frappe Drive dependency. (Drive file-tree registration and Yjs realtime are
separately-scoped follow-ups; see research notes.)
- patch register_comment_permission_type: registers a "comment" Permission Type
for Draw Diagram (adds a `comment` Check to DocShare + the doctype's perm
rules). Idempotent; skips gracefully on Frappe versions without Permission Type.
- draw/api/share.py: whitelisted share_diagram(name,user,level) /
unshare_diagram / get_diagram_shares / set_public. Levels map to DocShare flags
— view={read}, comment={read,comment}, edit={read,comment,write,share}. Public
reuses the diagram's is_public flag. All gated on the caller holding `share`.
- draw/api/permission.py + hooks permission_query_conditions: list visibility now
includes diagrams shared with the user (DocShare) and public ones, on top of
owner-scoped access. Document-level read/write come from DocShare; `comment` is
checked via frappe.has_permission("Draw Diagram","comment",doc=...).
Verified: `bench run-tests --app draw` → 6 pass, incl. new tests that a shared
user gets read+write+comment on "edit", read-only on "view", and nothing after
unshare (all asserted through frappe.has_permission as that user).
Next: the Share dialog UI (port Drive's ShareDialog — user picker + per-user
view/comment/edit + public link). Realtime collab (Yjs, per Writer) is a separate
milestone.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The role isn't guaranteed to exist on a fresh CI site at test time, and sharing must NOT depend on it — DocShare grants access on its own. Removing it fixes the CI LinkValidationError and makes the test a stronger, role-independent check. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Confidence Score: 4/5
Reviews (2): Last reviewed commit: "fix: run app setup on fresh install too ..." | Re-trigger Greptile |
| @frappe.whitelist() | ||
| def get_diagram_shares(name: str) -> list: | ||
| """The users this diagram is shared with, each with their access flags.""" | ||
| if not frappe.has_permission("Draw Diagram", "read", doc=name): | ||
| frappe.throw(_("Not permitted."), frappe.PermissionError) |
There was a problem hiding this comment.
get_diagram_shares only requires read permission, so any "view"-only user can call it and get the full share list (every collaborator's email + their access level). The PR description says all endpoints are "gated on the caller holding share" — this one is not. Change the gate to share.
| @frappe.whitelist() | |
| def get_diagram_shares(name: str) -> list: | |
| """The users this diagram is shared with, each with their access flags.""" | |
| if not frappe.has_permission("Draw Diagram", "read", doc=name): | |
| frappe.throw(_("Not permitted."), frappe.PermissionError) | |
| @frappe.whitelist() | |
| def get_diagram_shares(name: str) -> list: | |
| """The users this diagram is shared with, each with their access flags.""" | |
| if not frappe.has_permission("Draw Diagram", "share", doc=name): | |
| frappe.throw(_("Not permitted."), frappe.PermissionError) |
…hooks) Patches in patches.txt are marked complete WITHOUT executing on a fresh install, so a fresh Frappe Cloud install never got the Draw User role or the "comment" permission type — only migrates of existing sites did. (This is why the sharing tests failed on CI's fresh site but passed locally.) Consolidate all idempotent setup into draw/setup.py::ensure_setup (Draw User role + owner perms + register the diagram "comment" permission type) and run it from BOTH after_install (fresh) and after_migrate (upgrades). Remove the two now- superseded patches. Also assert the "comment" grant functionally via frappe.has_permission rather than the raw DocShare column. Verified locally: bench migrate runs the after_migrate hook cleanly; run-tests --app draw → 6 pass. CI's fresh-site install now exercises the after_install path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What & why
Roadmap item — share a diagram with view / comment / edit access like Frappe Writer. Built entirely on Frappe core DocShare + a custom "comment" permission type — no Frappe Drive dependency. (Drive file-tree registration and Yjs realtime collab are separately-scoped follow-ups, per the research.)
Changes
register_comment_permission_typepatch: registers a "comment"Permission Typefor Draw Diagram (adds acommentCheck toDocShare+ the doctype's perm rules). Idempotent; no-ops on Frappe versions without Permission Type.draw/api/share.py: whitelistedshare_diagram(name, user, level)/unshare_diagram/get_diagram_shares/set_public. Levels → DocShare flags:view={read},comment={read,comment},edit={read,comment,write,share}. Public reuses the diagram'sis_public. All gated on the caller holdingshare.draw/api/permission.py+permission_query_conditions: list visibility now includes diagrams shared with the user (DocShare) and public ones, on top of owner-scoped access. Document-level read/write come from DocShare;commentviafrappe.has_permission("Draw Diagram","comment",doc=…).Testing
bench --site … run-tests --app draw→ 6 pass, incl. 3 new: a shared user gets read+write+comment on edit, read-only on view, and no access after unshare — all asserted throughfrappe.has_permissionwhile acting as that user. (CI server-tests runs the same on a fresh site.)Next
ShareDialog.vue(user autocomplete + per-user view/comment/edit dropdown + public-link toggle), calling these APIs.Filerow withcontent_doctype=Draw Diagram) — only if Draw must live inside Drive; needs Drive as arequired_app.🤖 Generated with Claude Code