share_1.py 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. def add(doctype, name, user=None, read=1, write=0, share=0, everyone=0, flags=None):
  2. """Share the given document with a user."""
  3. if not user:
  4. user = frappe.session.user
  5. if not (flags or {}).get("ignore_share_permission"):
  6. check_share_permission(doctype, name)
  7. share_name = get_share_name(doctype, name, user, everyone)
  8. if share_name:
  9. doc = frappe.get_doc("DocShare", share_name)
  10. else:
  11. doc = frappe.new_doc("DocShare")
  12. doc.update({
  13. "user": user,
  14. "share_doctype": doctype,
  15. "share_name": name,
  16. "everyone": cint(everyone)
  17. })
  18. if flags:
  19. doc.flags.update(flags)
  20. doc.update({
  21. # always add read, since you are adding!
  22. "read": 1,
  23. "write": cint(write),
  24. "share": cint(share)
  25. })
  26. doc.save(ignore_permissions=True)
  27. notify_assignment(user, doctype, name, everyone)
  28. follow_document(doctype, name, user)
  29. return doc