1234567891011121314151617181920212223242526272829303132333435363738 |
- def add(doctype, name, user=None, read=1, write=0, share=0, everyone=0, flags=None):
- """Share the given document with a user."""
- if not user:
- user = frappe.session.user
- if not (flags or {}).get("ignore_share_permission"):
- check_share_permission(doctype, name)
- share_name = get_share_name(doctype, name, user, everyone)
- if share_name:
- doc = frappe.get_doc("DocShare", share_name)
- else:
- doc = frappe.new_doc("DocShare")
- doc.update({
- "user": user,
- "share_doctype": doctype,
- "share_name": name,
- "everyone": cint(everyone)
- })
- if flags:
- doc.flags.update(flags)
- doc.update({
- # always add read, since you are adding!
- "read": 1,
- "write": cint(write),
- "share": cint(share)
- })
- doc.save(ignore_permissions=True)
- notify_assignment(user, doctype, name, everyone)
- follow_document(doctype, name, user)
- return doc
|